If the object that your are serializing/deserializing is a {@code ParameterizedType}(i.e. contains at least one type parameter and may be an array) then you must use the {@link #toJson(Object,Type)} or {@link #fromJson(String,Type)} method. Here is anexample for serializing and deserialing a {@code ParameterizedType}:
Type listType = new TypeToken<List<String>>() {}.getType(); List<String> target = new LinkedList<String>(); target.add("blah"); Gson gson = new Gson(); String json = gson.toJson(target, listType); List<String> target2 = gson.fromJson(json, listType);
See the Gson User Guide for a more complete set of examples.
@see com.massivecraft.mcore.xlib.gson.reflect.TypeToken @author Inderjeet Singh @author Joel Leitch
|
|
|
|