Skip to content

Commit

Permalink
Merge pull request #281 from recurly/redemption-resource-fix
Browse files Browse the repository at this point in the history
fix: Adding workaround for incorrectly cased constants returned from the API
  • Loading branch information
andcoca authored Oct 31, 2024
2 parents 555a0f9 + 06dfacd commit 53479e1
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 53479e1

Please sign in to comment.