GSON does not parse booleans (always false)

I am using Retrofit to get a JSON document. The problem is that all logical values โ€‹โ€‹are always false.

The answer is as follows:

{ "gender":[0,1], "age":[20,30], "likesLeaveHome":false, "likesSport":false, "likesCulture":false, "likesTraveling":false ... } 

I am calling the retooling method with

 onResponse(Call<SearchProfile> call, Response<SearchProfile> response) 

And the SearchProfile class that needs to be processed should look like this:

 public class SearchProfile { public ArrayList<Integer> gender = new ArrayList<>(); // works fine public ArrayList<Integer> age = new ArrayList<>(); // works fine ... public Boolean likesLeaveHome = true; // always false @SerializedName("likesSport") public boolean likesSport = true; // always false @SerializedName("likesCulture") public Boolean likesCulture; // always false @SerializedName("likesTraveling") public Boolean mLikesTraveling; // always false public boolean isLikesTraveling() { return mLikesTraveling; } public void setLikesTraveling(boolean likesTraveling) { mLikesTraveling = likesTraveling; } } 

As you can see, this is a simple pojo class. Lists such as gender and age work fine. However, boolean values โ€‹โ€‹cannot be set. (This is especially strange since sending this object via Retrofit sends this particular document, so GSON probably knows the boolean values).

As shown in the breakaway, I also tried other methods, such as assigning a Boolean wrapper class as a type instead of boolean. I also used @SerializeName annotation or getter and setts methods, etc. All logical values โ€‹โ€‹are always false. Even if I declare them to be true by default (so GSON always seems to overwrite this value with false).

Hope someone has a good idea!

+6
source share

All Articles