Skip to content

Jackson well-known module support in native image #28709

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

Closed
mhalbritter opened this issue Jun 27, 2022 · 2 comments
Closed

Jackson well-known module support in native image #28709

mhalbritter opened this issue Jun 27, 2022 · 2 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Milestone

Comments

@mhalbritter
Copy link
Contributor

When running the binary from the webflux-kotlin sample from spring-native, I get the following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonObjectMapper': Instantiation of supplied bean failed
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainInstanceFromSupplier(AbstractAutowireCapableBeanFactory.java:1234) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1209) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1156) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:566) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:526) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:930) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:926) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:729) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:428) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at com.example.webflux.WebfluxApplicationKt.main(WebfluxApplication.kt:16) ~[webflux-kotlin:0.0.1-SNAPSHOT]
Caused by: kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath
        at kotlin.jvm.internal.ClassReference.error(ClassReference.kt:88) ~[na:na]
        at kotlin.jvm.internal.ClassReference.getConstructors(ClassReference.kt:21) ~[na:na]
        at kotlin.reflect.jvm.ReflectJvmMapping.getKotlinFunction(ReflectJvmMapping.kt:146) ~[na:na]
        at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:869) ~[na:na]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:191) ~[na:na]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:152) ~[na:na]
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:842) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:689) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:672) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration.jacksonObjectMapper(JacksonAutoConfiguration.java:113) ~[webflux-kotlin:3.0.0-SNAPSHOT]
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration_JacksonObjectMapperConfiguration__BeanDefinitions.lambda$getJacksonObjectMapperInstance$0(JacksonAutoConfiguration_JacksonObjectMapperConfiguration__BeanDefinitions.java:43) ~[na:na]
        at org.springframework.util.function.ThrowingFunction.apply(ThrowingFunction.java:63) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.util.function.ThrowingFunction.apply(ThrowingFunction.java:51) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        at org.springframework.beans.factory.aot.AutowiredInstantiationArgumentsResolver.resolve(AutowiredInstantiationArgumentsResolver.java:156) ~[na:na]
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration_JacksonObjectMapperConfiguration__BeanDefinitions.getJacksonObjectMapperInstance(JacksonAutoConfiguration_JacksonObjectMapperConfiguration__BeanDefinitions.java:43) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainInstanceFromSupplier(AbstractAutowireCapableBeanFactory.java:1223) ~[webflux-kotlin:6.0.0-SNAPSHOT]
        ... 18 common frames omitted

There is

		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-reflect</artifactId>
		</dependency>

in the pom.xml, the sample runs with mvn spring-boot:run

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 27, 2022
@poutsma poutsma added the theme: kotlin An issue related to Kotlin support label Jun 27, 2022
@sdeleuze sdeleuze added theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 28, 2022
@sdeleuze sdeleuze self-assigned this Jun 28, 2022
@sdeleuze sdeleuze added this to the 6.0.0-M5 milestone Jun 28, 2022
@sdeleuze sdeleuze changed the title Kotlin support in native image Kotlin reflection support in native image Jun 28, 2022
@sdeleuze sdeleuze changed the title Kotlin reflection support in native image Jackson Kotlin module support in native image Jun 28, 2022
@sdeleuze sdeleuze changed the title Jackson Kotlin module support in native image Jackson well-known module support in native image Jun 28, 2022
@sdeleuze
Copy link
Contributor

Seems related to the well-known Jackson modules (here KotlinModule) registered in Jackson2ObjectMapperBuilder#registerWellKnownModulesIfAvailable.

There could be Kotlin reflection hints missing as well (but those ones should go in the reachability metadata reprository I think, not sure yet what we do in the interim).

Spring Native KotlinHints could be used as a source of inspiration.

@sdeleuze
Copy link
Contributor

Notice I had to add Kotlin hints via spring-attic/spring-native@3392357 to make it work, this will go to the reachability repo or better we could ask Kotlin team to ship that out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants