Skip to content

Commit 5ce9c06

Browse files
fix(client): don't call validate() during deserialization if we don't have to (#101)
1 parent 17fc1d7 commit 5ce9c06

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

+8
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.openlayer.api.errors.OpenlayerInvalidDataException
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 OpenlayerInvalidDataException("Error deserializing", e)
38+
}
39+
3240
protected fun <T> ObjectCodec.tryDeserialize(
3341
node: JsonNode,
3442
type: TypeReference<T>,

0 commit comments

Comments
 (0)