Skip to content

Commit a1907bf

Browse files
fix(client): don't call validate() during deserialization if we don't have to (#569)
1 parent 6978fbf commit a1907bf

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

lithic-java-core/src/main/kotlin/com/lithic/api/core/BaseDeserializer.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.JsonMappingException
1111
import com.fasterxml.jackson.databind.JsonNode
1212
import com.fasterxml.jackson.databind.deser.ContextualDeserializer
1313
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
14+
import com.lithic.api.errors.LithicInvalidDataException
1415
import kotlin.reflect.KClass
1516

1617
abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
@@ -29,6 +30,13 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
2930

3031
protected abstract fun ObjectCodec.deserialize(node: JsonNode): T
3132

33+
protected fun <T> ObjectCodec.deserialize(node: JsonNode, type: TypeReference<T>): T =
34+
try {
35+
readValue(treeAsTokens(node), type)
36+
} catch (e: Exception) {
37+
throw LithicInvalidDataException("Error deserializing", e)
38+
}
39+
3240
protected fun <T> ObjectCodec.tryDeserialize(
3341
node: JsonNode,
3442
type: TypeReference<T>,

lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,14 @@ private constructor(
416416
json.asObject().getOrNull()?.get("verification_method")?.asString()?.getOrNull()
417417

418418
if (verificationMethod == "EXTERNALLY_VERIFIED") {
419-
tryDeserialize(
420-
node,
421-
jacksonTypeRef<ExternallyVerifiedCreateBankAccountApiRequest>(),
422-
) {
423-
it.validate()
424-
}
425-
?.let {
426-
return Body(
427-
externallyVerifiedCreateBankAccountApiRequest = it,
428-
_json = json,
429-
)
430-
}
419+
return Body(
420+
externallyVerifiedCreateBankAccountApiRequest =
421+
deserialize(
422+
node,
423+
jacksonTypeRef<ExternallyVerifiedCreateBankAccountApiRequest>(),
424+
),
425+
_json = json,
426+
)
431427
}
432428

433429
tryDeserialize(node, jacksonTypeRef<BankVerifiedCreateBankAccountApiRequest>()) {

0 commit comments

Comments
 (0)