I've got a `MutableMap<Name, @Polymorphic T>...
# serialization
a
I've got a
MutableMap<Name, @Polymorphic T>
field, where
Name
is an inline class. I have custom serializer for name. Is it possible to somehow implement a serializer for the map inheriting polymorphic behavior?
d
(Name.serializer() to T.serializer()).map
.
a
how can I inject it in the class containing the field? Do I need to rebuild the whole serializer for the class ( and its ancestors)?
d
Oh. In that case you shouldn't have to do anything. As long as you've annotated
Name
with
@Serializable(...)
I think.
a
No, it does not work for inline class
d
Oh, even
MutableMap<@UseSerializers(....) Name, @Polymorphic T>
?
a
Let me try it
UseSerializers
could be used only on the file level and it does not help
Still got
inline classes not supported
d
The only thing I can think of is to implement a custom serializer for the whole thing.
MutableMap<Name, @Polymorphic T>
.
a
Yeah, that was my thought as well, I just do not know how to implement polymorphic serializer
d
You don't have to, you can just use
T.serializer()
.
a
I will try, It does not play well with IDEA, but maybe it will work after compillation
d
Btw, are you only dealing with json?
a
For now I use JSON, but in future I want to also access more compact formats
It does not work even with custom serializer for the whole map. Check for inline class breaks everything
@sandwwraith It seems like a bug to me. Inline class check should not block serializator override
d
As a workaround, you can cast the
Decoder
to
JsonInput
and just manually parse.
a
I've replaced
Name
by `String for now, since it is an internal property, but it requires a few additional conversions, which are not free (Name is not a String,but a List of Strings)
s
Unfortunately, current design solution is 'not allow inline classes serialization until it is implemented'. Allowing custom serializers is not enough – inline classes require additional code for wrapping/unwrapping on use site, no matter what serializer you use