Duplicate Properties with Fields with all the name with upperCase

45 views
Skip to first unread message

Manuel Garcia

unread,
May 9, 2019, 7:16:50 PM5/9/19
to jackson-user
HI All,

We have a problem with UPPERCASE fields, like in this closed issued in Jackson

https://github.com/FasterXML/jackson-databind/issues/1609

But I prefer to know your opinion due to I think that it is really an issue.

We have to integrate with an API that its swagger api model has all the fields with UPPERCASE , like the following definition:

   
 OutputTO:
      description
: ...
      type
: object
      properties
:
     
       
UPPERCASEFIELD:
          type
: string
          description
: ....
          example
: ...  

  
In our case, using openapi generator plugin , the field in the class is created with the following sintax:

      @JsonProperty("UPPERCASE")
     
private String UPPERCASE;

     
public InputTO UPPERCASE(String UPPERCASE) {
         
this.UPPERCASE = UPPERCASE;
         
return this;
     
}

     
public String getUPPERCASE() {
         
return UPPERCASE;
     
}

     
public void setUPPERCASE(String UPPERCASE) {
         
this.UPPERCASE = UPPERCASE;
     
}

The problem appears when is parsed to json due to the field is duplicated:

{"uppercase":"upperCase","CAMELCASE":"camelCase","UPPERCASE":"upperCase"}

As you can see the field UPPERCASE is duplicated.

I know that there are two possible workarounds to solve this kind of stuff:

1) Put the @JsonProperty on getter, but in that case is not possible due to we use openapi generator based on spring cloud, and its template only adds the annotation on field


2) Reduce the visibility in ObjectMapper, to only explore Fields:
             
 ObjectMapper mapper = new ObjectMapper();
 mapper
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
 mapper
.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
 mapper
.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);

But we would prefer not to use this workaround.

So... Is it possible that in Jackson really exists a bug? I prefer to explore a solution in this forum first.

Tatu Saloranta

unread,
May 10, 2019, 2:12:14 AM5/10/19
to jackson-user
I think you may want to try enabling

MapperFeature.USE_STD_BEAN_NAMING

which I think might solve this particular problem.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages