[How to Solve] jackson not marked as ignorable

When the JSON string is transferred from the foreground to the background, the following exception message appears:
unrecognized field “pager. PageSize” (class XXXXX. Alxxxbean), not marked as ignorable
the reason is that the JSON string passed in the foreground contains attributes that the target Java entity class does not have

The solutions are as follows:
1. @ jsonignoreproperties (ignoreunknown = true)
add annotation to the corresponding entity class to indicate that the attribute that does not exist in the target object can be ignored,
the annotation belongs to import org.codehaus.jackson.annotate.jsonignoreproperties
— the method is feasible

2. Format the input content to ensure that the incoming JSON string does not contain the attributes of the target object

3. Global deserialization feature configuration

objectMapper.configure(DeserializationFeature.FAIL_ ON_ UNKNOWN_ PROPERTIES,false);
when the objectmapper is configured to deserialize, it ignores the attributes that the target object does not have. You will have this feature whenever you use the objectmapper to deserialize
– this method has not been tested

Similar Posts: