Here is my class:
public class OutstandingContact implements Parcelable {
public String phoneNumber;
public String gstIn;
public String cin;
public String email;
public String pincode;
public String emailCc;
public List<String> addressList;
public OutstandingContact() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.phoneNumber);
parcel.writeString(this.gstIn);
parcel.writeString(this.cin);
parcel.writeString(this.email);
parcel.writeString(this.pincode);
parcel.writeString(this.emailCc);
parcel.writeStringList(this.addressList);
}
protected OutstandingContact(Parcel in) {
this.phoneNumber = in.readString();
this.gstIn = in.readString();
this.cin = in.readString();
this.email = in.readString();
this.pincode = in.readString();
this.emailCc = in.readString();
this.addressList = in.createStringArrayList();
}
public static final Creator<OutstandingContact> CREATOR = new Creator<OutstandingContact>() {
@Override
public OutstandingContact createFromParcel(Parcel source) {
return new OutstandingContact(source);
}
@Override
public OutstandingContact[] newArray(int size) {
return new OutstandingContact[size];
}
};
}
While sending this as a body in a server API request (POST) the object 'stability' get added to it automatically. This is not reproducible for my device but users are facing this where the server request validations are failing.
For eg: The body goes like this:
{
"phoneNumber": "99999999"
"gstIn": ANDNFJKDNF43848"
"cin": ""
"email": abc@whatever.com
"pincode": "000001"
"emailCc": ""
"addressList": []
"stability": true
}
Jackson by default includes each property that has a getter. That includes methods like isStability()
or getStability()
- not just methods you define yourself but also inherited methods, and that includes default methods.
Since this Parcelable
interface isn't yours you cannot annotate this getter with @JsonIgnore
. You could override it only to add it, but Jackson has a similar annotation you can put on your class: JsonIgnoreProperties
:
@JsonIgnoreProperties("stability")
public class OutstandingContact implements Parcelable {
...
}