In a Spring Boot app with MVC, we can configure Jackson's property naming strategy by the following application.yml:
spring:
jackson:
property-naming-strategy: SNAKE_CASE
Unfortunately, this is read by Spring Boot Autoconfigure using reflection, and therefore, the static fields have to be registered in the case of a native build. Otherwise, we get an error message when running the app:
Caused by: java.lang.IllegalArgumentException: Constant named 'SNAKE_CASE' not found
at org.springframework.util.Assert.notNull(Assert.java:219) ~[na:na]
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$StandardJackson2ObjectMapperBuilderCustomizer.configurePropertyNamingStrategyField(JacksonAutoConfiguration.java:287) ~[spring-features.exe:na]
So I added native hints for the constants, hopefully the correct way and in the correct project. (There is already a Hint Registrar existing in the spring-boot project, that registers serializer implementations. But I suggest to create this registrar in the spring-boot-autoconfigure project, because this is the location where the error occurs.
Comment From: pivotal-cla
@ueberfuhr Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@ueberfuhr Thank you for signing the Contributor License Agreement!
Comment From: philwebb
Good spot! Thanks very much for contributing the fix.
Comment From: sbrannen
So I added native hints for the constants
Wouldn't you also need to register reflection hints for the constructors of those implementations?
See https://github.com/spring-projects/spring-framework/issues/29386#issuecomment-1308835391
Comment From: wilkinsona
No, I don't think so. We use reflection to get the value of a field declared on PropertyNamingStrategies. Those values are instances of PropertyNameStrategy implementations. We don't instantiate the strategy as Jackson's already done so and it doesn't use reflection.