From cd3cac266bd33f09a328e4ebfd0dfd5b2c3e408e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 02 Dec 2014 18:35:03 +0000
Subject: [PATCH] #396 fix - Added new method to JsonUtils

---
 src/main/java/net/curisit/securis/utils/JsonUtils.java |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/src/main/java/net/curisit/securis/utils/JsonUtils.java b/src/main/java/net/curisit/securis/utils/JsonUtils.java
index 5226c98..c71301d 100644
--- a/src/main/java/net/curisit/securis/utils/JsonUtils.java
+++ b/src/main/java/net/curisit/securis/utils/JsonUtils.java
@@ -83,8 +83,9 @@
     public static String toJSON(Object obj) throws SeCurisException {
         // and could also do other configuration...
         try {
-            if (obj == null)
+            if (obj == null) {
                 return null;
+            }
             return MAPPER.writeValueAsString(obj);
         } catch (IOException e) {
             LOG.error("Error formating JSON from object: {}", obj, e);
@@ -100,6 +101,27 @@
      * @param obj
      * @return JSON string representation from object
      */
+    public static String toJSON(Object obj, Class<?> klass) throws SeCurisException {
+        // and could also do other configuration...
+        try {
+            if (obj == null) {
+                return null;
+            }
+            return MAPPER.writerWithType(klass).writeValueAsString(obj);
+        } catch (IOException e) {
+            LOG.error("Error formating JSON from object: {}", obj, e);
+            throw new SeCurisException("Error formating JSON from object: " + obj, e);
+        }
+    }
+
+    /**
+     * Create a JSON string from a object compatible or annotated with Jackson,
+     * i.e: <code>
+     * {"f1":2345,"f2":"Test de valor"}
+     * 
+     * @param obj
+     * @return JSON string representation from object
+     */
     public static String toPrettyJSON(Object obj) throws SeCurisException {
         // and could also do other configuration...
         try {

--
Gitblit v1.3.2