Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Retrofit always returns false value for the type boolean while fetching jsonobject

I am new using retrofit and here i am stuck with an problem where retrofit always returns false for boolean type object which is actually 1(true) which i am retriving.

here below is my pojo class for retriving data

public class JobsModel implements Serializable {

@SerializedName("posted_on")
private String postedOn;
@SerializedName("is_active")
private boolean isActive=false;

public JobsModel(String postedOn, boolean isActive) {
    this.postedOn=postedOn;
    this.isActive=isActive;
}

public Boolean getPostedOn() {
    return postedOn
}

public void setPostedOn(String postedOn) {
    postedOn= postedOn
}

public Boolean getActive() {
    return isActive;
}

public void setActive(Boolean active) {
    isActive = active;
}

}

any help would be much appreciated

like image 393
md gouse Avatar asked Mar 06 '26 04:03

md gouse


1 Answers

first of all change private boolean isActive=false; to private boolean Active;

Secondly change

   public void setActive(Boolean active) {
        isActive = active;   }

to

public void setActive(boolean active) {
    Active = active;

}

and If your JSON contains any object starting with I then change it,cause it will always return false. Hope this will be helpful to you.

like image 141
flashberry Avatar answered Mar 08 '26 17:03

flashberry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!