Re:Debunking the myths about parsing JSON in Swift
by efaref on Thursday February 18, 2016 @11:45AM
(#11127025)
True. Although the Android JsonReader class does force you to write your own parser (it is itself merely a lexer). This is really inelegant.
What I'd really like is a way to write my POD types as normal:
class Foo {
int bar;
String baz;
ArrayList<String> blah;
ArrayList<Xyz> xyzs;
}
class Xyz
{
String name;
int value;
}
And then just write this to parse it all. ...
Parser<Foo> p = new Parser<Foo>();
Foo f;
try {
f = gp.parse(input);
} catch (JsonParseException e) {
...
}
I'd be willing to accept having to annotate some of the fields, (but other than that, this should be possible to do).
The rest is just getting the parsed data out of already parsed nested dictionaries and arrays in a way that makes the type checker happy. Calling that "parsing" is probably the biggest myth of them all (though agreed about all the other myths).