-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Using Jackson support for Kotlin fails in native mode. #3954
Comments
For a short-term work-around the following working:
|
I think this is a legit issue. As a parameter of a REST method, the There's something wrong going on. |
@geoand any chance you could have a look to this one? |
@gsmet sure thing |
This doesn't appear to be a Quarkus issue. The |
@geoand you're correct, it still works if I remove I also tested by swap back to
NOT WORKING
|
Thanks for confirming and looking into it. So I will go ahead and close this since it doesn't appear to be a Quarkus issue. If you feel that is not correct, please reopen and provide an update. Thanks |
@geoand I still think this is an issue as the NOT WORKING case, works just fine in JVM mode, it only fails in NATIVE mode. |
@rdifrango a small reproducer then where I can see the exact error you are getting? |
The code above is exactly what I used, nothing more nothing less :) To build it we issue:
To run it:
|
If you could upload it to github or something, so I don't make any mistakes while trying to reproduce that would be great :) |
@geoand , I'll see what I can do, sadly uploading to GH is non-trivial at the office :) Here's the maven POM file:
|
Thanks @rdifrango, I'll try and reproduce it. One last thing, do you have a curl command for POSTing to the endpoint? |
|
Thanks, I'll try it and let you know |
I was able to reproduce the problem. |
thank you @geoand! |
Actually what we are seeing seems consistent with the Kotlin module not being applied in native mode. So if anyone wants to explore more, that would be great. I will of course eventually get to this but frankly since we have workable workarounds and the root cause it probably hidden deep, I wouldn't consider it very high priority :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you! |
Would be nice to have this fixed. |
I'm sure we are getting off topic, and a Quarkus dev will yell at us soon, but defaults won't work as they only work when no value is specified, and via that constructor. Jackson will set them to null. |
Nobody is going to yell at anyone, we are as super friendly community :) The problem is that the behavior is different between JVM and native mode. With the no-arg plugin, in JVM the defaults are used which unfortunately is not the case in native mode. |
I am running into this same issue, except I get the error I tried debugging by doing |
Yeah this seems to require a chat with the Kotlin folks to see how to proceed. Unfortunately I haven't had the time to do that :( |
hi @geoand - have you been able to get in touch with the kotlin/graalvm folks? |
@tellisnz-shift unfortunately no. With all the stuff that needed to be done for 1.3, I didn't follow up after not being able to reach them the first time. |
Just as an indicator (I haven't isolated this into a barebones example), in case it helps, I am running into this problem for a data class which does not have any default values (but all properties are |
Any news? I was able to get around this problem by explicitly adding Jackson annotations. @RegisterForReflection
data class CreateTaskRequest(val name: String, val description: String?) but this code works in both JVM and native modes and keeps the class immutable. @RegisterForReflection
data class CreateTaskRequest @JsonCreator constructor(
@JsonProperty("name")
val name: String,
@JsonProperty("description")
val description: String?
) However, it pollutes my class and I expect to write code without any Jackson annotations as in the first example. Kotlin: 1.3.71 |
@miron4dev is that class part of a jax-rs method (I assume it's the payload of a POST request)? |
@geoand yes, it's the payload of a POST request. |
I want to give something a try soon. I'll come back when I have something to report. |
I went through various scenaria to try and reproduce the problems with Kotlin Data classes and Jackson deserialization in native but I failed to uncover any... Here is where I recorded what I did: https://github.com/geoand/kotlin-jackson-demo |
I need to do a little more testing. I need to upgrade Graal to test with 1.3.2, so this will take me a little longer. Will report back when I can. |
@codemwnci Thanks. Feel free to ping me when you have results :) |
I have tried a number of different configurations (slow testing cycle due to the 15minute native compile!). Upgrading to Quarkus 1.3.2, and GraalVM 20.x, did not initially make any difference. I then changed the POM to reflect your POM and it worked.
So, as long as the latest POM creation through the maven archetypes generate the above setting (which appears to be the case), then this bug can be closed. For anyone who is not creating a new project, they simply need to add the parameter to the "configuration" of the kotlin-maven-plugin, as linked to above. |
Thanks a lot for the thorough check @codemwnci! Indeed the project generation now includes I'll close this issue as per both our findings |
If anyone is having troubles with Kotlin in native mode, check the configuration resources linked here: oracle/graal#2306 |
I have some experiences to add on this one. I use an IntelliJ plug-in to convert JSON to Kotlin data classes for me (large structure!) Everything worked fine in JVM mode, Jackson-Kotlin-module clearly enabled for the What was interested was when I moved to using So, my recommendation for anyone having these issues, is to use I'm looking forward to using Java-records in the future in this scenario, and I believe Kotlin will map the internals of data-classes to records so it will look the same to the JVM(?). No not keen on using Lombok here as a replacement for my Kotlin data classes. JSON source was from Yahoo Finance: https://query1.finance.yahoo.com/v8/finance/chart/AMZN |
An addendum, I've been able to get it working with the entire object tree for native-image (fiddling with JSON to Kotlin data-class IntelliJ plugin options), generating val with nullable type and default of null, along with the Jackson field name, .i.e.:
|
@geoand, you asked for reproducible examples of issues. I ran into this issue last week and had a hard time figuring out why your example worked and my code didn't. In the end, I found out that the issue seemed to be data classes that have non-primitive members, e.g. a data class containing a Thanks! |
Thanks @lbilger. I'll try to take a look later on this week, |
@geoand This is the same issue I described above (complex structures) and why I added troubleshooting notes to the Kotlin documentation. Using the field annotation does overcome it, but may be considered a workaround. |
Ah, thanks @oztimpower, I had forgot! |
Describe the bug
When using the Jackson Kotlin module with a Kotlin data class, it fails in native mode with the following:
The example code is pretty straight forward:
Expected behavior
(Describe the expected behavior clearly and concisely.)
If I run this in JVM mode, aka
mvn compile quarkus:dev
, or as a runnable jar it works just fine.Actual behavior
(Describe the actual behavior clearly and concisely.)
To Reproduce
Steps to reproduce the behavior:
1.
2.
3.
Configuration
# Add your application.properties here, if applicable.
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
uname -a
orver
:java -version
:<quarkus.version>0.21.2</quarkus.version>
Additional context
(Add any other context about the problem here.)
Related #3652
The text was updated successfully, but these errors were encountered: