My Spring Boot API uses camelCase, but I need to proxy some requests through my API to a 3rd party API that uses snake_case. Is it possible to configure Jackson to deserialize the 3rd party response from snake_case, then serialize it back to camelCase to my frontend?
Step by step example of desired functionality:
Example Object:
MyObject {
String myProperty;
}
{
"my_property": "my value"
}
MyObject
{
"myProperty": "my value"
}
Right now I am using @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
but of course that will serialize into snake_case as well. Note - even though my api uses camelCase, it would be acceptable to always deserialize from snake_case as this will be a readonly enpoint.
You could add the @JsonAlias
annotation on the individual properties to add alternative names for deserialization. Or you could configure multiple object mappers with explicit naming strategies, one for deserialization of this third-party API, and one for your normal serialization/deserialization.
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