Skip to content

Commit

Permalink
issues/263 - Changed to obtain TypeFactory from the DeserializationCo…
Browse files Browse the repository at this point in the history
…ntext.
  • Loading branch information
meywood committed Apr 15, 2024
1 parent daa747a commit 8d58c1c
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package com.casper.sdk.jackson.deserializer;

import java.io.IOException;

import com.casper.sdk.exception.NoSuchTypeException;
import com.casper.sdk.jackson.resolver.CLValueResolver;
import com.casper.sdk.model.clvalue.AbstractCLValue;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.casper.sdk.jackson.resolver.CLValueResolver;
import com.casper.sdk.model.clvalue.AbstractCLValue;

import java.io.IOException;

/**
* Core Deserializer for the CLValue property. This deserializer is used by the
* {@link CLValueResolver} to return the correct CLType object in Java depending
* on the cl_type sent over json
*
*
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
* @see AbstractCLValue
* @since 0.0.1
*/
public abstract class AbstractAnyOfDeserializer extends AsPropertyTypeDeserializer {

protected AbstractAnyOfDeserializer(final JavaType bt, final TypeIdResolver idRes, final String typePropertyName,
final boolean typeIdVisible, JavaType defaultImpl) {
final boolean typeIdVisible, JavaType defaultImpl) {
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}

Expand All @@ -50,7 +45,7 @@ public Object deserializeTypedFromObject(final JsonParser jp, final Deserializat
} catch (NoSuchTypeException e) {
throw new IOException("Parse error", e);
}
TypeFactory factory = new ObjectMapper().getTypeFactory();
TypeFactory factory = ctxt.getTypeFactory();
JavaType type = factory.constructType(subType);

try (JsonParser jsonParser = new TreeTraversingParser(node, jp.getCodec())) {
Expand All @@ -64,9 +59,9 @@ public Object deserializeTypedFromObject(final JsonParser jp, final Deserializat

/**
* Returns the node which contains the type key.
*
* <p>
* Override if you have a child node which holds the type information.
*
*
* @param currentNode the current deserialization node
* @return node which contains the type key.
*/
Expand All @@ -76,7 +71,7 @@ protected JsonNode getTypeNode(JsonNode currentNode) {

/**
* Method that returns the instance of the found type
*
*
* @param classType the name of the class type
* @return {@link Class} of the type
* @throws NoSuchTypeException thrown if no type for the given classType String
Expand Down

0 comments on commit 8d58c1c

Please sign in to comment.