Model class for Jackson Parser to parse Uppercase properties

后端 未结 4 791
生来不讨喜
生来不讨喜 2021-01-18 02:21

I have a json file which looks like this:

{
    \"ANIMALS\": {
    \"TYPE\": \"MAMMAL\",
    \"COLOR\": \"BLACK\",
    \"HEIGHT\": \"45\",

    }
}
         


        
4条回答
  •  花落未央
    2021-01-18 03:13

    Building off of Deepak's answer, depending on how you have Jackson configured, you may need to put the @JsonProperty on the getters & setters instead of the property or you might get duplicate properties in the resulting JSON.

    Example

     @JsonProperty("ANIMALS")
     private string animals;
    

    Results in...{animals:"foo",ANIMALS:"foo"}

     private string animals;
    
     @JsonProperty("ANIMALS")
     public String getAnimals(){...}
    

    Results in...{ANIMALS:"foo"}

提交回复
热议问题