Reputation: 504
My pojo class is annotated with XmlAccessorType.NONE.
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Human {
@XmlElement(name="name")
private String name;
private int age
}
JSON which im trying to read contains both properties name and age. If i annotate the class with JsonIgnoreProperties(ignoreUnknown = true) everything works However if i try to use annotation XmlAccessorType(XmlAccessType.NONE) intead, jackson throws unknown property exception.
I tried to add JaxbAnnotationIntrospector into objectmapper but it did not help mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
Upvotes: 0
Views: 1441
Reputation: 116522
I don't see why XmlAccessorType(XmlAccessType.NONE)
would be relevant here,
It would affect discovery of properties available (no auto-discovery), but NOT what to do with JSON/XML properties for which there is no Bean property.
The difference here is probably more due to difference between defaults for JAXB and Jackson: by default, JAXB silently ignores anything it does not recognize. By default Jackson throws an exception when it does not recognize something.
If you want, you can configure ObjectMapper
to ignore these problems by default:
napper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
so that behavior is similar to that of JAXB.
Upvotes: 1