Closed tylergets closed 7 years ago
The easiest way is to define values
as List<Map<String, Object>>
.
You can also implement custom JSON adapter for objects contained by values attribute which produces different type of value based on their value. https://github.com/square/moshi#custom-type-adapters
Or you can define values
as JsonBuffer
which stores the data stream temporarily. And decide the adapter being used to deserialize at runtime.
Say I have a resource, in my example a "GraphObject".
It looks like this
The nested field "values" will change, right now it contains an id,x, and y value. It's possible for that values field to contain other data (Such as name and count, if it's a pie graph)
I have attempted some OOP magic, but I am getting cast exceptions because of the internal values model. Is there a way to handle this and parse values to a hash map?
Thanks!