X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Futil%2FMapperUtil.java;h=70534d8231b77d0a85520b7abc729754fa1b6c40;hb=a86d6a6644d6de3f3f814cd6e25cfe2213d5dd05;hp=8280ce0d2052cee628a6e1f8279419652df9a352;hpb=a395fa69a28a04d0a667fe458b4f10497a1d6794;p=aai%2Faai-common.git diff --git a/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java b/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java index 8280ce0d..70534d82 100644 --- a/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java +++ b/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java @@ -27,76 +27,75 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; public class MapperUtil { - /** - * Read as object of. - * - * @param the generic type - * @param clazz the clazz - * @param value the value - * @return the t - * @throws AAIException the AAI exception - */ - public static T readAsObjectOf(Class clazz, String value) throws AAIException { - com.fasterxml.jackson.databind.ObjectMapper MAPPER = new ObjectMapper(); - try { - return MAPPER.readValue(value, clazz); - } catch (Exception e) { - throw new AAIException("AAI_4007", e); + /** + * Read as object of. + * + * @param the generic type + * @param clazz the clazz + * @param value the value + * @return the t + * @throws AAIException the AAI exception + */ + public static T readAsObjectOf(Class clazz, String value) throws AAIException { + ObjectMapper MAPPER = new ObjectMapper(); + try { + return MAPPER.readValue(value, clazz); + } catch (Exception e) { + throw new AAIException("AAI_4007", e); + } } - } - - /** - * Read with dashes as object of. - * - * @param the generic type - * @param clazz the clazz - * @param value the value - * @return the t - * @throws AAIException the AAI exception - */ - public static T readWithDashesAsObjectOf(Class clazz, String value) throws AAIException { - com.fasterxml.jackson.databind.ObjectMapper MAPPER = new ObjectMapper(); - try { - MAPPER.registerModule(new JaxbAnnotationModule()); - MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); - - return MAPPER.readValue(value, clazz); - } catch (Exception e) { - throw new AAIException("AAI_4007", e); - } - } - /** - * Write as JSON string. - * - * @param obj the obj - * @return the string - * @throws AAIException the AAI exception - */ - public static String writeAsJSONString(Object obj) throws AAIException { - com.fasterxml.jackson.databind.ObjectMapper MAPPER = new ObjectMapper(); - try { - String s = MAPPER.writeValueAsString(obj); - return s; - //readValue(value, clazz); - } catch (Exception e) { - throw new AAIException("AAI_4008", e); - } - } - - /** - * Write as JSON string with dashes. - * - * @param obj the obj - * @return the string - * @throws AAIException the AAI exception - */ - public static String writeAsJSONStringWithDashes(Object obj) throws AAIException { - com.fasterxml.jackson.databind.ObjectMapper MAPPER = new ObjectMapper(); - try { - MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); - + /** + * Read with dashes as object of. + * + * @param the generic type + * @param clazz the clazz + * @param value the value + * @return the t + * @throws AAIException the AAI exception + */ + public static T readWithDashesAsObjectOf(Class clazz, String value) throws AAIException { + ObjectMapper MAPPER = new ObjectMapper(); + try { + MAPPER.registerModule(new JaxbAnnotationModule()); + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); + + return MAPPER.readValue(value, clazz); + } catch (Exception e) { + throw new AAIException("AAI_4007", e); + } + } + + /** + * Write as JSON string. + * + * @param obj the obj + * @return the string + * @throws AAIException the AAI exception + */ + public static String writeAsJSONString(Object obj) throws AAIException { + ObjectMapper MAPPER = new ObjectMapper(); + try { + String s = MAPPER.writeValueAsString(obj); + return s; + } catch (Exception e) { + throw new AAIException("AAI_4008", e); + } + } + + /** + * Write as JSON string with dashes. + * + * @param obj the obj + * @return the string + * @throws AAIException the AAI exception + */ + public static String writeAsJSONStringWithDashes(Object obj) throws AAIException { + ObjectMapper MAPPER = new ObjectMapper(); + try { + MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); MAPPER.configure(SerializationFeature.INDENT_OUTPUT, false); MAPPER.configure(SerializationFeature.WRAP_ROOT_VALUE, false); @@ -105,10 +104,10 @@ public class MapperUtil { MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false); MAPPER.registerModule(new JaxbAnnotationModule()); - String s = MAPPER.writeValueAsString(obj); - return s; - } catch (Exception e) { - throw new AAIException("AAI_4008", e); - } - } + String s = MAPPER.writeValueAsString(obj); + return s; + } catch (Exception e) { + throw new AAIException("AAI_4008", e); + } + } }