From e4ad9b0fb985834fd6e3a11d5bd2435ea1e0f2be Mon Sep 17 00:00:00 2001 From: Pavel Kotelevsky <38818382+chillleader@users.noreply.github.com> Date: Tue, 18 Jul 2023 18:02:18 +0200 Subject: [PATCH] fix: support nested generics in feel deserializer (#528) --- .../camunda/connector/impl/feel/FeelDeserializer.java | 10 ++++++---- .../camunda/connector/impl/feel/FeelEngineWrapper.java | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/io/camunda/connector/impl/feel/FeelDeserializer.java b/core/src/main/java/io/camunda/connector/impl/feel/FeelDeserializer.java index 495baaa0c4..3ea09b9370 100644 --- a/core/src/main/java/io/camunda/connector/impl/feel/FeelDeserializer.java +++ b/core/src/main/java/io/camunda/connector/impl/feel/FeelDeserializer.java @@ -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; /** @@ -28,14 +30,14 @@ */ public class FeelDeserializer extends AbstractFeelDeserializer { - 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; } @@ -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()); } } diff --git a/core/src/main/java/io/camunda/connector/impl/feel/FeelEngineWrapper.java b/core/src/main/java/io/camunda/connector/impl/feel/FeelEngineWrapper.java index 8b833ea4b8..b46291bac5 100644 --- a/core/src/main/java/io/camunda/connector/impl/feel/FeelEngineWrapper.java +++ b/core/src/main/java/io/camunda/connector/impl/feel/FeelEngineWrapper.java @@ -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; @@ -113,7 +114,7 @@ public T evaluate(final String expression, final Object variables) { } } - public T evaluate(final String expression, final Object variables, final Class clazz) { + public T evaluate(final String expression, final Object variables, final JavaType clazz) { Object result = evaluate(expression, variables); return objectMapper.convertValue(result, clazz); } @@ -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();