I'm using spring 3.0.0.
I have an endpoint that returns an object that I want to be serialized to JSON. When the request comes in with Accept: application/json, it works correctly. The request is currently coming in with */*
as the Accept value. Unfortunately I don't have control over the request, otherwise I would change that. When */*
is received, it throws a HttpMediaTypeNotAcceptableException exception.
Is there a way to map this accept pattern to application/json?
This is very similar to another question, but the key difference is I need to have the Accept header be */*
. Spring's Json not being resolved with appropriate response
Here's what my controller looks like:
@RequestMapping(value = "/v1/endpoint", method = RequestMethod.POST)
@ResponseBody
public EndpointResponse runEndpoint(@RequestBody String jsonData) {
ObjectMapper mapper = new ObjectMapper();
EndpointRequest opRequest = null;
EndpointResponse opResponse = null;
try {
opRequest = mapper.readValue(jsonData, EndpointRequest.class);
//....do stuff
} catch (JsonParseException e) {
return handleException(opResponse, e);
} catch (JsonMappingException e) {
return handleException(opResponse, e);
} catch (IOException e) {
return handleException(opResponse, e);
}
return opResponse;
}
Thanks!