summaryrefslogtreecommitdiffstats
path: root/common-be/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'common-be/src/main/java')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java5
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java22
2 files changed, 22 insertions, 5 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
index 84543e29f7..e9d584486d 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
@@ -36,7 +36,10 @@ public class CustomYamlFunction implements ToscaFunction, ToscaFunctionParameter
@Override
public String getValue() {
- return new Yaml().dump(yamlValue);
+ if (yamlValue == null) {
+ return null;
+ }
+ return yamlValue instanceof String ? (String) yamlValue : new Yaml().dump(yamlValue);
}
@Override
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
index 74aed12471..fda832b98e 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
@@ -32,10 +32,14 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToscaFunctionJsonDeserializer.class);
+
public ToscaFunctionJsonDeserializer() {
this(null);
}
@@ -74,16 +78,26 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
}
if (toscaFunctionType == ToscaFunctionType.YAML) {
- return this.deserializeYamlFunction(node);
+ return this.deserializeYamlFunction(node, context);
}
return null;
}
- private ToscaFunction deserializeYamlFunction(JsonNode node) {
+ private ToscaFunction deserializeYamlFunction(final JsonNode node, final DeserializationContext context) throws JsonMappingException {
var yamlFunction = new CustomYamlFunction();
- final Object value = new Yaml().load(node.get("value").asText());
- yamlFunction.setYamlValue(value);
+ final JsonNode valueJsonNode = node.get("value");
+ if (valueJsonNode == null) {
+ return yamlFunction;
+ }
+ final String valueAsText = valueJsonNode.asText();
+ try {
+ yamlFunction.setYamlValue(new Yaml().load(valueAsText));
+ } catch (final Exception e) {
+ final String errorMsg = String.format("Could not parse YAML expression: '%s'", valueAsText);
+ LOGGER.debug(errorMsg, e);
+ throw context.instantiationException(ToscaFunction.class, errorMsg);
+ }
return yamlFunction;
}