I'm using a 3rd party REST API which is returning 'NaN' in it's JSON response :( I can't change the response.
I'm using Spring MVC with RestTemplate and the built in Message Converters to deserialize the JSON to an Object.
I was wondering, if there is a smart way of setting the JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS
property to allow for the NaN in the response.
Because I have other message converters which I do not need to configure myself I'm currently doing the following:
List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
for (HttpMessageConverter converter : converters) {
if (converter instanceof MappingJacksonHttpMessageConverter) {
ObjectMapper objectMapper = ((MappingJacksonHttpMessageConverter) converter).getObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
}
}
This works but I don't like the fact that I'm a) iterating and b) doing the instanceof comparison just to set this property.
What would be a smarter/nicer way to do this?