How to parse dynamic JSON fields with GSON?

According to GSON documentation you can do things like:

Type mapType = new TypeToken<Map<Integer, Result> >() {}.getType(); // define generic type
Map<Integer, Result> result= gson.fromJson(new InputStreamReader(source), mapType);

Or you can try to write custom serializer for your class.

Disclaimer: I too, have no experience with GSon but with other frameworks like Jackson.

Leave a Comment