-
Notifications
You must be signed in to change notification settings - Fork 525
Dynamic code generation: support Kotlin data classes with non-nullable properties #170
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
Comments
I have no experience of kotlin. Any one can help on this? |
Data classes themselves introduce nothing special — they implement
I've omitted types, but they are inferred. Kotlin is statically-typed and preserves them, and uses primitive Java types when possible, despite they are absent at language level. So, class structure has no serious differences from Java's one. |
I think I'll get a list of all constructors, choose the one with the least amount of parameters, and provide non null values to them. If the parameters type is not a standard one like Long, String and such, then I don't know what the best approach would be... |
Why non null? What if the value is nullable? |
It already fails really fast ;) The point of the current issue is to provide support for Kotlin classes with non-nullable properties. Currently, null values are passed to the constructor, and the constructor throws an exception because the properties are non-nullable. My idea is to change jsoniter library so that it chooses non-null values to pass to the constructor. |
If there's no such value, what deserializer should do? Use defaults values? |
Upon further reflection on this, I think the constructor should be called with the values read from the JSON being parsed. Otherwise, we'll have to pass it a default value and then call the Java reflection API to set any final fields to the desired values. All of this should be doable without kotlin-reflect, I guess. |
It seems that Kotlin data classes with non-nullable properties or with immutable properties (val) don't get their values when deserialized.
Related: #55
The text was updated successfully, but these errors were encountered: