Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters and Setter Alphabetically Order for Write and Read #405

Open
OKivuu opened this issue Oct 25, 2023 · 0 comments
Open

Getters and Setter Alphabetically Order for Write and Read #405

OKivuu opened this issue Oct 25, 2023 · 0 comments

Comments

@OKivuu
Copy link

OKivuu commented Oct 25, 2023

First, thanks for sharing the library. So... got an issue on methods naming that using a class object that is unwrapped on a client app using my lib (version 1.x). Later on i had to add a new field (version 2.x) but the client was still unwrapping using the old lib version 1.x. Saw on generated $$Pacelable the the new field was not added at the end of the wirte and read bytes calls, but was put at first because of its naming starting with "a" so ordering alphabetically messing up the old bytes read fields

Above is the code of 1.x and commented the new field added in 2.x:

package br.com.testparcel;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import org.parceler.IdentityCollection;
import org.parceler.ParcelerRuntimeException;

@Parcel(Parcel.Serialization.BEAN)
public class MyData {

    public MyData() {
    }

    public MyData(@NonNull String pathResponse, String acqPath, @NonNull String responseMessage) {
        this();
        this.pathResponse = pathResponse;
        this.acqPath = acqPath;
        this.responseMessage = responseMessage;
    }

// Added this field on newer version
//    @NonNull
//    private String acqAdditional;

    @NonNull
    private String pathResponse;

    private String acqPath;

    @NonNull
    private String responseMessage;

    @NonNull
    public String getPathResponse() {
        return pathResponse;
    }

    public void setPathResponse(@NonNull String pathResponse) {
        this.pathResponse = pathResponse;
    }

    public String getAcqPath() {
        return acqPath;
    }

    public void setAcqPath(String acqPath) {
        this.acqPath = acqPath;
    }

    @NonNull
    public String getResponseMessage() {
        return responseMessage;
    }

    public void setResponseMessage(@NonNull String responseMessage) {
        this.responseMessage = responseMessage;
    }

/*
    public void setAcqAdditional(@NonNull String acqAdditional) {
        this.acqAdditional = acqAdditional;
    }

    @NonNull
    public String getAcqAdditional() {
        return acqAdditional;
    }
*/
}

And this is the generated class with the code of 2.x (uncommented lines):

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package br.com.testparcel;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import org.parceler.IdentityCollection;
import org.parceler.ParcelWrapper;
import org.parceler.ParcelerRuntimeException;

public class MyData$$Parcelable implements Parcelable, ParcelWrapper<MyData> {
    private MyData myData$$0;
    public static final Creator<MyData$$Parcelable> CREATOR = new Creator<MyData$$Parcelable>() {
        public MyData$$Parcelable createFromParcel(Parcel parcel$$2) {
            return new MyData$$Parcelable(MyData$$Parcelable.read(parcel$$2, new IdentityCollection()));
        }

        public MyData$$Parcelable[] newArray(int size) {
            return new MyData$$Parcelable[size];
        }
    };

    public MyData$$Parcelable(MyData myData$$2) {
        this.myData$$0 = myData$$2;
    }

    public void writeToParcel(Parcel parcel$$0, int flags) {
        write(this.myData$$0, parcel$$0, flags, new IdentityCollection());
    }

    public static void write(MyData myData$$1, Parcel parcel$$1, int flags$$0, IdentityCollection identityMap$$0) {
        int identity$$0 = identityMap$$0.getKey(myData$$1);
        if (identity$$0 != -1) {
            parcel$$1.writeInt(identity$$0);
        } else {
            parcel$$1.writeInt(identityMap$$0.put(myData$$1));
            parcel$$1.writeString(myData$$1.getAcqAdditional());
            parcel$$1.writeString(myData$$1.getAcqPath());
            parcel$$1.writeString(myData$$1.getPathResponse());
            parcel$$1.writeString(myData$$1.getResponseMessage());
        }

    }

    public int describeContents() {
        return 0;
    }

    public MyData getParcel() {
        return this.myData$$0;
    }

    public static MyData read(Parcel parcel$$3, IdentityCollection identityMap$$1) {
        int identity$$1 = parcel$$3.readInt();
        if (identityMap$$1.containsKey(identity$$1)) {
            if (identityMap$$1.isReserved(identity$$1)) {
                throw new ParcelerRuntimeException("An instance loop was detected whild building Parcelable and deseralization cannot continue.  This error is most likely due to using @ParcelConstructor or @ParcelFactory.");
            } else {
                return (MyData)identityMap$$1.get(identity$$1);
            }
        } else {
            int reservation$$0 = identityMap$$1.reserve();
            MyData myData$$4 = new MyData();
            identityMap$$1.put(reservation$$0, myData$$4);
            myData$$4.setAcqAdditional(parcel$$3.readString());
            myData$$4.setAcqPath(parcel$$3.readString());
            myData$$4.setPathResponse(parcel$$3.readString());
            myData$$4.setResponseMessage(parcel$$3.readString());
            identityMap$$1.put(identity$$1, myData$$4);
            return myData$$4;
        }
    }
}

After all, want to know if is there a way of making the get and set of AcqAdditional be at the end of the write and read methods after the setResponseMessage and getResponseMessage without having to rename the AcqAdditional field because it is already in use for other clients

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant