aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-09-09 16:51:32 -0400
committerJim Hahn <jrh3@att.com>2019-09-11 15:32:01 -0400
commit173c4dbea9a1175a6f18031a221bb701deeecaa7 (patch)
treecff8d6fc46b6096b551b075e489b406c50b61531 /utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
parent216b2beaf25eba50e948374d07e92b6c0a02b7c9 (diff)
Create StandardYamlCoder
Created StandardYamlCoder which is like a StandardCoder, except that the original converts to/from JSON, while the new class converts to/from YAML. Also added YamlMessageBodyHandler and incorporated it into the http server so that it supports a media type of */yaml. Change-Id: Ibd83a9f6d355a330f63e435f2bb41affcf1947c2 Issue-ID: POLICY-2065 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java')
-rw-r--r--utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
index 80eddb86..d3d69812 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
@@ -211,6 +211,16 @@ public class StandardCoder implements Coder {
}
/**
+ * Encodes an object into a json tree, without catching exceptions.
+ *
+ * @param object object to be encoded
+ * @return a json element representing the object
+ */
+ protected JsonElement toJsonTree(Object object) {
+ return GSON.toJsonTree(object);
+ }
+
+ /**
* Encodes an object into json, without catching exceptions.
*
* @param object object to be encoded
@@ -232,6 +242,17 @@ public class StandardCoder implements Coder {
}
/**
+ * Decodes a json element into an object, without catching exceptions.
+ *
+ * @param json json element to be decoded
+ * @param clazz class of object to be decoded
+ * @return the object represented by the given json element
+ */
+ protected <T> T fromJson(JsonElement json, Class<T> clazz) {
+ return convertFromDouble(clazz, GSON.fromJson(json, clazz));
+ }
+
+ /**
* Decodes a json string into an object, without catching exceptions.
*
* @param json json string to be decoded