Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 408
Parundeep Singh Avatar asked Dec 22 '25 19:12

Parundeep Singh


2 Answers

Old:

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)

To New:

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
-- or 
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
like image 65
Ananasann Avatar answered Dec 24 '25 10:12

Ananasann


ObjectMapper mapper = new ObjectMapper();

mapper.setPropertyNamingStrategy(new PropertyNamingStrategies.SnakeCaseStrategy());

That's it.

like image 34
Daniel Domingueti Avatar answered Dec 24 '25 10:12

Daniel Domingueti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!