Pete B. Pete B. - 25 days ago 6
Java Question

What would this JSON string map to?

I am having a lot of trouble mapping this JSON string to something sensible in Java:

[{"key1":"xx1"},{"key2":"yyy"},{"key3":"zzz"}]


I've tried to map it to a List, a Map, and a custom object that has key1, key2, and key3 as members. None of those work.

Any ideas? I can do gson or jackson.

Answer

This works:

String json = " [{\"key1\":\"xx1\"},{\"key2\":\"yyy\"},{\"key3\":\"zzz\"}]";

Gson gson = new Gson();
List<TreeMap<String, String>> a = gson.fromJson(json, List.class);
Comments