-
Notifications
You must be signed in to change notification settings - Fork 175
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
Deserialization of data classes with properties starting with uppercase char fails #173
Comments
May be related to #172 |
Edit: wrong statement, see comments further below.. |
@PeterVanco, Try using Data class would then look like this: And generated JSON will be |
after some debugging it looks like |
I mentioned above that the same issue occurs for Following my previous comment the explanation is the same - it's because the resulting Getter ( |
@cowtowncoder @apatrida what would be the logical right thing to do here? I would be happy to contribute but I'm not quite sure where / how to approach. Could you please provide some guidance / or any blockers which might even prevent this to be doable via this module? |
This seems to related to #80 |
Hi, would anyone be able to provide some guidance - I have created unit tests and spent a lot of time debugging - but I wasn't able to really understand how names are finally resolved. I have forked and created some test cases:
(see commit 74c7575) Who can
|
@hartmut-co-uk Name resolution occurs within
The real challenge is that Jackson collects indicators from all accessors -- fields, getter/setter methods, constructor parameters -- but has no knowledge of Kotlin semantics. It follows Bean specification (to a degree; plus mixing in constructor information), and has no idea of logical model of Kotlin objects but only how Kotlin compiler then generates underlying fields, methods. Anyway, that's a long way of saying that things are ... complicated. :) I will add a separate not on something I think could help here. |
Ok, so, there is one thing that is added for Jackson 2.11, to be released soon (as soon as we get #281 handled to some degree), that could help improve situation here. Addition of mechanism in databind (new method FasterXML/jackson-databind#2527 and corresponding use by Kotlin module (see #284) could perhaps be extended. As is, 2.11 will solve problem of "is-getters" (Kotlin using But perhaps it could and should also be applied to field names that start with upper case character? Could the solution be as simple as that? If anyone has time to see if this approach could lead to solution, that'd be great. I am bit swamped myself, to drive this, but would be happy to help if someone else could lead. |
@cowtowncoder, many thanks for your replies and guidance. I'll see if I can experiment some more and find something worth proposing. |
@hartmut-co-uk I would be interested in everything you find! I have been trying to think of ways to support "field name is the REAL name, try to match getters", while retaining compatibility with Java side. It is a tricky situation, and actually also relevant for plain Java use with libraries like Lombok. |
I just wanted to mention that this issue also exists for properties that are camelCased and start with less than two lowercase characters. Take for example the following data class:
I would expect, that the following statement should work:
But this Statement throws the following exception:
It seems to be that it only works if the property starts with at least two lowercase characters. So for example This is really annoying as it's very common to camelCase properties and some external classes can't be changed. |
The issue of property names in the serialization result differing from the definition in |
Deserialization of data classes with properties starting with uppercase char does not work:
Here is a simple test:
Also, serialization produces lowercase result (which may be alright):
{"name":"John Smith"}
The exception thrown:
Workaround:
class StartsWithUppercase(@JsonProperty("name") val Name: String)
The property obviously does not follow naming conventions for beans - therefore this issue is more a question - should the deserialization really fail this way in such cases?
The text was updated successfully, but these errors were encountered: