0

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": [email protected]
 "pincode": "000001"
 "emailCc": ""
 "addressList": []
 "stability": true
}
Doug Stevenson
321k37 gold badges458 silver badges474 bronze badges
asked Dec 11, 2023 at 13:12
3
  • Can you share the code from where you are calling the API? Commented Dec 11, 2023 at 13:43
  • Does interface Parcelable have a default method isStability() or getStability()? Some JSON frameworks like Jackson by default include every method that looks like a getter, even if it returns a calculated value. Commented Dec 11, 2023 at 18:08
  • @RobSpoor Yes it does. The Parcelable interface is from the package 'android.os'. And yes we are using com.fasterxml.jackson Commented Dec 12, 2023 at 7:28

1 Answer 1

2

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 {
 ...
}
answered Dec 12, 2023 at 8:20
Sign up to request clarification or add additional context in comments.

3 Comments

Let me try this and check for a week or two. Thanks for the suggestion. This should work in my opinion
It has been happening since API 34
According to android.googlesource.com/platform/frameworks/base/+blame/refs/… the getStability() method that is causing this issue was added at 2020年07月23日 01:21:52 +0000. That implies that it's already part since API 31 (possibly even 29 or 30). What was your previous API version?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.