Pete B. Pete B. - 1 year ago 61
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:


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 Source

This works:

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

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