JSON conversion to POJO object failing for new fields in JBoss EAP 7

Solution Verified - Updated -

Issue

Jackson JSON library is being used to convert some JSON objects to POJO classes.
The problem is, the JSON object have a new "isShared" field added which is not present in the POJO class.

This is working fine in JBoss EAP ť, but it is breaking in JBoss EAP ý with the following exception:

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "isShared" (class com.services.document.DocumentModel), not marked as ignorable

Below is the configuration provided in the class:

import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;

@Provider
@Produces(MediaType.APPLICATION_JSON)
@Singleton
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {

    public ObjectMapper getContext(Class<?> aClass) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return mapper;
    }
}

It seems that it could be solved by using @JsonIgnoreProperties(ignoreUnknown = true) on the POJO class to ignore the unknown property. But is this really required? Should the configuration mentioned above not be sufficient - DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false ?

Environment

  • Red Hat JBoss EAP
    • 7.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.