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

Missing @SerializedName annotation on integer-based enums #253

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Examples/Java/Sources/Everything.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class Everything {

public enum EverythingCharEnum {
CHAR_CASE_1(-1);
@SerializedName("-1") CHAR_CASE_1(-1);
private final int value;
EverythingCharEnum(int value) {
this.value = value;
Expand All @@ -40,8 +40,8 @@ public int getValue() {
}

public enum EverythingIntEnum {
INT_CASE_1(-1),
INT_CASE_2(65536);
@SerializedName("-1") INT_CASE_1(-1),
@SerializedName("65536") INT_CASE_2(65536);
private final int value;
EverythingIntEnum(int value) {
this.value = value;
Expand All @@ -52,8 +52,8 @@ public int getValue() {
}

public enum EverythingNsintegerEnum {
NSINTEGER_CASE_1(-1),
NSINTEGER_CASE_2(4294967295);
@SerializedName("-1") NSINTEGER_CASE_1(-1),
@SerializedName("4294967295") NSINTEGER_CASE_2(4294967295);
private final int value;
EverythingNsintegerEnum(int value) {
this.value = value;
Expand All @@ -64,7 +64,7 @@ public int getValue() {
}

public enum EverythingNsuintegerEnum {
NSUINTEGER_CASE_2(4294967296);
@SerializedName("4294967296") NSUINTEGER_CASE_2(4294967296);
private final int value;
EverythingNsuintegerEnum(int value) {
this.value = value;
Expand All @@ -75,8 +75,8 @@ public int getValue() {
}

public enum EverythingShortEnum {
SHORT_CASE_1(-1),
SHORT_CASE_2(256);
@SerializedName("-1") SHORT_CASE_1(-1),
@SerializedName("256") SHORT_CASE_2(256);
private final int value;
EverythingShortEnum(int value) {
this.value = value;
Expand All @@ -91,7 +91,7 @@ public enum EverythingStringEnum {
}

public enum EverythingUnsignedCharEnum {
UNSIGNED_CHAR_CASE_2(255);
@SerializedName("255") UNSIGNED_CHAR_CASE_2(255);
private final int value;
EverythingUnsignedCharEnum(int value) {
this.value = value;
Expand All @@ -102,7 +102,7 @@ public int getValue() {
}

public enum EverythingUnsignedIntEnum {
UNSIGNED_INT_CASE_2(65536);
@SerializedName("65536") UNSIGNED_INT_CASE_2(65536);
private final int value;
EverythingUnsignedIntEnum(int value) {
this.value = value;
Expand All @@ -113,7 +113,7 @@ public int getValue() {
}

public enum EverythingUnsignedShortEnum {
CHAR_CASE_2(256);
@SerializedName("256") CHAR_CASE_2(256);
private final int value;
EverythingUnsignedShortEnum(int value) {
this.value = value;
Expand Down
6 changes: 3 additions & 3 deletions Examples/Java/Sources/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
public class Pin {

public enum PinInStock {
UNKNOWN(-1),
OUT_OF_STOCK(0),
IN_STOCK(1);
@SerializedName("-1") UNKNOWN(-1),
@SerializedName("0") OUT_OF_STOCK(0),
@SerializedName("1") IN_STOCK(1);
private final int value;
PinInStock(int value) {
this.value = value;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/JavaIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public struct JavaIR {
case let .integer(values):
let names = values
.map { ($0.description, $0.defaultValue) }
.map { "\($0.0.uppercased())(\($0.1))" }.joined(separator: ", \n")
.map { "@\(JavaAnnotation.serializedName(name: "\($0.1)").rendered) \($0.0.uppercased())(\($0.1))" }.joined(separator: ", \n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may have just been an oversight that the annotation wasn't added here. On line 400, we have this annotation for string-based enums.

let enumInitializer = JavaIR.method([], "\(name)(int value)") { [
"this.value = value;",
] }
Expand Down