Open cgarciae opened 9 years ago
This is a pretty cool feature indeed. I'll take a look at it and let you know.
@luizmineo Reflecting a little bit, since Redstone Mapper uses annotations it might not be necessary to pass the hint field name to decodeJson
, instead have it "reflect" to see if the parent class (View
in this case) has a parameter annotated with @Hint()
, and if it does use that name. In case no hint field is provided, just decode to the parent class as normal.
Just checked an JsonFx
(the C# library) doesn't use a hint field on the class, the field appears on the json when encoded, and it is expected when decoded, but the actual object doesn't contain it.
Say you have the abstract class
And the subclasses
Given JSON and MongoDB's flexibility, it would be nice if you could have a JSON with a list
View
s and decoded to aList<View>
like thisbut each view was decoded to a
TextView
orMultimediaView
. I use a package in C# with uses ahint
field and passes it to the parser. The hint field contains as aString
the name of the class that object should be encoded to, and the hint is passes to the decoder as a parameter. So you have to change View toThe hint field is passed like this to the decoder as an optional parameter
and a working example could be
This way you can treat these object in a general way, store them in the same collection, move them around in together, have each override the abstract methods, etc.