You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Attempting to retrieve a serializer via serializer(typeOf<SimpleNamedCompanion>()) wrongly declares that SimpleNamedCompanion needs to be marked with Serializable, even though they are.
This does not happen if the default plugin generated serializer is used, or on targets other than the JVM. The Platform check for companion objects for the JVM only checks if there's a declared field named "Companion", which fails if it's named anything else.
To Reproduce
Attach a code snippet or test data if possible.
Unfortunately it is impossible to understand that named object is a companion using only standard JVM reflection. kotlin-reflect-full is needed for this, but we have to avoid dependency on it in kotlinx-serialization. Therefore, general recommendation is to avoid using named companions in the serializable classes.
Compiler intrinsics (see #1348) solve with this problem when using serializer() with reified type argument instead of KType.
Describe the bug
Attempting to retrieve a serializer via
serializer(typeOf<SimpleNamedCompanion>())
wrongly declares that SimpleNamedCompanion needs to be marked with Serializable, even though they are.This does not happen if the default plugin generated serializer is used, or on targets other than the JVM. The Platform check for companion objects for the JVM only checks if there's a declared field named "Companion", which fails if it's named anything else.
To Reproduce
Attach a code snippet or test data if possible.
I've also attached a test suite at UnderMybrella/KotlinMRE
Expected behavior
The serializer should be retrievable.
Environment
The text was updated successfully, but these errors were encountered: