Google-gson is a java library from Google for encoding and decoding JSON text.
Get the latest binaries from
http://code.google.com/p/google-gson/.
The following example shows serializing and de-serializing generic types.
/**
* @param args
*/ public static void main(String[] args) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
List<String> strings = Arrays.asList("ONE", "TWO", "THREE", "FOUR");
String jsonStr = gson.toJson(strings);
System.out.println(jsonStr); //We loose the type info once we serialize to JSON string
//Specify the explicit type for de-serialization
Type listType = new TypeToken<List<String>>() {}.getType();
strings = gson.fromJson(jsonStr, listType);
System.out.println(strings);
}