From 9874f3428435a549511aba2418f06cfea6d0b4ee Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 29 Mar 2025 02:38:21 +0000 Subject: [PATCH] fix(client): don't call `validate()` during deserialization if we don't have to --- .../kotlin/com/openlayer/api/core/BaseDeserializer.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/BaseDeserializer.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/BaseDeserializer.kt index b95fa1a3..84e09911 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/BaseDeserializer.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/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.openlayer.api.errors.OpenlayerInvalidDataException 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 OpenlayerInvalidDataException("Error deserializing", e) + } + protected fun ObjectCodec.tryDeserialize( node: JsonNode, type: TypeReference,