-
Notifications
You must be signed in to change notification settings - Fork 174
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
objectMapper.writeValueAsString does not properly serialize Kotlin data class variables that begin with "is" #575
Comments
Reproduced in Jackson-module-kotlin: 2.12.1
produces
instead of the expected
|
@jgorgen 2.12.1 is an old version, so at very least should test with 2.12.7 (latest from 2.12). I assume reproduction is still valid but this is an important consideration in many other cases. |
reproduced with 2.13.4 ;) |
I had a look at it and it is filtered out here https://github.com/FasterXML/jackson-databind/blob/2.14/src/main/java/com/fasterxml/jackson/databind/introspect/DefaultAccessorNamingStrategy.java#L73 Seems like the getters starting with I am not sure, on what is the desired behaviour for this... |
Thank you @Richie94. Yes, that would be problematic; for original Java Beans there is this limitation -- but Kotlin does not impose it so ideally Jackson would not either, in case of Kotlin classes. |
Another thought here: does Kotlin module provide custom This could be complementary to: FasterXML/jackson-databind#3609 which would allow exposing non-boolean-returning-is-getters more generally. The main reason why I think it'd be good to do this Kotlin-specific override is if it allows solving other Kotlin-naming issues (wrt Java POJO naming Jackson assumes). |
I also think your suggestion doing it for all would be the better way, because you could also build these combinations with java code. |
The problem with doing it for all is that semantics of JAva POJOs, Scala Objects and Kotlin Objects vary to some degree. So the applies-to-all solution will never work exactly right by default for everything. That said, the basic logic for whether strict "Boolean-returning" is needed for is-getter is something that makes enough sense. It's just that if anything more fine-grained is needed, that should go via |
This issue will be fixed by #630 and therefore closed as a duplicate. |
Describe the bug
When calling the objectMapper's writeValueAsString and passing a Kotlin data class to the function, any of the variables that begin with "is" such as "isDayTime" and that is a string type, do not retain its values after serialization. This was observed after using the serialized body in a GET request to a private API where the API threw an error due to missing required parameters. This does work though if the variable is a boolean.
To Reproduce
Expected behavior
The objectMapper would serialize the data class as expected and would retain the value, regardless of the naming convention of a variable.
Versions
Kotlin: 1.7.10
Jackson-module-kotlin: 2.13.3
Jackson-databind:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: