From cb067ee35bfba82cb686cdfce8207fe3060380c8 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 24 Aug 2018 09:02:47 -0400 Subject: aairesultwrapper is now actually serializable added in a proper serialization and deserialization test addressed any comments from pull added in a serialization test for AAIResultWrapper and updated one of the null returns change jsonBody in AAIResultWrapper back to String Change-Id: Iffa5661f129cc26d69dfaa966cd265c67903cf21 Issue-ID: SO-899 Signed-off-by: Benjamin, Max (mb388a) --- .../so/client/aai/entities/AAIResultWrapper.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (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 9087995f97..36e67e2e09 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 @@ -35,19 +35,19 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class AAIResultWrapper implements Serializable { private static final long serialVersionUID = 5895841925807816737L; - private final Optional jsonBody; + private final String jsonBody; private final ObjectMapper mapper; public AAIResultWrapper(String json) { - this.jsonBody = Optional.ofNullable(json); + this.jsonBody = json; this.mapper = new AAICommonObjectMapperProvider().getMapper(); } public Optional getRelationships() { final String path = "$.relationship-list"; - if (!jsonBody.isPresent()) { + if (isEmpty()) { return Optional.empty(); } - Optional result = JsonPathUtil.getInstance().locateResult(jsonBody.get(), path); + Optional result = JsonPathUtil.getInstance().locateResult(jsonBody, path); if (result.isPresent()) { return Optional.of(new Relationships(result.get())); } else { @@ -56,33 +56,37 @@ public class AAIResultWrapper implements Serializable { } public String getJson() { - return jsonBody.orElse("{}"); + if(jsonBody == null) { + return "{}"; + } else { + return jsonBody; + } } public Map asMap() { - if (!this.jsonBody.isPresent()) { + if (isEmpty()) { return new HashMap<>(); } try { - return mapper.readValue(this.jsonBody.get(), new TypeReference>(){}); + return mapper.readValue(this.jsonBody, new TypeReference>(){}); } catch (IOException e) { return new HashMap<>(); } } public Optional asBean(Class clazz) { - if (!this.jsonBody.isPresent()) { + if (isEmpty()) { return Optional.empty(); } try { - return Optional.of(mapper.readValue(this.jsonBody.get(), clazz)); + return Optional.of(mapper.readValue(this.jsonBody, clazz)); } catch (IOException e) { return Optional.empty(); } } public boolean isEmpty() { - return !this.jsonBody.isPresent(); + return jsonBody == null; } @Override public String toString() { -- cgit 1.2.3-korg