diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-01-18 21:57:46 +0530 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-01-25 21:55:25 +0530 |
commit | 05e7b8a207b1c641468e77d754fe1a5ae9e1a51e (patch) | |
tree | b0df8d9b8a08ca001120d6fa544f1e2c5da4f59d /cps-rest/src/main/java | |
parent | db1e983f40be1db7bca5acacf5a3369d74a29c95 (diff) |
Replace gson mapper with jackson mapper
We introduced JsonObjectMapper (wapper) as Spring component.
Issue-ID: CPS-751
Change-Id: I536b0771a3a263325e6907717baf6941d70c0d6c
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-rest/src/main/java')
-rwxr-xr-x | cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java | 31 | ||||
-rw-r--r-- | cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java | 13 |
2 files changed, 23 insertions, 21 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java index a55b1ba7a1..fc2818b6f6 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020-2021 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2021 Nordix Foundation + * Modifications Copyright (C) 2021-2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ package org.onap.cps.rest.controller; -import com.google.gson.Gson; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import javax.validation.ValidationException; @@ -32,6 +31,7 @@ import org.onap.cps.api.CpsDataService; import org.onap.cps.rest.api.CpsDataApi; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.utils.DataMapUtils; +import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -47,17 +47,18 @@ public class DataRestController implements CpsDataApi { private static final DateTimeFormatter ISO_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern(ISO_TIMESTAMP_FORMAT); private final CpsDataService cpsDataService; - private final Gson gson; + private final JsonObjectMapper jsonObjectMapper; @Override public ResponseEntity<String> createNode(final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { + final String jsonDataAsString = jsonObjectMapper.asJsonString(jsonData); if (isRootXpath(parentNodeXpath)) { - cpsDataService.saveData(dataspaceName, anchorName, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + cpsDataService.saveData(dataspaceName, anchorName, jsonDataAsString, + toOffsetDateTime(observedTimestamp)); } else { - cpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + cpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, + jsonDataAsString, toOffsetDateTime(observedTimestamp)); } return new ResponseEntity<>(HttpStatus.CREATED); } @@ -73,8 +74,8 @@ public class DataRestController implements CpsDataApi { @Override public ResponseEntity<String> addListElements(final String parentNodeXpath, final String dataspaceName, final String anchorName, final Object jsonData, final String observedTimestamp) { - cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath, + jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -91,8 +92,8 @@ public class DataRestController implements CpsDataApi { @Override public ResponseEntity<Object> updateNodeLeaves(final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { - cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath, + jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); return new ResponseEntity<>(HttpStatus.OK); } @@ -100,8 +101,8 @@ public class DataRestController implements CpsDataApi { public ResponseEntity<Object> replaceNode(final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { cpsDataService - .replaceNodeTree(dataspaceName, anchorName, parentNodeXpath, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + .replaceNodeTree(dataspaceName, anchorName, parentNodeXpath, + jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); return new ResponseEntity<>(HttpStatus.OK); } @@ -109,8 +110,8 @@ public class DataRestController implements CpsDataApi { public ResponseEntity<Object> replaceListContent(final String parentNodeXpath, final String dataspaceName, final String anchorName, final Object jsonData, final String observedTimestamp) { - cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, gson.toJson(jsonData), - toOffsetDateTime(observedTimestamp)); + cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, + jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java index 8aa65a0057..eb422dc69e 100644 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,18 +20,18 @@ package org.onap.cps.rest.controller; -import com.google.gson.Gson; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import javax.validation.Valid; +import lombok.RequiredArgsConstructor; import org.onap.cps.api.CpsQueryService; import org.onap.cps.rest.api.CpsQueryApi; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; import org.onap.cps.utils.DataMapUtils; -import org.springframework.beans.factory.annotation.Autowired; +import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -39,10 +39,11 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("${rest.api.cps-base-path}") +@RequiredArgsConstructor public class QueryRestController implements CpsQueryApi { - @Autowired - private CpsQueryService cpsQueryService; + private final CpsQueryService cpsQueryService; + private final JsonObjectMapper jsonObjectMapper; @Override public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName, @@ -55,6 +56,6 @@ public class QueryRestController implements CpsQueryApi { for (final DataNode dataNode : dataNodes) { dataNodeList.add(DataMapUtils.toDataMap(dataNode)); } - return new ResponseEntity<>(new Gson().toJson(dataNodeList), HttpStatus.OK); + return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataNodeList), HttpStatus.OK); } } |