diff options
author | priyanka.akhade <priyanka.akhade@huawei.com> | 2020-03-13 10:52:03 +0000 |
---|---|---|
committer | priyanka.akhade <priyanka.akhade@huawei.com> | 2020-03-13 10:52:03 +0000 |
commit | 471d10938b8886d695bd9c50b88ad210a61b5a8c (patch) | |
tree | ee44ea20e32928f26fa4e1a071f3e36254f82f22 | |
parent | 222fe26ea3926a08f3797ebc50cb958fe756683f (diff) |
Migrate to gson
Issue-ID: VNFSDK-553
Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com>
Change-Id: Ideb0e20ebe09945f221cc31560922aae9e375dde
4 files changed, 23 insertions, 12 deletions
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml index c197beb..ca979bd 100644 --- a/csarvalidation/pom.xml +++ b/csarvalidation/pom.xml @@ -84,13 +84,13 @@ <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-framework</artifactId> - <version>3.0.0</version> + <version>5.0.2</version> </dependency> <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-main</artifactId> - <version>3.0.0</version> + <version>5.0.2</version> <scope>test</scope> </dependency> diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java index 2055cf2..1c05948 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -15,8 +15,7 @@ */ package org.onap.cvc.csar; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; import org.onap.cvc.csar.parser.SourcesParser; @@ -43,6 +42,7 @@ import java.util.Optional; */ public class CSARArchive implements AutoCloseable { + private static Gson gson = new Gson(); public static final String SOL0004_2_4_1 = "V2.4.1 (2018-02)"; public static final String TEMP_DIR = "/tmp"; @@ -156,8 +156,8 @@ public class CSARArchive implements AutoCloseable { public String toString() { try { - return new ObjectMapper().writeValueAsString(this); - } catch (JsonProcessingException e) { + return gson.toJson(this); + } catch (Exception e) { //NOSONAR //never occurs return "{}"; } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java index 20700ac..043d4dc 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java @@ -21,7 +21,6 @@ import java.util.Date; import java.util.List; import java.util.Properties; -import com.fasterxml.jackson.core.JsonProcessingException; import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; @@ -34,13 +33,14 @@ import org.onap.cvc.csar.CSARArchive.CSARError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; /** * Validates CSAR */ @OnapCommandSchema(schema = "vtp-validate-csar.yaml") public class VTPValidateCSAR extends OnapCommand { + private static Gson gson = new Gson(); private static final Logger LOG = LoggerFactory.getLogger(VTPValidateCSAR.class); public static final String PNF_ATTRIBUTE_NAME = "pnf"; @@ -268,15 +268,15 @@ public class VTPValidateCSAR extends OnapCommand { return validation; } - private void setOperationResult(CSARValidation validation) throws JsonProcessingException { + private void setOperationResult(CSARValidation validation) throws Exception { //NOSONAR this.getResult().getRecordsMap().get("vnf").getValues().add( - new ObjectMapper().writeValueAsString(validation.getVnf())); + gson.toJson(validation.getVnf())); this.getResult().getRecordsMap().get("date").getValues().add(validation.getDate()); this.getResult().getRecordsMap().get("criteria").getValues().add(validation.getCriteria()); this.getResult().getRecordsMap().get("results").getValues().add( - new ObjectMapper().writeValueAsString(validation.getResults())); + gson.toJson(validation.getResults())); - this.getResult().setOutput(new ObjectMapper().writeValueAsString(validation)); + this.getResult().setOutput(gson.toJson(validation)); this.getResult().setType(OnapCommandResultType.TEXT); } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java index bd9b191..2831532 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java @@ -21,6 +21,7 @@ import java.util.Arrays; import org.junit.Test; +import static org.junit.Assert.assertEquals; public class CSARArchiveTest { @Test @@ -42,4 +43,14 @@ public class CSARArchiveTest { } } + @Test + public void testErrorToStringForGson(){ + + String expected = "{\"code\":\"0x1001\",\"message\":\"Invalid value. Entry [testEntry]. Valid values are [-1]. InvalidEntry\",\"file\":\"abc\",\"lineNumber\":-1}"; + CSARArchive.CSARErrorInvalidEntryValue testError = + new CSARArchive.CSARErrorInvalidEntryValue("testEntry","abc","InvalidEntry","-1"); + assertEquals(expected,testError.toString()); + + } + } |