I need to build a service that needs to consume different xmlTypes in request body of one endpoint.
To do so, I've implemented this:
@PostMapping(value="/one")
public ResponseEntity<?> result(
String xmlType,
@RequestBody Object body
) {
Employe employee = null; // employee object that is generated by xsd file.
Profile profile = null; // profile object that is generated by xsd file.
if (body instanceof Employe) {
employee = (Employe) body;
} else if (body instanceof Profile) {
profile = (Profile) body;
}
// business logic
return ResponseEntity.accepted().build();
}
but by this implementation, I'm getting Unsupported Media Type error.
Example usage of the service;
- url: '/domain/one?xmlType=Profile', body(requestBody):
<Profile></Profile> - url: '/domain/one?xmlType=Employee', body(requestBody):
<Employee></Employee>
When I use the specific Object it works, but I couldn't implement the generic version. So, how can I achieve this feature?