How to parcel cascading classes with Parceler?

63 Views Asked by At

I can parcel some models using Parceler like this:

@Parcel(Serialization.BEAN)
public class PasswordSetModel {

    private String mPassword;
    private String mRepetition;

    /* Getter & Setter */
    ...

But if this class is part of another class, the mechanism does not work. I am getting an NPE for mPasswordSetModel. Creating an instance in an constructor did not work, because the members mPassword and mRepetition were null after unparcelling.

@Parcel
public class RegistrationModel {

    private PasswordSetModel mPasswordSetModel;

    /* Getter & Setter */
    ...

So how can I parcel this using Parceler?

1

There are 1 best solutions below

0
On

okay, the problem was that I uses "wrong" setter methods. In order to use fluent interface style I made it this way:

public String getPassword() {
    return mPassword;
}

public PasswordSetModel setPassword(String password) {
    mPassword = password;
    return this;
}

public String getRepetition() {
    return mRepetition;
}

public PasswordSetModel setRepetition(String repetition) {
    mRepetition = repetition;
    return this;
}

It seems that the setters were now found and therefor the model was NULL