aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java')
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java177
1 files changed, 87 insertions, 90 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java
index c3eefcd3cd..602172f8a4 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/JsonWrapper.java
@@ -25,10 +25,8 @@ package org.onap.so.bpmn.core.domain;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
-
import org.json.JSONException;
import org.json.JSONObject;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
@@ -36,100 +34,99 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Wrapper encapsulates needed JSON functionality
- * to be extended by MSO service decomposition objects
- * providing ways to convert to and from JSON
+ * Wrapper encapsulates needed JSON functionality to be extended by MSO service decomposition objects providing ways to
+ * convert to and from JSON
*
*/
@JsonInclude(Include.NON_NULL)
-public abstract class JsonWrapper implements Serializable {
-
- private static final Logger logger = LoggerFactory.getLogger(JsonWrapper.class);
- @JsonInclude(Include.NON_NULL)
- public String toJsonString(){
-
- String jsonString = "";
- //convert with Jackson
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
-
- mapper.setSerializationInclusion(Include.NON_NULL);
-
- ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
- try {
- jsonString = ow.writeValueAsString(this);
- } catch (Exception e){
-
- logger.debug("Exception :",e);
- }
- return jsonString;
- }
-
- @JsonInclude(Include.NON_NULL)
- public JSONObject toJsonObject(){
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
- JSONObject json = new JSONObject();
- try {
- json = new JSONObject(mapper.writeValueAsString(this));
- } catch (JsonGenerationException e) {
- logger.debug("Exception :",e);
- } catch (JsonMappingException e) {
- logger.debug("Exception :",e);
- } catch (JSONException e) {
- logger.debug("Exception :",e);
- } catch (IOException e) {
- logger.debug("Exception :",e);
- }
- return json;
- }
-
- public String listToJson(List list) {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
-
- String jsonString = "";
- try {
- jsonString = mapper.writeValueAsString(list);
- } catch (JsonGenerationException e) {
- logger.debug("Exception :",e);
- } catch (JsonMappingException e) {
- logger.debug("Exception :",e);
- } catch (IOException e) {
- logger.debug("Exception :",e);
- }
- return jsonString;
- }
-
- @JsonInclude(Include.NON_NULL)
- public String toJsonStringNoRootName(){
-
- String jsonString = "";
- //convert with Jackson
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(Include.NON_NULL);
-
- ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
- try {
- jsonString = ow.writeValueAsString(this);
- } catch (Exception e){
-
- logger.debug("Exception :",e);
- }
- return jsonString;
- }
-
- /**
- * Returns a string representation of this object.
- */
- public String toString() {
- return this.toJsonString();
- }
+public abstract class JsonWrapper implements Serializable {
+
+ private static final Logger logger = LoggerFactory.getLogger(JsonWrapper.class);
+
+ @JsonInclude(Include.NON_NULL)
+ public String toJsonString() {
+
+ String jsonString = "";
+ // convert with Jackson
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+
+ mapper.setSerializationInclusion(Include.NON_NULL);
+
+ ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
+ try {
+ jsonString = ow.writeValueAsString(this);
+ } catch (Exception e) {
+
+ logger.debug("Exception :", e);
+ }
+ return jsonString;
+ }
+
+ @JsonInclude(Include.NON_NULL)
+ public JSONObject toJsonObject() {
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+ JSONObject json = new JSONObject();
+ try {
+ json = new JSONObject(mapper.writeValueAsString(this));
+ } catch (JsonGenerationException e) {
+ logger.debug("Exception :", e);
+ } catch (JsonMappingException e) {
+ logger.debug("Exception :", e);
+ } catch (JSONException e) {
+ logger.debug("Exception :", e);
+ } catch (IOException e) {
+ logger.debug("Exception :", e);
+ }
+ return json;
+ }
+
+ public String listToJson(List list) {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+
+ String jsonString = "";
+ try {
+ jsonString = mapper.writeValueAsString(list);
+ } catch (JsonGenerationException e) {
+ logger.debug("Exception :", e);
+ } catch (JsonMappingException e) {
+ logger.debug("Exception :", e);
+ } catch (IOException e) {
+ logger.debug("Exception :", e);
+ }
+ return jsonString;
+ }
+
+ @JsonInclude(Include.NON_NULL)
+ public String toJsonStringNoRootName() {
+
+ String jsonString = "";
+ // convert with Jackson
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+
+ ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
+ try {
+ jsonString = ow.writeValueAsString(this);
+ } catch (Exception e) {
+
+ logger.debug("Exception :", e);
+ }
+ return jsonString;
+ }
+
+ /**
+ * Returns a string representation of this object.
+ */
+ public String toString() {
+ return this.toJsonString();
+ }
}