Skip to content

Commit

Permalink
fix: support nested generics in feel deserializer (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Jul 26, 2023
1 parent 6e3634d commit 3f7781b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

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.type.TypeFactory;
import java.util.Map;

/**
Expand All @@ -28,14 +30,14 @@
*/
public class FeelDeserializer extends AbstractFeelDeserializer<Object> {

private final Class<?> outputType;
private final JavaType outputType;
private static final FeelEngineWrapper FEEL_ENGINE_WRAPPER = new FeelEngineWrapper();

public FeelDeserializer() { // needed for references in @JsonDeserialize
this(FEEL_ENGINE_WRAPPER, Object.class);
this(FEEL_ENGINE_WRAPPER, TypeFactory.unknownType());
}

protected FeelDeserializer(FeelEngineWrapper feelEngineWrapper, Class<?> outputType) {
protected FeelDeserializer(FeelEngineWrapper feelEngineWrapper, JavaType outputType) {
super(feelEngineWrapper, true);
this.outputType = outputType;
}
Expand All @@ -50,6 +52,6 @@ protected Object doDeserialize(String expression) {

@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) {
return new FeelDeserializer(FEEL_ENGINE_WRAPPER, property.getType().getRawClass());
return new FeelDeserializer(FEEL_ENGINE_WRAPPER, property.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand Down Expand Up @@ -113,7 +114,7 @@ public <T> T evaluate(final String expression, final Object variables) {
}
}

public <T> T evaluate(final String expression, final Object variables, final Class<T> clazz) {
public <T> T evaluate(final String expression, final Object variables, final JavaType clazz) {
Object result = evaluate(expression, variables);
return objectMapper.convertValue(result, clazz);
}
Expand All @@ -138,6 +139,7 @@ public String evaluateToJson(final String expression, final Object variables) {
private Object evaluateInternal(final String expression, final Object variables) {
var variablesAsMap = ensureVariablesMap(variables);
var variablesAsMapAsScalaMap = toScalaMap(variablesAsMap);

var result = feelEngine.evalExpression(trimExpression(expression), variablesAsMapAsScalaMap);
if (result.isRight()) {
return result.right().get();
Expand Down

0 comments on commit 3f7781b

Please sign in to comment.