AutoValue Usage

Bradley Campbell edited this page Nov 27, 2016 · 7 revisions

Important: all information in this on this page is only relevant to PaperParcel 1.x. For information on the latest version of PaperParcel, visit http://grandstaish.github.io/paperparcel/

Basic usage

Simply implement Parcelable on your AutoValue class and PaperParcel's AutoValue extension will take care of the rest, e.g.:

@AutoValue
public abstract class Example implements Parcelable {
    public abstract int test();
    public static State create(int test) {
        return new AutoValue_Example(test);
    }
}

Now your AutoValue class can be passed directly to a Bundle or Intent.

A simple example can be found in the autovalue-example module.

TypeAdapter usage

Any TypeAdapter annotated with @DefaultAdapter will be used automatically unless a more specifically scoped adapter is applied.

For class-scoped TypeAdapters, apply directly to the @AutoValue class, e.g.:

@AutoValue
@TypeAdapters(DateTypeAdapter.class)
public abstract class Example implements Parcelable {
    ...
}

For variable-scoped TypeAdapters, apply directly to the abstract property method, e.g.:

@AutoValue
public abstract class Example implements Parcelable {
    @TypeAdapters(DateTypeAdapter.class)
    public abstract Date test();
    ...
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.