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.
Old:
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
To New:
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class)
-- or
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(new PropertyNamingStrategies.SnakeCaseStrategy());
That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With