diff options
Diffstat (limited to 'adapters/mso-adapters-rest-interface/src/main/java/org/onap')
2 files changed, 26 insertions, 2 deletions
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java index 23bbbb3f43..7a2d4ec3e1 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java @@ -24,6 +24,8 @@ package org.onap.so.adapters.vnfrest; import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import com.fasterxml.jackson.databind.ObjectMapper; @@ -71,7 +73,7 @@ public abstract class VfResponseCommon { public String toXmlString() { try { ByteArrayOutputStream bs = new ByteArrayOutputStream(); - JAXBContext context = JAXBContext.newInstance(this.getClass()); + JAXBContext context = JAXBContext.newInstance(this.getClass(), ArrayList.class, HashMap.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML marshaller.marshal(this, bs); diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java index d20d2b7758..0327fd67a3 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java @@ -20,9 +20,16 @@ package org.onap.so.openstack.mappers; +import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; public class MapElements { + private static final Logger logger = LoggerFactory.getLogger(MapElements.class); @XmlElement public String key; @XmlElement @@ -32,6 +39,21 @@ public class MapElements { public MapElements(String key, Object value) { this.key = key; - this.value = value; + // this is required to handle marshalling raw json + // always write values as strings for XML + if (value != null) { + if (value instanceof List || value instanceof Map) { + try { + this.value = new ObjectMapper().writeValueAsString(value); + } catch (JsonProcessingException e) { + logger.warn("could not marshal value to json, calling toString"); + this.value = value.toString(); + } + } else { + this.value = value; + } + } else { + this.value = value; + } } } |