Is serializing anonymous objects supported in kotl...
# serialization
j
Is serializing anonymous objects supported in kotlinx serialization? something like:
Copy code
@Serializable object {
    val message = "some message"
}
Seems to throw an internal error
Copy code
e: java.lang.IllegalStateException: not identifier: <no name provided>
	at org.jetbrains.kotlin.name.Name.getIdentifier(Name.java:39)
	at org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndexImpl.search(JvmDependenciesIndexImpl.kt:115)
	at org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndexImpl.traverseDirectoriesInPackage(JvmDependenciesIndexImpl.kt:77)
	at org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesDynamicCompoundIndex.traverseDirectoriesInPackage(JvmDependenciesDynamicCompoundIndex.kt:59)
	at org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndex$DefaultImpls.traverseDirectoriesInPackage$default(JvmDependenciesIndex.kt:33)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl.findPackage(KotlinCliJavaFileManagerImpl.kt:191)
b
Yeah, if you look at most of the serializable functions from the library, they require specific type parameters. So yeah, this wouldn't make sense for an anonymous object
e
how would it be deserialized?
j
Presumably the same way it would be deserialized if it were an explicit type
b
^^ I think that was a rhetorical question.
😉
j
Why would it be rhetorical lol
e
serious question, in terms of "have you thought through everything that's involved"
@Serializable
generates a KSerializer that performs both serialization and deserialization. the descriptor here needs to have a SerialName (even if you don't use it, because some formats do), the object here also does not have a constructor that a deserializer can invoke, and it definitely can't work if it captures anything
👍 1
250 Views