diff --git a/core/src/main/java/io/kestra/core/models/property/Property.java b/core/src/main/java/io/kestra/core/models/property/Property.java index 3c7d0860203..e7c4c1a81eb 100644 --- a/core/src/main/java/io/kestra/core/models/property/Property.java +++ b/core/src/main/java/io/kestra/core/models/property/Property.java @@ -99,13 +99,7 @@ public static Property of(V value) { * @see io.kestra.core.runners.RunContextProperty#as(Class) */ public static T as(Property property, RunContext runContext, Class clazz) throws IllegalVariableEvaluationException { - if (property.value == null) { - String rendered = runContext.render(property.expression); - // special case for duration as they should be serialized as double but are not always - property.value = MAPPER.convertValue(rendered, clazz); - } - - return property.value; + return as(property, runContext, clazz, Map.of()); } /** @@ -132,17 +126,7 @@ public static T as(Property property, RunContext runContext, Class cla * @see io.kestra.core.runners.RunContextProperty#asList(Class) */ public static T asList(Property property, RunContext runContext, Class itemClazz) throws IllegalVariableEvaluationException { - if (property.value == null) { - String rendered = runContext.render(property.expression); - JavaType type = MAPPER.getTypeFactory().constructCollectionLikeType(List.class, itemClazz); - try { - property.value = MAPPER.readValue(rendered, type); - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return property.value; + return asList(property, runContext, itemClazz, Map.of()); } /** @@ -174,27 +158,7 @@ public static T asList(Property property, RunContext runContext, Class * @see io.kestra.core.runners.RunContextProperty#asMap(Class, Class) */ public static T asMap(Property property, RunContext runContext, Class keyClass, Class valueClass) throws IllegalVariableEvaluationException { - if (property.value == null) { - JavaType targetMapType = MAPPER.getTypeFactory().constructMapType(Map.class, keyClass, valueClass); - - try { - String trimmedExpression = property.expression.trim(); - // We need to detect if the expression is already a map or if it's a pebble expression (for eg. referencing a variable containing a map). - // Doing that allows us to, if it's an expression, first render then read it as a map. - if (trimmedExpression.startsWith("{{") && trimmedExpression.endsWith("}}")) { - property.value = MAPPER.readValue(runContext.render(property.expression), targetMapType); - } - // Otherwise if it's already a map we read it as a map first then render it from run context which handle map rendering by rendering each entry of the map (otherwise it will fail with nested expressions in values for eg.) - else { - Map asRawMap = MAPPER.readValue(property.expression, Map.class); - property.value = MAPPER.convertValue(runContext.render(asRawMap), targetMapType); - } - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return property.value; + return asMap(property, runContext, keyClass, valueClass, Map.of()); } /** @@ -229,134 +193,6 @@ public static T asMap(Property property, RunContext runContext, Clas return property.value; } - /** - * Render a property then convert it to its target type.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T as(RunContext runContext, Class clazz) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression); - this.value = MAPPER.convertValue(rendered, clazz); - } - - return this.value; - } - - /** - * Render a property with additional variables, then convert it to its target type.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T as(RunContext runContext, Class clazz, Map variables) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression, variables); - this.value = MAPPER.convertValue(rendered, clazz); - } - - return this.value; - } - - /** - * Render a property then convert it as a list of target type.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T asList(RunContext runContext, Class itemClazz) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression); - JavaType type = MAPPER.getTypeFactory().constructCollectionLikeType(List.class, itemClazz); - try { - this.value = MAPPER.readValue(rendered, type); - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return this.value; - } - - /** - * Render a property with additional variables, then convert it as a list of target type.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T asList(RunContext runContext, Class itemClazz, Map variables) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression, variables); - JavaType type = MAPPER.getTypeFactory().constructCollectionLikeType(List.class, itemClazz); - try { - this.value = MAPPER.readValue(rendered, type); - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return this.value; - } - - /** - * Render a property then convert it as a map of target types.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T asMap(RunContext runContext, Class keyClass, Class valueClass) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression); - JavaType type = MAPPER.getTypeFactory().constructMapType(Map.class, keyClass, valueClass); - try { - this.value = MAPPER.readValue(rendered, type); - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return this.value; - } - - /** - * Render a property with additional variables, then convert it as a map of target types.
- * - * This method is safe to be used as many times as you want as the rendering and conversion will be cached. - * Warning, due to the caching mechanism, this method is not thread-safe. - * - * @deprecated use RunContext.render(Property) instead. - */ - @Deprecated(forRemoval = true) - public T asMap(RunContext runContext, Class keyClass, Class valueClass, Map variables) throws IllegalVariableEvaluationException { - if (this.value == null) { - String rendered = runContext.render(expression, variables); - JavaType type = MAPPER.getTypeFactory().constructMapType(Map.class, keyClass, valueClass); - try { - this.value = MAPPER.readValue(rendered, type); - } catch (JsonProcessingException e) { - throw new IllegalVariableEvaluationException(e); - } - } - - return this.value; - } - @Override public String toString() { return value != null ? value.toString() : expression;