Polymorphism support
raderio opened this issue · 1 comments
raderio commented
sealed class Shape
class Circle(val radius: Double) : Shape
class Rectangle(val width: Double) : Shape
There are 2 types of polymorphism:
- Polymorphism by field value, aka discriminator
1.1 Discriminator embedded in object
[ { "type": "CIRCLE", "radius": 10.0 }, { "type": "RECTANGLE", "width": 20.0 } ]
1.2 Discriminator external
[ { "type": "CIRCLE", "data": { "radius": 10.0 } }, { "type": "RECTANGLE", "data": { "width": 20.0 } } ]
- Polymorphism by filed name, aka union, or
anyOf
from Swagger
[ { "radius": 10.0 }, { "width": 20.0 } ]
Because only Circle
class has radius
field, first object from list will be deserialized in Circle
class.
Also should be possible to do nested deserialization(multi level).
Please add support for all this cases.
fluidsonic commented
All cases can already be implemented manually using JSONDecoderCodec
s.
What would simplify this for you? Or is it just that you need some examples?
Are you actually using codecs or what exactly is the context here?