-
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
Jackson deserializes kotlin.Unit
singleton as new instances.
#196
Comments
I'm surprised by the use case of storing the value of |
I used it when one our |
@LDVSOFT can you check this against the 2.10 branch, there was a fix for |
The issues seems to be back since 2.12.0 (2.11.4 is still working):
results in |
I'm seeing the same. This issue has returned. This threw me for a pretty good runaround today! 😂 |
Is there a plan to fix this in the future or should we find another way (e.g., not use |
@schmist @hudson155 adding comments on closed issues is less visible than filing a new issue with link to earlier one, so if this is still problematic, please file a new issue. I don't have context here to know if there has been regression: if so, providing a PR for failing test case(s) (can be put under |
Unfortunately this didn't have a test so it's hard to pinpoint where it broke—someone spending time with |
With the latest Jasckon version 2.16.0-rc1, and Kotlin version 1.9.10. Object deserialize still not work, the answer of deserializing object from String, is not equals to the original object Here is a simplest example object Data
fun main() {
val jsonMapper = jacksonObjectMappe()
assert(jsonMapper.readValue<Data>("{}") == Data) // the answer is not equal
} And the simplest way to fix this in Kotlin 1.9 and above, is make object as a data class. For other version's Kotlin which is below 1.9. There is no solution for this problem now. data object Data Also, I test the mentioned version Then I checked code, I found there is a class I tried debuging. Found that is version And I traced this code, found that in Then I found it be disabled by this comment #307 . Which leads us to #281 . So the current way to solve this problem is
Hope this comment will help you guys.
|
Kotlin has builtin support for singleton classes in form of
object
-s. The most trivial one isUnit
from standard library and is used likevoid
in Java: every method that returns nothing actually returnsUnit
type, and emptyreturn
statement returnsUnit
. In most cases you would not see it as it's represented as Javavoid
, but in some cases it will be represented with singleton instance.As stated in #141, it's not in Jackson power to understand which classes are only used as singletones, but
object
ones should be considered those, especially, for example, standardUnit
.For example, let's condider that user serializes a generic structure that happens to store several
Unit
values. After serialization, they all are represented by{}
, that may not be the best form, but it's OK. But when deserialized, they all becomeUnit
instanses that are not equal to each one nor theUnit
one. The shortest form to test this is:Kotlin does expose information about
object
classes via KClass::objectInstance property. Maybe, then Jackson should (at least for stantard library classes) use it?The text was updated successfully, but these errors were encountered: