Reputation: 13585
It seems to be a straightforward implementation but somehow not working for me.
public class ParentEntity {
private List<ChildEntity> childFields;
public List<ChildEntity> getChildFields() {
return childFields;
}
public void setChildFields(List<ChildEntity> childFields) {
this.childFields = childFields;
}
}
Input JSON
{
"childFields": [
{<different child properties>},
{<different child properties>}
]
}
Exception
class ChildEntity not marked as ignorable (11 known properties:...different child field properties
Upvotes: 0
Views: 212
Reputation: 5085
Regarding the exception message that you added, you have a mismatch in the properties you specified in your JSON for the ChildEntity and the ChildEntity properties.
If you have a mismatch and you want to specify more properties in JSON, than available in the ChildEntity class, you can use Jackson's
@JsonIgnoreProperties
annotation. It will ignore every property you haven't defined in your POJO.
You could also choose to use:
ObjectMapper objectMapper = getObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
It will ignore all the properties that are not declared.
Upvotes: 1