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
Best Answer
Spring's
RestTemplate
expectscom.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 theRestTemplate
to ignore unknown properties: