-
-
Notifications
You must be signed in to change notification settings - Fork 177
Deserializing singleton object causes different instances #141
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
This is outside the scope of the module, you cannot replace an object singleton in Kotlin, and if it is immutable values the content could not be set. Jackson does not "bind into existing instances" for any case and the definition of |
The only addition I have is that Jackson 2.9 does actually allow "merging", in which case existing Object instance will be modified. This is controlled by one of:
That said, I don't know if that could be relevant here; the root value is trickier, as intent is that caller would use Specifically I don't know if Kotlin has enough metadata to let runtime understand that given class only exists for singleton usage. If not, there's not much that can be done automatically. |
I don't really understand the problem here, you can detect if a class corresponds to a singleton object by checking it's constructors, then calling $ kotlinc-jvm
Welcome to Kotlin version 1.3.41 (JRE 11.0.7+10-LTS)
Type :help for help, :quit for quit
>>> object Foo
>>> data class Bar(val baz: String)
>>> class Quux()
>>> val fooClass = Foo::class
>>> val barClass = Bar::class
>>> val quuxClass = Quux::class
>>> println(listOf(fooClass, barClass, quuxClass).map { it.simpleName to it.constructors })
[(Foo, []), (Bar, [fun <init>(kotlin.String): Line_1.Bar]), (Quux, [fun <init>(): Line_2.Quux])]
>>> fooClass.objectInstance
res8: Line_0.Foo? = Line_0$Foo@5788722f
>>> barClass.objectInstance
res9: Line_1.Bar? = null
>>> quuxClass.objectInstance
res10: Line_2.Quux? = null
>>> |
Sorry for the noise, this actually ended up getting fixed in #244 |
Step to reproduce:
Expect behavior:
object declaration
should be only one instance per VMEnvironment:
Oracle JDK 1.8 (also reproduce in Android)
Kotlin 1.2.30
Jackson, Jackson kotlin - 2.9.4
The text was updated successfully, but these errors were encountered: