Skip to content

Commit

Permalink
fix: Adding workaround for incorrectly cased constants returned from …
Browse files Browse the repository at this point in the history
…the API
  • Loading branch information
douglasmiller committed Oct 31, 2024
1 parent 555a0f9 commit 06dfacd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/com/recurly/v3/JsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public T read(JsonReader in) throws IOException {
in.nextNull();
return null;
}
T constant = nameToConstant.get(in.nextString());
String constantString = in.nextString();
T constant = nameToConstant.get(constantString);
// TODO: Remove this once the API stops Capitalizing the Coupon's redemption_resource
if (constant == null) {
constant = nameToConstant.get(constantString.toLowerCase());
}
if (constant == null) {
return nameToConstant.get("UNDEFINED");
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/recurly/v3/JsonSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public void testDeserialize() {
assertEquals(FixtureConstants.ConstantType.TWENTY_THREE, mockResource.getMyConstant());
}

@Test
public void testDeserializeCapitalizedEnum() {
final JsonSerializer jsonSerializer = new JsonSerializer();
final MyResource mockResource =
jsonSerializer.deserialize("{\"my_constant\":\"TwEnty-thRee\"}", MyResource.class);
assertEquals(FixtureConstants.ConstantType.TWENTY_THREE, mockResource.getMyConstant());
}

@Test
public void testDeserializeUnknownEnum() {
final JsonSerializer jsonSerializer = new JsonSerializer();
Expand Down

0 comments on commit 06dfacd

Please sign in to comment.