Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaxbAnnotationModule and PropertyNamingStrategy conflicts #167

Open
theseeker58 opened this issue Mar 10, 2022 · 1 comment
Open

JaxbAnnotationModule and PropertyNamingStrategy conflicts #167

theseeker58 opened this issue Mar 10, 2022 · 1 comment

Comments

@theseeker58
Copy link

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 LowerCamelCase
mapper.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

@theseeker58
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant