From 78b31f2c64a3ffbceb4475ca1bfb5344d1175557 Mon Sep 17 00:00:00 2001 From: David Ribeiro Date: Tue, 3 Feb 2026 11:51:47 +0000 Subject: [PATCH 1/3] refactor: Change how mapping is done to take camelCase usage into account --- .../AuthenticationResultAdapterFactory.java | 49 +++++++++---------- .../AuthenticationResultAdapterTest.java | 23 +++++++++ 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java b/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java index 10f4882..d1e2d79 100644 --- a/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java +++ b/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java @@ -7,10 +7,7 @@ import com.riskified.models.AuthenticationResult; import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; import java.util.Map; -import java.util.Set; /** * Gson TypeAdapterFactory for AuthenticationResult that handles backward @@ -26,7 +23,7 @@ *

* Handles field name changes between legacy and current formats: *

* @@ -54,8 +51,6 @@ public TypeAdapter create(Gson gson, TypeToken type) { */ private static class AuthenticationResultTypeAdapter extends TypeAdapter { private final TypeAdapter delegateAdapter; - private final Set manuallyHandledKeys = new HashSet(Arrays.asList(new String[] { "tran_status", - "trans_status", "tran_status_reason", "trans_status_reason", "tra_exemption", "TRA_exemption" })); AuthenticationResultTypeAdapter(Gson gson, TypeAdapterFactory skipPast) { // Get delegate adapter to avoid infinite recursion @@ -84,28 +79,30 @@ public AuthenticationResult read(JsonReader in) throws IOException { JsonObject original = element.getAsJsonObject(); JsonObject transformed = new JsonObject(); - if (original.has("tran_status")) { - transformed.add("trans_status", original.get("tran_status")); - } else if (original.has("trans_status")) { - transformed.add("trans_status", original.get("trans_status")); - } - - if (original.has("tran_status_reason")) { - transformed.add("trans_status_reason", original.get("tran_status_reason")); - } else if (original.has("trans_status_reason")) { - transformed.add("trans_status_reason", original.get("trans_status_reason")); - } - - if (original.has("tra_exemption")) { - transformed.add("TRA_exemption", original.get("tra_exemption")); - } else if (original.has("TRA_exemption")) { - transformed.add("TRA_exemption", original.get("TRA_exemption")); - } - for (Map.Entry entry : original.entrySet()) { String key = entry.getKey(); - if (!manuallyHandledKeys.contains(key)) { - transformed.add(key, entry.getValue()); + JsonElement value = entry.getValue(); + + if (key.equals("tranStatus") || key.equals("tran_status")) { + transformed.add("trans_status", value); + } + else if (key.equals("tranStatusReason") || key.equals("tran_status_reason")) { + transformed.add("trans_status_reason", value); + } + else if (key.equals("threeDChallenge")) { + transformed.add("three_d_challenge", value); + } + else if (key.equals("traExemption") || key.equals("tra_exemption")) { + transformed.add("TRA_exemption", value); + } + else if (key.equals("liabilityShift")) { + transformed.add("liability_shift", value); + } + else if (key.equals("createdAt")) { + transformed.add("created_at", value); + } + else { + transformed.add(key, value); } } diff --git a/riskified-sdk/src/test/java/com/riskified/adapters/AuthenticationResultAdapterTest.java b/riskified-sdk/src/test/java/com/riskified/adapters/AuthenticationResultAdapterTest.java index 264caf0..697509a 100644 --- a/riskified-sdk/src/test/java/com/riskified/adapters/AuthenticationResultAdapterTest.java +++ b/riskified-sdk/src/test/java/com/riskified/adapters/AuthenticationResultAdapterTest.java @@ -271,4 +271,27 @@ public void testPaypalPaymentDetails() { assertFalse("3D challenge should be false", result.get3DChallenge()); assertTrue("TRA exemption should be true", result.getTRAExemption()); } + + @Test + public void testLegacyFormatCamelCase() { + String json = "{\"credit_card_bin\":\"123456\",\"credit_card_number\":\"****1234\"," + + "\"credit_card_company\":\"Visa\",\"authentication_result\":{\"eci\":\"05\"," + + "\"cavv\":\"AAABCZIhcQAAAABZlyFxAAAAAAA=\",\"tranStatus\":\"Y\"," + + "\"tranStatusReason\":\"01\",\"liability_shift\":true," + + "\"threeDChallenge\":false,\"traExemption\":true}}"; + + CreditCardPaymentDetails details = gson.fromJson(json, CreditCardPaymentDetails.class); + + assertNotNull("Payment details should not be null", details); + assertNotNull("Authentication result should not be null", details.getAuthenticationResults()); + + AuthenticationResult result = details.getAuthenticationResults(); + assertEquals("ECI should match", "05", result.getEci()); + assertEquals("CAVV should match", "AAABCZIhcQAAAABZlyFxAAAAAAA=", result.getCavv()); + assertEquals("TransStatus should be Y", TransStatus.Y, result.getTransStatus()); + assertEquals("TransStatusReason should be Zero_One", TransStatusReason.Zero_One, result.getTransStatusReason()); + assertTrue("Liability shift should be true", result.getLiabilityShift()); + assertFalse("3D challenge should be false", result.get3DChallenge()); + assertTrue("TRA exemption should be true", result.getTRAExemption()); + } } From db4939eaebe48bab3e89f5cc9ae60a52674fad39 Mon Sep 17 00:00:00 2001 From: David Ribeiro Date: Tue, 3 Feb 2026 11:59:24 +0000 Subject: [PATCH 2/3] chore: update version --- riskified-sdk/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riskified-sdk/pom.xml b/riskified-sdk/pom.xml index da6085f..b6c1900 100644 --- a/riskified-sdk/pom.xml +++ b/riskified-sdk/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.riskified riskified-sdk - 5.0.1-rc.2 + 5.0.1-rc.3 Riskified SDK Riskified rest api SDK for java https://www.riskified.com From c7409b74adf4a346a1e20dbfa50ac98caad48e39 Mon Sep 17 00:00:00 2001 From: David Ribeiro Date: Tue, 3 Feb 2026 16:04:23 +0000 Subject: [PATCH 3/3] refactor: use hashmap isntead of conditionals to map to snake case property name --- .../AuthenticationResultAdapterFactory.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java b/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java index d1e2d79..f900274 100644 --- a/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java +++ b/riskified-sdk/src/main/java/com/riskified/adapters/AuthenticationResultAdapterFactory.java @@ -7,6 +7,7 @@ import com.riskified.models.AuthenticationResult; import java.io.IOException; +import java.util.HashMap; import java.util.Map; /** @@ -51,11 +52,32 @@ public TypeAdapter create(Gson gson, TypeToken type) { */ private static class AuthenticationResultTypeAdapter extends TypeAdapter { private final TypeAdapter delegateAdapter; + private final Map propertyMap = new HashMap<>(); AuthenticationResultTypeAdapter(Gson gson, TypeAdapterFactory skipPast) { // Get delegate adapter to avoid infinite recursion this.delegateAdapter = gson.getDelegateAdapter(skipPast, TypeToken.get(AuthenticationResult.class)); + + this.populateMap(); + + } + + private void populateMap() { + this.propertyMap.put("tranStatus", "trans_status"); + this.propertyMap.put("tran_status", "trans_status"); + + this.propertyMap.put("tranStatusReason", "trans_status_reason"); + this.propertyMap.put("tran_status_reason", "trans_status_reason"); + + this.propertyMap.put("threeDChallenge", "three_d_challenge"); + + this.propertyMap.put("tra_exemption", "TRA_exemption"); + this.propertyMap.put("traExemption", "TRA_exemption"); + + this.propertyMap.put("liabilityShift", "liability_shift"); + + this.propertyMap.put("createdAt", "created_at"); } @Override @@ -83,25 +105,9 @@ public AuthenticationResult read(JsonReader in) throws IOException { String key = entry.getKey(); JsonElement value = entry.getValue(); - if (key.equals("tranStatus") || key.equals("tran_status")) { - transformed.add("trans_status", value); - } - else if (key.equals("tranStatusReason") || key.equals("tran_status_reason")) { - transformed.add("trans_status_reason", value); - } - else if (key.equals("threeDChallenge")) { - transformed.add("three_d_challenge", value); - } - else if (key.equals("traExemption") || key.equals("tra_exemption")) { - transformed.add("TRA_exemption", value); - } - else if (key.equals("liabilityShift")) { - transformed.add("liability_shift", value); - } - else if (key.equals("createdAt")) { - transformed.add("created_at", value); - } - else { + if (this.propertyMap.containsKey(key)) { + transformed.add(this.propertyMap.get(key), value); + } else { transformed.add(key, value); } }