rsanchez
2015-09-22 7d8713e88c7872b195f7e4d02ac4812536ae196b
src/main/java/net/curisit/securis/utils/JsonUtils.java
....@@ -135,6 +135,26 @@
135135 }
136136
137137 /**
138
+ * Create a JSON string from a object compatible or annotated with Jackson,
139
+ * i.e: <code>
140
+ * {"f1":2345,"f2":"Test de valor"}
141
+ *
142
+ * @param obj
143
+ * @return JSON string representation from object
144
+ */
145
+ public static String toPrettyJSON(Object obj, Class<?> klass) throws SeCurisException {
146
+ // and could also do other configuration...
147
+ try {
148
+ if (obj == null)
149
+ return null;
150
+ return MAPPER_PRETTY.writerWithType(klass).writeValueAsString(obj);
151
+ } catch (IOException e) {
152
+ LOG.error("Error formating JSON from object: {}", obj, e);
153
+ throw new SeCurisException("Error formating JSON from object: " + obj, e);
154
+ }
155
+ }
156
+
157
+ /**
138158 * Create a Map from a json string, i.e: <code>
139159 * {"f1":2345,"f2":"Test de valor"}
140160 * </code>