3 ms·
You specify the type to deserialise to. This lets you be very concrete about this if you have versioned API endpoint or different data source. Alternatively if
by kimburgess 6y ago
You specify the type to deserialise to. This lets you be very concrete about this if you have versioned API endpoint or different data source. Alternatively if you deserialise into a type union, the first compatible type will be used. Finally, you can also use a discriminator field [1] to select an appropriate subtype.
[1]: https://crystal-lang.org/api/0.35.1/JSON/Serializable.html#use_json_discriminator(field,mapping)-macro https://crystal-lang.org/api/0.35.1/JSON/Serializable.html#u...
- valenterry 6y agoI mean, what if the type I deserialize into is the same (my current domain object type), but I have to deserialize two (or more) different versions of json into it. I think what you linked is the case where my domain object type is either A or B - but that's not what I meant.