[Java] Mutual conversion of notations such as camel case and snake case [Jackson]

Guava is famous for mutual conversion of naming conventions in Java such as camel case and snake case, but Jackson can also do it, so I will summarize it.

manner

You can do this by using the various Strategys defined in com.fasterxml.jackson.databind.PropertyNamingStrategy.

As an example, here is the conversion from camel case to snake case.

public static String camelToSnake(String value) {
    return new PropertyNamingStrategy.SnakeCaseStrategy().translate(value);
}

See the source code and documentation for other conversions.

Supplement

As another method, ModelMapper and Gson are likely to have equivalent functions.

-Java -Map and Bean conversion with snake case key | teratail

Articles that I used as a reference

-Jackson's Property Naming Strategy Summary -Qiita

Recommended Posts

[Java] Mutual conversion of notations such as camel case and snake case [Jackson]
Make the JSON of the snake case correspond to the field of the camel case in Java (JVM)
Mutual conversion between Java objects and JSON using Moshi
Spring Boot Servlet mapping
Spring profile function, and Spring Boot application.properties
I got stuck using snake case for variable name in Spring Boot
[Java] Mutual conversion of notations such as camel case and snake case [Jackson]
Implementation method for multi-data source with Spring boot (Mybatis and Spring Data JPA)
HTTPS with Spring Boot and Let's Encrypt
Add spring boot and gradle to eclipse
Advantages and disadvantages of Java