Search code examples
javaspringspring-bootjacksonjackson-databind

Alternatives for PropertyNamingStrategy.SNAKE_CASE or PropertyNamingStrategy.SnakeCaseStrategy as it is deprecated now


In prior versions of jackson, we were using the following two ways to modify the Property Naming during serialization and deserialization of objects.

First way: Mentioning the following annotation on class level.

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)

Second way: Setting the PropertyNamingStrategy in Object Mapper itself.

objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SnakeCaseStrategy.class);

or,

objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

Now as it has been deprecated from version 2.13.

Reference : https://fasterxml.github.io/jackson-databind/javadoc/2.13/com/fasterxml/jackson/databind/PropertyNamingStrategy.html

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

Now what are the alternative for the above thing.

Could anyone please help me with how it can be done?

Was trying the above two ways, but its is showing deprecated now.


Solution

  • NOTE! Since 2.12 sub-classes defined here (as well as static singleton instances thereof) are deprecated due to databind#2715. Please use constants and classes in PropertyNamingStrategies instead.

    https://fasterxml.github.io/jackson-databind/javadoc/2.13/com/fasterxml/jackson/databind/PropertyNamingStrategies.html