summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-07-17 13:44:51 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-07-17 13:44:51 +0200
commit328dd54a476dc947413f35ba5e0de8c55602c5b4 (patch)
tree98301379407c16695127e5be07b7c8f9d4097dcb
parent1f54ef67f54face4de2647b90e2552d9a1aca54a (diff)
downloadEAAF-Components-328dd54a476dc947413f35ba5e0de8c55602c5b4.tar.gz
EAAF-Components-328dd54a476dc947413f35ba5e0de8c55602c5b4.tar.bz2
EAAF-Components-328dd54a476dc947413f35ba5e0de8c55602c5b4.zip
update JSON mapper implementation
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java18
-rw-r--r--eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/JsonMapper.java29
2 files changed, 40 insertions, 7 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java
index 10e6464b..6db5a6ae 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java
@@ -1,12 +1,12 @@
package at.gv.egiz.eaaf.core.api.utils;
import java.io.IOException;
+import java.io.InputStream;
import at.gv.egiz.eaaf.core.exceptions.EAAFJsonMapperException;
public interface IJsonMapper {
-
-
+
/**
* Serialize an object to a JSON string.
* @param value the object to serialize
@@ -27,6 +27,16 @@ public interface IJsonMapper {
*/
<T> Object deserialize(String value, Class<T> clazz) throws EAAFJsonMapperException;
- //<T> Object deserialize(String value, TypeReference<T> clazz) throws EAAFJsonMapperException;
-
+ /**
+ * Deserialize a JSON string.
+ *
+ * @param is the JSON to deserialize as {@link InputStream}
+ * @param clazz optional parameter that determines the type of the returned object. If not set, an {@link Object} is returned.
+ * @return the deserialized JSON string as an object of type {@code clazz} or {@link Object}
+ * @throws JsonParseException if the JSON string contains invalid content.
+ * @throws JsonMappingException if the input JSON structure does not match structure expected for result type
+ * @throws IOException if an I/O problem occurs (e.g. unexpected end-of-input)
+ */
+ <T> Object deserialize(InputStream is, Class<T> clazz) throws EAAFJsonMapperException;
+
} \ No newline at end of file
diff --git a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/JsonMapper.java b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/JsonMapper.java
index 043a39bc..b33649e1 100644
--- a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/JsonMapper.java
+++ b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/JsonMapper.java
@@ -1,6 +1,7 @@
package at.gv.egiz.eaaf.modules.auth.sl20.utils;
import java.io.IOException;
+import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public class JsonMapper implements IJsonMapper {
log.debug("JSON object-mapper initialized");
}
-
+
/* (non-Javadoc)
* @at.gv.egiz.eaaf.core.api.utils.IJsonMapper#getMapper()
@@ -86,8 +87,7 @@ public class JsonMapper implements IJsonMapper {
try {
if (clazz != null) {
if (clazz.isAssignableFrom(TypeReference.class))
- return mapper.readValue(value, clazz);
-
+ return mapper.readValue(value, clazz);
else {
final JavaType javaType = TypeFactory.defaultInstance().constructType(clazz);
return mapper.readValue(value, javaType);
@@ -104,5 +104,28 @@ public class JsonMapper implements IJsonMapper {
}
}
+
+ @Override
+ public <T> Object deserialize(InputStream is, Class<T> clazz) throws EAAFJsonMapperException {
+ try {
+ if (clazz != null) {
+ if (clazz.isAssignableFrom(TypeReference.class))
+ return mapper.readValue(is, clazz);
+ else {
+ final JavaType javaType = TypeFactory.defaultInstance().constructType(clazz);
+ return mapper.readValue(is, javaType);
+
+ }
+
+ } else
+ return mapper.readValue(is, Object.class);
+
+ } catch (final IOException e) {
+ log.warn("JSON mapping FAILED with error: {}", e.getMessage());
+ throw new EAAFJsonMapperException(e.getMessage(), e);
+
+ }
+
+ }
}