0

I am using AutoValue in my models, I want to update the isTrue() value of the model when the user does something. So I need help. Here is my model.

@AutoValue
public abstract class Xyz implements Parcelable {

    @SerializedName("isTrue")
    public abstract boolean isTrue();

    @Nullable
    @SerializedName("lead_image_url")
    public abstract String lead_image_url();

    public static TypeAdapter<Readable> typeAdapter(Gson gson) {
        return new AutoValue_Readable.GsonTypeAdapter(gson);
    }
}
tynn
  • 38,113
  • 8
  • 108
  • 143
shivam
  • 445
  • 1
  • 8
  • 22

1 Answers1

0

The use-case for @AutoValue is creating

Generated immutable value classes ...

If you want to change a value, you'd have to create a new instance of the type, updating this one value.

This can be easily implemented with auto-value-with. Just add a with-method to your type.

public abstract Xyz withIsTrue(boolean isTrue);

The extension will implement the method copying all data to the new instance.

tynn
  • 38,113
  • 8
  • 108
  • 143