diff options
author | Rob Daugherty <rd472p@att.com> | 2018-09-10 12:44:14 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-10 12:44:14 +0000 |
commit | aae59c1642f773fac85e749d2d7cf68cdda31aaa (patch) | |
tree | a0102c8d4c6d2ec95bad2fe38a6493ab7c5a61b5 | |
parent | e8b5ccd0a6865aea17385056b75b2df8b6566570 (diff) | |
parent | 9ce5f66414eae5084667929f63aa798826a5a15a (diff) |
Merge "added object constructor"
-rw-r--r-- | common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java | 17 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java | 8 |
2 files changed, 23 insertions, 2 deletions
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<Relationships> getRelationships() { final String path = "$.relationship-list"; if (isEmpty()) { diff --git a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java index e40c25a2e2..d4bf1b0224 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java @@ -102,8 +102,12 @@ public class AAIResultWrapperTest { assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class)); assertEquals(true, wrapper.asMap().isEmpty()); assertEquals("{}", wrapper.toString()); - - } + + @Test + public void objectConstructor() { + AAIResultWrapper wrapper = new AAIResultWrapper(new GenericVnf()); + assertEquals("{}", wrapper.getJson()); + } } |