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

Exception for spring.jackson.property-naming-strategy - Unable to instantiate jackson 26 object #4303

Closed
nnpatel4u opened this issue Oct 10, 2016 · 7 comments
Milestone

Comments

@nnpatel4u
Copy link

nnpatel4u commented Oct 10, 2016

Overview of the issue

I generated sample JHipster application taking available jdl example. Required files are attached.
Spring boot has the setting for the same to use spring.jackson.property-naming-strategy to SNAKE_CASE (http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html).
While, using it for the JHipster generated project, I am getting multiple exception for "Unable to instantiate jackson 26 object".

DEBUG 8677 --- [  restartedMain] c.f.j.d.introspect.POJOPropertyBuilder   : Unable to instantiate jackson 26 object

java.lang.NoSuchMethodException: com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.<init>(com.fasterxml.jackson.databind.PropertyName, com.fasterxml.jackson.databind.AnnotationIntrospector, boolean)
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getConstructor(Class.java:1825)
    at springfox.documentation.schema.property.PojoPropertyBuilderFactory.constructorWithParams(PojoPropertyBuilderFactory.java:105)
    at springfox.documentation.schema.property.PojoPropertyBuilderFactory.jackson26Instance(PojoPropertyBuilderFactory.java:89)
    at springfox.documentation.schema.property.PojoPropertyBuilderFactory.create(PojoPropertyBuilderFactory.java:42)
    at springfox.documentation.schema.property.BeanPropertyDefinitions.getName(BeanPropertyDefinitions.java:69)
    at springfox.documentation.schema.property.BeanPropertyDefinitions.access$000(BeanPropertyDefinitions.java:28)
    at springfox.documentation.schema.property.BeanPropertyDefinitions$2.apply(BeanPropertyDefinitions.java:58)
    at springfox.documentation.schema.property.BeanPropertyDefinitions$2.apply(BeanPropertyDefinitions.java:55)
    at com.google.common.base.Present.transform(Present.java:71)
    at springfox.documentation.schema.property.ObjectMapperBeanPropertyNamingStrategy.nameForSerialization(ObjectMapperBeanPropertyNamingStrategy.java:56)
    at springfox.documentation.schema.property.BeanPropertyDefinitions.name(BeanPropertyDefinitions.java:46)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.beanModelProperty(OptimizedModelPropertiesProvider.java:271)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.access$200(OptimizedModelPropertiesProvider.java:79)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider$2.apply(OptimizedModelPropertiesProvider.java:163)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider$2.apply(OptimizedModelPropertiesProvider.java:155)
    at com.google.common.base.Present.transform(Present.java:71)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.candidateProperties(OptimizedModelPropertiesProvider.java:212)
    at springfox.documentation.schema.property.OptimizedModelPropertiesProvider.propertiesFor(OptimizedModelPropertiesProvider.java:127)
    at springfox.documentation.schema.property.CachingModelPropertiesProvider$1.load(CachingModelPropertiesProvider.java:56)
    at springfox.documentation.schema.property.CachingModelPropertiesProvider$1.load(CachingModelPropertiesProvider.java:54)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
    at springfox.documentation.schema.property.CachingModelPropertiesProvider.propertiesFor(CachingModelPropertiesProvider.java:64)
    at springfox.documentation.schema.DefaultModelProvider.properties(DefaultModelProvider.java:151)
    at springfox.documentation.schema.DefaultModelProvider.modelFor(DefaultModelProvider.java:84)
    at springfox.documentation.schema.CachingModelProvider$1.load(CachingModelProvider.java:51)
    at springfox.documentation.schema.CachingModelProvider$1.load(CachingModelProvider.java:49)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
    at springfox.documentation.schema.CachingModelProvider.modelFor(CachingModelProvider.java:59)
    at springfox.documentation.spring.web.scanners.ApiModelReader.read(ApiModelReader.java:67)
    at springfox.documentation.spring.web.scanners.ApiListingScanner.scan(ApiListingScanner.java:88)
    at springfox.documentation.spring.web.scanners.ApiDocumentationScanner.scan(ApiDocumentationScanner.java:69)
    at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.scanDocumentation(DocumentationPluginsBootstrapper.java:85)
    at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:127)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:874)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.example.ExampleApp.main(ExampleApp.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

I believe this is an issue with JHipster generated application as Spring boot documentation suggests the alternative to provide required property naming strategy through the application properties.

Motivation for or Use Case

I am checking the feasibility to use JHipster for one of my freelancing project to generate Monolithic Application. In that application, I need to call third party APIs and respond the various clients - Android, iOS, Web Client. So as per client specification, I am looking for property naming with lower case and "_" to separate words.

Reproduce the error

=> Generate jhipster monolithic application with sample jdl file present in https://jhipster.github.io/jdl-studio.
=> Update src/main/resources/config/application-dev.yml file to have SNAKE_CASE as property naming strategy.
spring:
jackson:
serialization.indent_output: true
property-naming-strategy: SNAKE_CASE
=> Run the application with development goal - ./mvnw -Pdev

Related issues

Unable to find any similar issue. But tried to look how I can set application wide property naming strategy. And majority have provided the solution to use application properties for the same. I have checked for the alternatives / issues relating to this and tried to update custom object mapper builder to have SNAKE_CASE as the property naming strategy. Also tried with fully qualified class name (com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStretegy). But sill the exceptions are present while starting the server (./mvnw -Pdev).

Suggest a Fix

Not found yet (new to Spring boot and JHipster).

JHipster Version(s)

3.8.0 (The output of yo jhipster:info is attached.)

JHipster configuration, a .yo-rc.json file generated in the root folder

The .yo-rc.json is attached.

Entity configuration(s) entityName.json files generated in the .jhipster directory

Files present in .jhipster directory are attached.

Browsers and Operating System

Mozilla Firefox 48.0
Ubuntu 14.04 LTS
prop_naming_issue.zip

@gmarziou
Copy link
Contributor

java.lang.NoSuchMethodException: com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.(com.fasterxml.jackson.databind.PropertyName, com.fasterxml.jackson.databind.AnnotationIntrospector, boolean)

Looks like a wrong version of Jackson is used.
Have you changed dependencies?

@cbornet
Copy link
Member

cbornet commented Oct 10, 2016

It seems that springfox doesn't like this parameter.
Could you try with a simple springfox/boot project ?

@jdubois
Copy link
Member

jdubois commented Oct 12, 2016

I confirm the issue, but this is because you changed the default configuration to "SNAKE_CASE". While this configuration seems to exist in the Jackson code, it doesn't even autocomplete in my Spring Boot configuration, so I guess this might not be supported by Spring Boot.

Anyway, the issue is either:

  • A problem in Jackson
  • An issue with Spring Boot

Our default configuration works, if you want to do something else, you might encounter this kind of integration issue (we got them all the time, that's why JHipster is a lot of work), but we can't help you with this.

@dilipkrish
Copy link

dilipkrish commented Oct 20, 2016

Also just to note that this is not an issue per se, unless someone can confirm otherwise.

This is a debug message.

We explicitly added an anti-corruption layer to shield consumers from changes in 2.6 vs 2.7 vs 2.8 of jackson. So this is just a message indicating that "we tried doing X with 2.6 and now we're going to try with 2.7".

@codebusta
Copy link

codebusta commented Oct 23, 2016

I do confirm that this issue occurs in jhipster application. The default JacksonConfiguration is as follows:

`@Configuration
public class JacksonConfiguration {

public static final DateTimeFormatter ISO_FIXED_FORMAT =
    DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneId.of("Z"));

@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
    return new Jackson2ObjectMapperBuilderCustomizer() {
        @Override
        public void customize(Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
            jackson2ObjectMapperBuilder.serializers(new ZonedDateTimeSerializer(ISO_FIXED_FORMAT));
        }
    };
}

}`

The only thing i needed to make my parameter to automatically become snake_case was to do the following:

`@Configuration
public class JacksonConfiguration {

public static final DateTimeFormatter ISO_FIXED_FORMAT =
    DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneId.of("Z"));

@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
    return new Jackson2ObjectMapperBuilderCustomizer() {
        @Override
        public void customize(Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
            jackson2ObjectMapperBuilder.serializers(new ZonedDateTimeSerializer(ISO_FIXED_FORMAT))
                .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        }
    };
}

}`
Now this is not working. It throws exceptions while starting the project as described above. So digging deeper, i noticed that the error message is actually valid. So, if you still want to make this automatic camelCase properties to become snake_case, you just need to turn off log.
Just go to logback-spring.xml and put the following line:

And, voila, your application now starts again and the properties in the REST API are all snake_case.

@jdubois jdubois modified the milestone: 3.10.0 Oct 27, 2016
@rajjaiswalsaumya
Copy link

Is this working, i am using 2.8 and plain spring boot project. I wrote snake_case (in caps) and log threw weird error and application failed to start :(

@pascalgrimaud
Copy link
Member

Plz, don't comment old ticket.
If you have an issue with JHipster, open a new ticket with full details and full steps, so we can reproduce.

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

8 participants