I am using GSON 1.4 and serializing an object with two generic arraylist<myObject>
as follows
String data = Gson.toJson(object, object.class)
. When I desirialize it I do gson.fromJson(json, type);
sadly I get
java.lang.IllegalArgumentException: Can not set java.util.ArrayList field ... to java.util.LinkedList
Why is that ? GSON doc notes that if I serialize with object.class parameter it supports generics. any idea? thanks.
my class is :
public class IndicesAndWeightsParams {
public List<IndexParams> indicesParams;
public List<WeightParams> weightsParams;
public IndicesAndWeightsParams() {
indicesParams = new ArrayList<IndexParams>();
weightsParams = new ArrayList<WeightParams>();
}
public IndicesAndWeightsParams(ArrayList<IndexParams> indicesParams, ArrayList<WeightParams> weightsParams) {
this.indicesParams = indicesParams;
this.weightsParams = weightsParams;
}
}
public class IndexParams {
public IndexParams() {
}
public IndexParams(String key, float value, String name) {
this.key = key;
this.value = value;
this.name = name;
}
public String key;
public float value;
public String name;
}
Type type = new TypeToken