5 ms·
How does this deal with deserializing json arrays? Unless you have reified generics it's impossible. This is a common headache when working with Jackson.
by Gurkenmaster 12y ago
How does this deal with deserializing json arrays? Unless you have reified generics it's impossible. This is a common headache when working with Jackson.
- breakingcups 12y agoThe example linked and described already deals with deserializing json arrays. What trouble exactly are you experiencing?
- Spiritus 12y agoNot the parent, but my biggest issue with arrays and nested objects is this: Most JSON arrays come in the form { "objects": [{"foo": "bar"}, ...] } Instead of `[{"foo": "bar"}, ...]`. So I need to create a temporary struct, it would've been nice to be able to provide a starting point or similar. Like `json.UnmarshalFrom(data, &foos, "objects")` (hmm, this gave me an idea!). Another example is this: type Address struct { street string city string } And I want to parse that populate that struct with the data from { "name": "John Doe", "address": { "street": "Some street 1", "city": "Footown" }, ... } Again I have to use temporary struct.
- bcgraham 12y agoFor deeply nested structures, it'll always be a bit of a hassle. In your toy example, you can use struct literals to get to the guts of the object quickly. https://play.golang.org/p/VE90fwT0sE https://play.golang.org/p/VE90fwT0sE
- Gurkenmaster 12y agoSorry I actually meant Lists. In Java List<String> is just List (since they aren't reified) at compile time so you have to explicitly deserialize an String[] and then manually throw it into an ArrayList<String>.