Open theseeker58 opened 2 years ago
Found the solution! after adding JaxbAnnotationModule, if you still want to set propertyNamingStrategy you have to enable the MapperFeature ALLOW_EXPLICIT_PROPERTY_RENAMING. Unfortunately I had to refactor my code since enable(MapperFeature) is deprecated on ObjectMapper. I used a subclass named JsonMapper. Here is the code.
JsonMapper mapper = JsonMapper.builder()
.addModule(new JaxbAnnotationModule())
.enable(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING)
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.build();
Just to share with other guys who come across this problem. Cheers
I don't know it it's a feature or a bug, but after registering JaxbAnnotationModule to the ObjectMapper
mapper.registerModule(new JaxbAnnotationModule());
setting PropertynamingStrategy different from LowerCamelCasemapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
is definitely ignored. Only default LOWER_CAMEL_CASE works. If I remove JaxbAnnotationModule I can successfully set different PropertyNamingStrategy. Unfortunately I need JaxbAnnotationModule to ignore field annotated with XmlTransient in schema generation, but at the same time I have to comply to the ISO Whitepaper for 20022 UNIFI messages that forces snake_case naming convention. Cheers