I'm getting an error trying to deserialize what I believe is a valid JSON string:
String json = "{\"email\":\"[email protected]\",\"password\":\"12345\"}";
// FlexJSON deserializer
JSONDeserializer<Signin> deserializer = new JSONDeserializer<Signin>();
// Deserialize into a Signin POJO.
Signin signin = deserializer.deserialize(json);
When I run this code, I get:
java.util.HashMap cannot be cast to com.myapp.server.Signin
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.myapp.server.Signin
at com.myapp.server.SigninService.doPost(SigninService.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
... rest of stack trace omitted for brevity
Is my JSON malformed? It's almost as if the JSON is somehow "bad" and FlexJSON is treating it like a HashMap...
Looking at the documentation, the problem is that your json doesn't declare its class. This means that you explicitly need to supply a
Class
object to the deserializer, as in Java generics are only compile time, not runtime.To quote from the documentation:
So use: