Skip to content

Commit

Permalink
Missing @SerializedName annotation on integer-based enums (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoYao authored Nov 14, 2019
1 parent fbcd34f commit 9e5c65f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
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")
let enumInitializer = JavaIR.method([], "\(name)(int value)") { [
"this.value = value;",
] }
Expand Down

0 comments on commit 9e5c65f

Please sign in to comment.