From 4d4f3a09519a313c4bed79590caeab3aaeb7c30f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 28 Mar 2025 13:24:47 +0000 Subject: [PATCH] fix(client): don't call `validate()` during deserialization if we don't have to --- .../com/lithic/api/core/BaseDeserializer.kt | 8 ++++++++ .../models/ExternalBankAccountCreateParams.kt | 20 ++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/core/BaseDeserializer.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/core/BaseDeserializer.kt index 70addadfe..629271a9c 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/core/BaseDeserializer.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/core/BaseDeserializer.kt @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.deser.ContextualDeserializer import com.fasterxml.jackson.databind.deser.std.StdDeserializer +import com.lithic.api.errors.LithicInvalidDataException import kotlin.reflect.KClass abstract class BaseDeserializer(type: KClass) : @@ -29,6 +30,13 @@ abstract class BaseDeserializer(type: KClass) : protected abstract fun ObjectCodec.deserialize(node: JsonNode): T + protected fun ObjectCodec.deserialize(node: JsonNode, type: TypeReference): T = + try { + readValue(treeAsTokens(node), type) + } catch (e: Exception) { + throw LithicInvalidDataException("Error deserializing", e) + } + protected fun ObjectCodec.tryDeserialize( node: JsonNode, type: TypeReference, diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt index 817f23fc0..a6204ca51 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt @@ -416,18 +416,14 @@ private constructor( json.asObject().getOrNull()?.get("verification_method")?.asString()?.getOrNull() if (verificationMethod == "EXTERNALLY_VERIFIED") { - tryDeserialize( - node, - jacksonTypeRef(), - ) { - it.validate() - } - ?.let { - return Body( - externallyVerifiedCreateBankAccountApiRequest = it, - _json = json, - ) - } + return Body( + externallyVerifiedCreateBankAccountApiRequest = + deserialize( + node, + jacksonTypeRef(), + ), + _json = json, + ) } tryDeserialize(node, jacksonTypeRef()) {