-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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
Spring boot native image is not able to convert 'SORT' to json, throws org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON #35692
Comments
Thanks for the report. Unfortunately, without knowing what type you are returning in the HTTP response and exactly what hints you provided, we can only guess about the cause of the problem. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue. |
Thank you for the quick response. Attached the code for your reference. |
Thanks for the sample. Unfortunately, I haven't been able to reproduce the problem. I am trying to do so on the JVM initially. Once that works, I'll try in a native image. The project requires Postgres which I'd prefer not to use as there may be external configuration in the database that you haven't shared. I switched to H2 which allowed the app to start. Accessing http://localhost:8080/master/project/list?pageNum=0&projectsCount=10&sortType=DESC&sortField=projectStatus results in a 404 response. Looking at the controllers, I think the correct URL is http://localhost:8080/list?pageNum=0&projectsCount=10&sortType=DESC&sortField=projectStatus. This results in a different 404 response:
With the following logged to the console:
It looks like the project's entities are not sufficient for Hibernate to create the expected database schema. Can you please update the sample to use an in-memory database such as H2 and ensure that it reproduces the problem you have described without relying on any additional external configuration. |
I have uploaded the app with h2 enabled (demo.zip). Let me know If i can be a help |
Thanks for the updates. Unfortunately, I still can't reproduce the problem. With Spring Boot 3.1.0, the native image fails to start due to some known problems with Hibernate 6.2.2. When I downgrade to Spring Boot 3.0.7, the image starts and the
|
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
I was facing this issue because of feign dependency in application. I was not able to find the root cause of it, but as soon as I removed all the feign dependencies the sort started to work in native image. Thank you for the support. |
The sample you provided includes a dependency on Feign but it does not appear to reproduce the problem. Unfortunately, without something that reproduces the problem we won't be able to help. |
Hi @pulsar-gupta @wilkinsona
It's enough to return a dummy PageImpl in your controller to raise this exception:
The request should contain the sort field:
It seems it's related to a misplaced serializator from openfeign I was able to fix this by providing serialization config for the Sort class:
Hope this tip will help someone! |
@mykhailokulakov |
I am generating spring boot 3 native image using -Pnative switch.
The DAO class fetches the data from DB with SORT object passed to DAO (below is sample)
However, the call is failed when the call is returned from controller and the exception is
"org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException(207) : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Couldn't serialize object"
I have tried to provide hints to serialize the SORT object but this is also not working.
The text was updated successfully, but these errors were encountered: