FlexJSON - JSONDeserializer String Cannot be caste as Boolean

1.1k views Asked by At

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

1

There are 1 answers

1
Pere Villega On BEST ANSWER

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.