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

Always keep fields of annotated enums #693

Merged
merged 1 commit into from
Sep 28, 2018

Conversation

technoir42
Copy link
Contributor

We need to keep enum fields for EnumJsonAdapter even if they are not used elsewhere.

@JsonClass(generateAdapter = false)
enum class StatusCode {
    @Json(name = "success")
    Success,
    @Json(name = "error")
    Error
}

if (status == StatusCode.Success) {
    ...
}

-keepclassmembernames won't prevent StatusCode.Error from being removed that's why -keepclassmembers should be used instead.
@gabrielittner

@ZacSweers
Copy link
Collaborator

errrr I don't think you should be annotating enums with @JsonClass, you should just keep enums (or just the ones you specifically need) instead. I'm not sure the generated adapter for this would even work, let alone be something that Moshi would look for in its adapter resolution.

@technoir42
Copy link
Contributor Author

@hzsweers ProGuard rule for enums annotated with @JsonClass was added a day ago. See #689 and #691 for context.

@ZacSweers
Copy link
Collaborator

I've been on vacation, so I missed that :). Just noticed the = false bit as well, so in that case I think this looks good 👍

@gabrielittner
Copy link
Contributor

LGTM.

I didn't run into this but I think that's just because my enums are used in exhaustive when statements so all fields are used.

@ZacSweers ZacSweers merged commit 21a9c56 into square:master Sep 28, 2018
@adams-y-chen
Copy link

adams-y-chen commented Mar 4, 2022

My enum class name is still obfuscated in the apk after added the @JsonClass(generateAdapter = false). I'm using moshi 1.12.0.
Do I have to add proguard rule to my app project in addition to annotate my enum class?

@JsonClass(generateAdapter = false)
enum class StatusCode {
    @Json(name = "success")
    Success,
    @Json(name = "error")
    Error
}

Updates:
Notice that my AGP version is 4.2.0. Do I have to upgrade AGP to new version to use support this annotation?

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

Successfully merging this pull request may close these issues.

4 participants