File tree 1 file changed +8
-0
lines changed
openlayer-java-core/src/main/kotlin/com/openlayer/api/core
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.JsonMappingException
11
11
import com.fasterxml.jackson.databind.JsonNode
12
12
import com.fasterxml.jackson.databind.deser.ContextualDeserializer
13
13
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
14
+ import com.openlayer.api.errors.OpenlayerInvalidDataException
14
15
import kotlin.reflect.KClass
15
16
16
17
abstract class BaseDeserializer <T : Any >(type : KClass <T >) :
@@ -29,6 +30,13 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
29
30
30
31
protected abstract fun ObjectCodec.deserialize (node : JsonNode ): T
31
32
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
+
32
40
protected fun <T > ObjectCodec.tryDeserialize (
33
41
node : JsonNode ,
34
42
type : TypeReference <T >,
You can’t perform that action at this time.
0 commit comments