| .. | .. |
|---|
| 135 | 135 | } |
|---|
| 136 | 136 | |
|---|
| 137 | 137 | /** |
|---|
| 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 | + /** |
|---|
| 138 | 158 | * Create a Map from a json string, i.e: <code> |
|---|
| 139 | 159 | * {"f1":2345,"f2":"Test de valor"} |
|---|
| 140 | 160 | * </code> |
|---|