Description
What is the easiest way of reading class hierarchies with discriminator fields at the end of the object? Unfortunately, we need to adapt to an existing schema.
As explained in https://github.com/AVSystem/scala-commons/blob/master/docs/GenCodec.md#flat-sealed-hierarchy-format:
It may also be sensitive to object field order because the discriminator field must be read before any other fields (this is only a problem with Input implementations that do not support random field access by name - JsonStringInput does not have this problem).
I did some checks, and it seems like BsonReaderInput
has this problem, but BsonValueInput
hasn't: https://github.com/pulewicz/mongo-commons-playground/blob/master/src/main/scala/PlaygroundApp.scala#L47
Questions:
-
Is there any easy way to use
TypedMongoCollection
with value input and output? From what I see currently it's hardcoded and it will need creating your own versions of the following classes, is it correct?- https://github.com/AVSystem/scala-commons/blob/master/commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/GenCodecBasedBsonCodec.scala#L14
- https://github.com/AVSystem/scala-commons/blob/master/commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala#L10
- https://github.com/AVSystem/scala-commons/blob/master/commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecRegistry.scala#L14
- https://github.com/AVSystem/scala-commons/blob/master/commons-mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala#L35
-
Is using the value input and output a good solution, or are there any disadvantages?
Regards,
Paweł Ulewicz.