utahiosmac / Marshal

Marshaling the typeless wild west of [String: Any]
MIT License
698 stars 63 forks source link

Marshalling array of different subclasses. #100

Closed mikaelbartlett closed 7 years ago

mikaelbartlett commented 7 years ago

How can I unmarshall JSON that contains an array of different subclasses?

We're using ObjectMapper right now but I have some issues with the heavy use of unwrapped optionals and handling data validation.

jarsen commented 7 years ago

Currently the best solution for this is probably to iterate through your array and look for whatever key indicates your type, and then unmarshall that object depending on the key, appending each result yourself to some [Any] if you want some single untyped array as a result.

jarsen commented 7 years ago

I'm going to go ahead and mark this issue as closed, but if you feel like that didn't answer your question or I missed something feel free to keep it going. :)