From 9ce5f66414eae5084667929f63aa798826a5a15a Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Sat, 8 Sep 2018 22:34:55 -0400 Subject: added object constructor added Object constructor to AAIResultWrapper Change-Id: Ic1bae387a13b7b7864c2687a63532347d8f102e7 Issue-ID: SO-998 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/client/aai/entities/AAIResultWrapper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'common/src/main/java/org') diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java index 36e67e2e09..45621f09a6 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java @@ -26,9 +26,11 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import org.apache.log4j.Logger; import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.jsonpath.JsonPathUtil; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,11 +39,26 @@ public class AAIResultWrapper implements Serializable { private static final long serialVersionUID = 5895841925807816737L; private final String jsonBody; private final ObjectMapper mapper; + private final transient Logger logger = Logger.getLogger(AAIResultWrapper.class); + public AAIResultWrapper(String json) { this.jsonBody = json; this.mapper = new AAICommonObjectMapperProvider().getMapper(); } + public AAIResultWrapper(Object aaiObject) { + this.mapper = new AAICommonObjectMapperProvider().getMapper(); + this.jsonBody = mapObjectToString(aaiObject); + } + + protected String mapObjectToString(Object aaiObject) { + try { + return mapper.writeValueAsString(aaiObject); + } catch (JsonProcessingException e) { + logger.warn("could not parse object into json - defaulting to {}"); + return "{}"; + } + } public Optional getRelationships() { final String path = "$.relationship-list"; if (isEmpty()) { -- cgit 1.2.3-korg