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 b95fa1a..84e0991 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,