Jackson does not accept @XlmElement uppercase keys

Viewed 65

I try to deserialize some classes for use in OpenAPI. Like for example:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MyClass", propOrder = {
    "config",
    "value"
})
public class MyClass
{
  @XmlElement(name = "CONFIG")
  protected MyConfig config;

  @XmlElement(name = "VALUE")
  protected MyValue value;

  public MyConfig getCONFIG()
  {
    return config;
  }

  public MyValue getVALUE()
  {
    return value;
  }
}

I am using these dependencies:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.8.4</version>
</dependency>
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-jersey2-jaxrs</artifactId>
</dependency>

In my Swagger-UI i see that it generated this json:

{
  "value": {
    [...]
  },
  "config": {
    [...]
  }
}

But my REST-Interface only accepts the object if the properties are in UPPERCASE.

This is my object Mapper:

om = new ObjectMapper();
om.registerModule(new JaxbAnnotationModule());

What am i doing wrong here?

1 Answers

You could use MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES.

Feature that will allow for more forgiving deserialization of incoming JSON. If enabled, the bean properties will be matched using their lower-case equivalents, meaning that any case-combination (incoming and matching names are canonicalized by lower-casing) should work.

So:

om.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
Related