Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "json"
- # Big thanks to @hzhzhzhz1111 for this useful example!
- class Result
- include JSON::Serializable
- use_json_discriminator "type", {tenant: Tenant, dcim: DCIM}
- property type : String
- end
- class Tenant < Result
- property name : String
- end
- class DCIM < Result
- property name : String
- end
- class Results
- include JSON::Serializable
- property count : Int32
- property next : Int32?
- property previous : Int32?
- property results : Array(Result)
- end
- j = %({"count": 32, "next": null, "previous": null, "results": [{"type": "tenant", "name": "abc"}, {"type": "dcim", "name": "abc"}]})
- p Results.from_json(j)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement