ankushg
12/11/2019, 7:33 PMactual typealias MyClass = String
for some platforms, while using actual data class MyClass(val someVal: String)
on other platforms. We also have an expect val MyClassSerializer: KSerializer<MyClassSerializer>
which we set equal to either StringSerializer
or the generated serializer for the data class. We declare contextual(MyClass::class, MyClassSerializer)
in our common serialization context.
On platforms where we typealias to Strings, we get a SerializerAlreadyRegisteredException: Serializer for class String already registered in this module
, even though our MyClassSerializer
points to the built-in StringSerializer
.
Is there a way to avoid this error?
• I see the overwriteWith
option, but it feels scary to use this since I'd be overwriting behavior for ALL Strings. It seems easy to declare a custom serializer for a type without realizing that this might change behavior for every String in your app.
• My understanding is that using an inline class instead of typealias might help here, but I'm not sure about the state of inline classes in multiplatform.
• Can I contextually register a serializer if-and-only-if there isn't already one registered for the type?
• Is it possible for the contextual registration to do an equality check on the KSerializer
and not throw an error if we're just redeclaring the preexisting association?Robert Jaros
12/11/2019, 7:52 PMRobert Jaros
12/11/2019, 7:53 PMRobert Jaros
12/11/2019, 7:57 PMankushg
12/11/2019, 8:11 PMinclude
to pull them into the global SerialModule we define in Common?Robert Jaros
12/11/2019, 9:04 PMRobert Jaros
12/11/2019, 9:06 PM