I am using a domain object imported from other service which implements builder pattern and hence have no No-arg Constructor and setters. I want to map JSON coming from @RequestBody to this domain object. I know I can annotate it with @JSONPojoBuilder and some other ones but i don't have control over it. So I'm stuck with writing my own JSON to Object mapper which i don't think is a good idea as it involves validations etc. and is tightly coupled with request body.
Code -
@RequestMapping(value = "someurl", method = RequestMethod.POST)
public ResponseEntity<ObjectA> addObject(@PathVariable String id, @RequestBody @NonNull String body) {
ObjectA obj = service.addObject(id, mapper.mapJSONToObject(body));
return new ResponseEntity<>(obj , HttpStatus.CREATED);
}
Instead of writing my own mapper, I heard we can use some message convertor and pass our Builder class as some argument. I did not find such examples, if anybody has done it before or can point me to some site, that'd be helpful.