diff options
6 files changed, 17 insertions, 24 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java index c4be02e3..8d707906 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java @@ -31,8 +31,7 @@ import org.apache.commons.csv.CSVPrinter; import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed; import org.onap.cli.fw.output.OnapCommandPrintDirection; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; import net.minidev.json.JSONArray; import net.minidev.json.JSONObject; @@ -43,7 +42,6 @@ import net.minidev.json.JSONValue; */ public class OnapCommandPrint { - private static Gson gson = new GsonBuilder().serializeNulls().create(); public static final int MAX_COLUMN_LENGTH = 50; @@ -273,7 +271,7 @@ public class OnapCommandPrint { array.add(rowO); } try { - return gson.toJson(array.toJSONString()).toString(); + return new JsonParser().parse(array.toJSONString()).toString(); } catch (Exception e) { // NOSONAR // TODO Auto-generated catch block return array.toJSONString(); diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java index 97fc9e01..d5d04888 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java @@ -32,7 +32,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class OnapCommandResultTest { - private static Gson gson = new GsonBuilder().serializeNulls().create(); @Test @Ignore @@ -230,10 +229,9 @@ public class OnapCommandResultTest { res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); res.setType(OnapCommandResultType.JSON); - String result = res.print(); String expRes="[{\"param\":{\"id\":\"0001\",\"value\":\"result\"}}]"; - assertEquals(gson.toJson(expRes),result); + assertEquals(expRes,result); } } diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java index 8b9448b7..93b5beee 100644 --- a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java +++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java @@ -45,8 +45,7 @@ import org.open.infc.grpc.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; import io.grpc.Server; import io.grpc.ServerBuilder; @@ -55,7 +54,6 @@ import io.grpc.stub.StreamObserver; public class OpenInterfaceGrpcServer { private static final Logger logger = LoggerFactory.getLogger(OpenInterfaceGrpcServer.class.getName()); - private static Gson gson = new GsonBuilder().serializeNulls().create(); private static final String CONF_FILE = "oclip-grpc-server.properties"; private static final String CONF_SERVER_PORT = "oclip.grpc_server_port"; @@ -248,7 +246,7 @@ public class OpenInterfaceGrpcServer { reply.setSuccess(cmd.getResult().isPassed()); try { - reply.putAttrs(OnapCommandConstants.RESULTS, gson.fromJson(printOut,String.class)); + reply.putAttrs(OnapCommandConstants.RESULTS, new JsonParser().parse(printOut).toString()); } catch (Exception e) { // NOSONAR reply.putAttrs(OnapCommandConstants.RESULTS, printOut); } diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java index 0eb06c96..a592ac79 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java @@ -43,6 +43,8 @@ import org.slf4j.LoggerFactory; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; @@ -300,9 +302,10 @@ public class OnapCommandHttpUtils { } public static String normalizeJson(String json) throws OnapCommandHttpInvalidRequestBody { + JsonParser jsonParser = new JsonParser(); JsonElement node; try { - node = gson.fromJson(json,JsonElement.class); + node = jsonParser.parse(json); normalizeJson(node); return gson.toJson(node); } catch (Exception e) { //NOSONAR diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java index 2ad9b85c..3bba8c21 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java @@ -20,8 +20,7 @@ import java.io.IOException; import java.net.URL; import java.util.Map; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; import com.google.gson.JsonElement; public class MockRequest { @@ -29,8 +28,6 @@ public class MockRequest { private String uri; private Map<String, String> headers; private JsonElement json; - private static Gson gson = new GsonBuilder().serializeNulls().create(); - public String getMethod() { return method; } @@ -64,9 +61,10 @@ public class MockRequest { public void setJson(String json) throws IOException { if (!json.isEmpty()) { try { - this.json = gson.fromJson(json,JsonElement.class); + JsonParser parser = new JsonParser(); + this.json = parser.parse(json); } catch (Exception e) { - this.json = gson.fromJson("{}",JsonElement.class); + this.json = new JsonParser().parse("{}"); } } diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java index 9184d3ad..30f64f20 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java @@ -18,15 +18,12 @@ package org.onap.cli.http.mock; import java.io.IOException; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; +import com.google.gson.JsonParser; public class MockResponse { private int status; private JsonElement json; - private static Gson gson = new GsonBuilder().serializeNulls().create(); - public int getStatus() { return status; } @@ -42,9 +39,10 @@ public class MockResponse { public void setJson(String json) throws IOException { if (json != null && !json.isEmpty()) { try { - this.json = gson.fromJson(json,JsonElement.class); + JsonParser parser = new JsonParser(); + this.json = parser.parse(json); } catch (Exception e) { - this.json = gson.fromJson("{}", JsonElement.class); + this.json = new JsonParser().parse("{}"); } } } |