使用flexjson序列化对象列表

时间:2013-03-14 15:48:54

标签: java android google-cloud-endpoints flexjson

我正在玩flexjsonGoogle Cloud Endpoints。我需要序列化的模型是:

public class SampleModel {
 Long id;
 DateTime createdAt;
 String message;
 OtherModel other;
}

我刚刚创建了DateTimeObjectFactory来找到创建DateTime对象的方法(缺少没有arg构造函数)。现在我对OtherModelSampleModel也有疑问。

我想序列化List SampleModel List<SampleModel> sampleList = new ArrayList<SampleModel>(); // ... // adding some items to sampleList // ... String s = new JSONSerializer().deepSerialize(sampleList); 。所以这是我的代码:

deepSerialize

我现在想要s来避免一些非序列化的字段,但就目前而言。

当我想反序列化sampleList = new JSONDeserializer<List<SampleModel>>() .use("other", OtherModel.class) .use(DateTime.class, new DateTimeObjectFactory()) .deserialize(s); 时,我这样做:

sampleList

我认为在那种反序列化中一切都很好,因为我可以在日志中看到反序列化的对象。但事实上,当我想从新java.lang.ClassCastException: java.util.HashMap cannot be cast to com.test.games.testapi.model.SampleModel 获取项目时,我收到错误:

Map

如果我没有很好地理解,如果我没有将正确的类指向反序列化器,那么每个不重要的对象将被反序列化为SampleModel。所以这个错误意味着脚本不知道{{1}}?这是什么意思?

0 个答案:

没有答案
相关问题