summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main/java/org')
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java b/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java
index 338a841a7a..60a6e16fe7 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java
@@ -90,6 +90,22 @@ public class JsonObjectMapper {
}
/**
+ * Serializing generic json object to bytes using Jackson.
+ *
+ * @param jsonObject any json object value
+ * @return the generated JSON as a byte array.
+ */
+ public byte[] asJsonBytes(final Object jsonObject) {
+ try {
+ return objectMapper.writeValueAsBytes(jsonObject);
+ } catch (final JsonProcessingException jsonProcessingException) {
+ log.error("Parsing error occurred while converting JSON object to bytes.");
+ throw new DataValidationException("Parsing error occurred while converting given JSON object to bytes.",
+ jsonProcessingException.getMessage());
+ }
+ }
+
+ /**
* Deserialize JSON content from given JSON content String to JsonNode.
*
* @param jsonContent JSON content