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

weird Enum pattern causes problems for clients #235

Closed
andersonbd1 opened this issue Apr 23, 2019 · 3 comments
Closed

weird Enum pattern causes problems for clients #235

andersonbd1 opened this issue Apr 23, 2019 · 3 comments

Comments

@andersonbd1
Copy link

Wouldn't it make more sense for your Enum constants to look like this:

  public static enum EnumCustomerFileSource {
      BOTH_USER_AND_PARTNER_PROVIDED,
      PARTNER_PROVIDED_ONLY,
      ...
      // NULL isn't necessary
  }

as opposed to this:

  public static enum EnumCustomerFileSource {
      @SerializedName("BOTH_USER_AND_PARTNER_PROVIDED")
      VALUE_BOTH_USER_AND_PARTNER_PROVIDED("BOTH_USER_AND_PARTNER_PROVIDED"),
      @SerializedName("PARTNER_PROVIDED_ONLY")
      ...
      NULL(null);

      private String value;

      private EnumCustomerFileSource(String value) {
        this.value = value;
      }

      @Override
      public String toString() {
        return value;
      }
  }

it's less code, simpler, and avoids problems like this for clients:
FasterXML/jackson-databind#2309

@andersonbd1
Copy link
Author

@jingping2015 - any thoughts on this?

@jingping2015
Copy link
Contributor

Hi ,
Thanks for reporting this issue. Actually @SerializedName annotation is used for serializing and deserializing by GSON. So we are not be able to just have enum constants like you proposed.

@andersonbd1
Copy link
Author

Thanks @jingping2015 . What about the NULL(null);. Is that really necessary? It doesn't work with Jackson (see link above).

facebook-github-bot pushed a commit that referenced this issue Sep 20, 2019
Summary:
#235

Looks like we don't need `NULL` for enum class

Reviewed By: joesus

Differential Revision: D17242244

fbshipit-source-id: 33c2cc4c
facebook-github-bot pushed a commit to facebook/facebook-business-sdk-codegen that referenced this issue Sep 20, 2019
Summary:
facebook/facebook-java-business-sdk#235

Looks like we don't need `NULL` for enum class

Reviewed By: joesus

Differential Revision: D17242244

fbshipit-source-id: 33c2cc4c
jlavera pushed a commit to order-metrics/facebook-java-business-sdk that referenced this issue Sep 29, 2020
Summary:
facebook#235

Looks like we don't need `NULL` for enum class

Reviewed By: joesus

Differential Revision: D17242244

fbshipit-source-id: 33c2cc4c
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

2 participants