aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main')
-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 338a841a7..60a6e16fe 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