Java 使用flexjson序列化对象列表
我正在玩Java 使用flexjson序列化对象列表,java,android,google-cloud-endpoints,flexjson,Java,Android,Google Cloud Endpoints,Flexjson,我正在玩flexjson和googlecloudendpoints。我需要序列化的模型是: public class SampleModel { Long id; DateTime createdAt; String message; OtherModel other; } 我刚刚创建了DateTimeObjectFactory,以找到创建DateTime对象的方法(没有参数构造函数)。现在我有关于OtherModel和SampleModel的问题 实际上,我想序列化示例模型的列表。这
flexjson
和googlecloudendpoints
。我需要序列化的模型是:
public class SampleModel {
Long id;
DateTime createdAt;
String message;
OtherModel other;
}
我刚刚创建了DateTimeObjectFactory
,以找到创建DateTime
对象的方法(没有参数构造函数)。现在我有关于OtherModel
和SampleModel
的问题
实际上,我想序列化示例模型的列表
。这是我的代码:
List<SampleModel> sampleList = new ArrayList<SampleModel>();
// ...
// adding some items to sampleList
// ...
String s = new JSONSerializer().deepSerialize(sampleList);
我认为在这种反序列化中一切都很好,因为我可以在日志中看到反序列化的对象。但事实上,当我想从新的sampleList
中获取项目时,我会得到一个错误:
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.test.games.testapi.model.SampleModel
如果我理解得很好,如果我没有将正确的类指向反序列化器,那么每个不平凡的对象都将被反序列化为Map
。所以这个错误意味着脚本不知道SampleModel
?这是什么意思?如果您尝试使用它会发生什么。使用(“values”,SampleModel.class)阅读包含/排除部分,您可能会有一些想法。
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.test.games.testapi.model.SampleModel