Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<T : Any>(type: KClass<T>) :
Expand All @@ -29,6 +30,13 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :

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

protected fun <T> ObjectCodec.deserialize(node: JsonNode, type: TypeReference<T>): T =
try {
readValue(treeAsTokens(node), type)
} catch (e: Exception) {
throw LithicInvalidDataException("Error deserializing", e)
}

protected fun <T> ObjectCodec.tryDeserialize(
node: JsonNode,
type: TypeReference<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,14 @@ private constructor(
json.asObject().getOrNull()?.get("verification_method")?.asString()?.getOrNull()

if (verificationMethod == "EXTERNALLY_VERIFIED") {
tryDeserialize(
node,
jacksonTypeRef<ExternallyVerifiedCreateBankAccountApiRequest>(),
) {
it.validate()
}
?.let {
return Body(
externallyVerifiedCreateBankAccountApiRequest = it,
_json = json,
)
}
return Body(
externallyVerifiedCreateBankAccountApiRequest =
deserialize(
node,
jacksonTypeRef<ExternallyVerifiedCreateBankAccountApiRequest>(),
),
_json = json,
)
}

tryDeserialize(node, jacksonTypeRef<BankVerifiedCreateBankAccountApiRequest>()) {
Expand Down