From 06dfacdd04d0642988cfce7c7a5c06bc2b284270 Mon Sep 17 00:00:00 2001 From: Douglas Miller Date: Wed, 30 Oct 2024 23:23:24 -0500 Subject: [PATCH] fix: Adding workaround for incorrectly cased constants returned from the API --- src/main/java/com/recurly/v3/JsonSerializer.java | 7 ++++++- src/test/java/com/recurly/v3/JsonSerializerTest.java | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recurly/v3/JsonSerializer.java b/src/main/java/com/recurly/v3/JsonSerializer.java index d708e5a3..f149a057 100644 --- a/src/main/java/com/recurly/v3/JsonSerializer.java +++ b/src/main/java/com/recurly/v3/JsonSerializer.java @@ -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"); } diff --git a/src/test/java/com/recurly/v3/JsonSerializerTest.java b/src/test/java/com/recurly/v3/JsonSerializerTest.java index 0f9755ed..958bd14e 100644 --- a/src/test/java/com/recurly/v3/JsonSerializerTest.java +++ b/src/test/java/com/recurly/v3/JsonSerializerTest.java @@ -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();