私は GSON 1.4 を使用しており、次のように 2 つのジェネリックを使用してオブジェクトをシリアル化してarraylist<myObject>
います
String data = Gson.toJson(object, object.class)
。私がそれをデシリアライズするときgson.fromJson(json, type);
悲しいことに、私は得る
java.lang.IllegalArgumentException: java.util.ArrayList フィールドを設定できません ... を java.util.LinkedList に設定します
何故ですか ?GSON doc は、object.class パラメーターを使用してシリアル化すると、ジェネリックがサポートされることに注意してください。何か案が?ありがとう。
私のクラスは:
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;
}