Question

I am using FlexJson within my play framework application but at the point I am trying to deseralize the json string it throws a java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean:

    User user = new JSONDeserializer<User>()
        .use(null, User.class).deserialize(body);

Body is the json string passed into the controller using standard jquery/ajax and where User has the following boolean value declared:

    public Boolean isCurrentUser;

Any ideas as to what I am doing wrong?

Thanks

Was it helpful?

Solution

In Json, Boolean is a type. Your JSon is:

{"user_id":"18","isCurrentUser":"true","title":"mr","description":"description"} 

when it should be:

{"user_id":"18","isCurrentUser":true,"title":"mr","description":"description"} 

Note that true is not a String, but a boolean. The parser fails because it finds a String instead of the expected boolean type. Fix the JSon generation to add a boolean, not a String.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top