I have a json file which looks like this:
{
\"ANIMALS\": {
\"TYPE\": \"MAMMAL\",
\"COLOR\": \"BLACK\",
\"HEIGHT\": \"45\",
}
}
If you are not generating the JSON (serialisation), but you want to consume an object without having to care about the case.
You can receive Animal or AniMal :
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
You should implement new naming strategy for your case:
class LowerCaseNamingStrategy extends LowerCaseWithUnderscoresStrategy {
private static final long serialVersionUID = 1L;
@Override
public String translate(String arg0) {
return arg0.toUpperCase();
}
}
After that, configure ObjectMapper
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(new LowerCaseNamingStrategy());
See also @JsonProperty
annotation.
Thanks I solved this issue using @JsonProperty annotation
@JsonProperty("ANIMALS")
private string animals;
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"}