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

Boolean: is naming convention: Cannot find symbol #15

Closed
PaulWoitaschek opened this issue Mar 22, 2016 · 4 comments
Closed

Boolean: is naming convention: Cannot find symbol #15

PaulWoitaschek opened this issue Mar 22, 2016 · 4 comments

Comments

@PaulWoitaschek
Copy link

I have a very simple class:

@AutoValue public abstract class PurchaseStateModel {

    @NonNull public static PurchaseStateModel of(boolean isPurchased) {
        return new AutoValue_PurchaseStateModel(isPurchased);
    }

    public abstract boolean isPurchased();
}

Which causes an exception at compile time. It transformed "isPurchased" to "purchased".

@Override
    public void write(JsonWriter jsonWriter, PurchaseStateModel object) throws IOException {
      jsonWriter.beginObject();
      jsonWriter.name("purchased");
      purchasedAdapter.write(jsonWriter, object.purchased());
      jsonWriter.endObject();
    }
@rharter
Copy link
Owner

rharter commented Mar 22, 2016

This is because the is prefix is a common prefix, like get, for java properties, so AutoValue strips common Java property prefixes.

You can fix this by simply using Gson's @SerializedName attribute to tell it you actually do want the serialized version called isPurchased.

@rharter rharter closed this as completed Mar 22, 2016
@JakeWharton
Copy link
Contributor

Are you sure it's not this bug which I fixed in the parcel impl? rharter/auto-value-parcel@cdba2d9

@rharter
Copy link
Owner

rharter commented Mar 22, 2016

You're right. Sorry, I thought the error was in the JSON naming, not the method name. That makes sense now.

@rharter rharter reopened this Mar 22, 2016
rharter added a commit that referenced this issue Mar 22, 2016
Adds better handling of method prefixes. Fixes #15
@PaulWoitaschek
Copy link
Author

Thanks 👍

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

3 participants