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

@EnableSpringDataWebSupport not working in native image #3117

Closed
czp3009 opened this issue Jul 1, 2024 · 2 comments
Closed

@EnableSpringDataWebSupport not working in native image #3117

czp3009 opened this issue Jul 1, 2024 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@czp3009
Copy link

czp3009 commented Jul 1, 2024

With @EnableSpringDataWebSupport in graalvm native image, requests will always return 500

Consider following code:

@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
@SpringBootApplication
class Application

@RestController
class DefaultController {
    @GetMapping("/")
    fun endpoint() = PageImpl(listOf(1, 2))
}

response:

{"timestamp":"2024-07-01T09:06:31.252+00:00","status":500,"error":"Internal Server Error","path":"/"}

log:

2024-07-01T09:06:31.220Z  WARN 1 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson serialization for type [class org.springframework.data.domain.PageImpl]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PageModelConverter': Failed to instantiate [org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PageModelConverter]: No default constructor found

issue reproduction repository: https://github.com/czp3009/spring-EnableSpringDataWebSupport-not-working-in-native-image

please follow the steps in the repository README to reproduce

=========================================================
More discoveries:
there is the same result whether pageSerializationMode is specified or not. log of another case:

2024-07-01T09:24:55.564Z  WARN 1 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson serialization for type [class org.springframework.data.domain.PageImpl]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning': Failed to instantiate [org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning]: No default constructor found
2024-07-01T09:24:55.595Z  WARN 1 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson serialization for type [class org.springframework.data.domain.PageImpl]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning': Failed to instantiate [org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning]: No default constructor found
2024-07-01T09:24:55.596Z  WARN 1 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.UnsupportedOperationException)]
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 1, 2024
@czp3009
Copy link
Author

czp3009 commented Jul 1, 2024

workaround for someone else also meet this problem:

class SpringDataJacksonHints: RuntimeHintsRegistrar {
    override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
        hints.reflection().registerType(TypeReference.of(
            "org.springframework.data.web.config.SpringDataJacksonConfiguration\$PageModule\$PageModelConverter"
        ), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
        hints.reflection().registerType(TypeReference.of(
            "org.springframework.data.web.config.SpringDataJacksonConfiguration\$PageModule\$PlainPageSerializationWarning"
        ), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
    }
}

@christophstrobl christophstrobl self-assigned this Jul 2, 2024
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 2, 2024
@christophstrobl
Copy link
Member

Thank you @czp3009 for raising the issue and the reproducer.

christophstrobl added a commit to christophstrobl/spring-aot-smoke-tests that referenced this issue Jul 3, 2024
Add tests to verify Jackson serialization of Page instances work using the PageModule.

See: spring-projects/spring-data-commons#3117
mp911de pushed a commit that referenced this issue Aug 5, 2024
@mp911de mp911de closed this as completed in 1f347dc Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
4 participants