RestTemplate
's getForObject
method ignores the @JsonIgnoreProperties(ignoreUnknown = true)
annotation on the class.
E.g. for
@JsonIgnoreProperties(ignoreUnknown = true)
public class Stock extends AbstractSObject
{
// fields
}
and
RestTemplate rest = new RestTemplate();
Stock s = rest.getForObject("address", Stock.class);
I'm getting the following error
Could not read JSON: Unrecognized field "SomeField" (class sandbox.Stock), not marked as ignorable
Spring's RestTemplate
expects com.fasterxml.jackson.annotation.JsonIgnoreProperties
.
If you are using the org.codehaus.jackson.annotate.JsonIgnoreProperties
annotation from the older package for other purposes, you can manually setup the RestTemplate
to ignore unknown properties:
RestTemplate rest = new RestTemplate();
ObjectMapper lax = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MappingJacksonHttpMessageConverter c = new MappingJacksonHttpMessageConverter();
c.setObjectMapper(lax);
List<HttpMessageConverter<?>> list = new ArrayList<>();
list.add(c);
rest.setMessageConverters(list);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With