I am playing with flexjson
and Google Cloud Endpoints
. My model which I need to serialize is:
public class SampleModel {
Long id;
DateTime createdAt;
String message;
OtherModel other;
}
I just created DateTimeObjectFactory
to find a way of creating DateTime
objects (lacks of no arg constructor). Now I have question about OtherModel
and SampleModel
as well.
I want to serialize in fact a List
of SampleModel
. So here is my code:
List<SampleModel> sampleList = new ArrayList<SampleModel>();
// ...
// adding some items to sampleList
// ...
String s = new JSONSerializer().deepSerialize(sampleList);
I want to deepSerialize
it for now to avoid some unserializated fields, but just for now.
When I want to deserialize s
I do that:
sampleList = new JSONDeserializer<List<SampleModel>>()
.use("other", OtherModel.class)
.use(DateTime.class, new DateTimeObjectFactory())
.deserialize(s);
I think that everything is just ok in that kind of deserializing, because I can see in logs deserialized object. But in fact when I want to get item from that new sampleList
I get an error:
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.test.games.testapi.model.SampleModel
If I have good understanding every not trivial object will be deserialized as Map
if I don't point the right class to deserializer. So this error means that script didn't know SampleModel
? What is the meaning of this?