You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
Given JSON and MongoDB's flexibility, it would be nice if you could have a JSON with a list Views and decoded to a List<View> like this
List<View> views = decodeJson (View, json);
but each view was decoded to a TextView or MultimediaView. I use a package in C# with uses a hint field and passes it to the parser. The hint field contains as a String 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 to
abstractclassView
{
@Id() String id;
@Field() String name;
@Hint() String hint__;//Choose a rare name for the field
}
The hint field is passed like this to the decoder as an optional parameter
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.
The text was updated successfully, but these errors were encountered:
@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.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The text was updated successfully, but these errors were encountered: