If you want this for a Single Class, you can use the PropertyNamingStrategies with the @JsonNaming, annotation, like this:
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Request {
String businessName;
String businessLegalName;
}
Will serialize to:
{
"business_name" : "",
"business_legal_name" : ""
}
Before Jackson 2.7
, use PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class
:
@JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
public static class Request {
String businessName;
String businessLegalName;
}
From Jackson 2.7
to Jackson 2.12
the LowerCaseWithUnderscoresStrategy
is deprecated in favor of SnakeCaseStrategy
, so you should use:
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public static class Request {
String businessName;
String businessLegalName;
}
Since Jackson 2.12
the PropertyNamingStrategy.SnakeCaseStrategy
is deprecated in favor of PropertyNamingStrategies.SnakeCaseStrategy
, you should use:
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Request {
String businessName;
String businessLegalName;
}