| .. | .. |
|---|
| 45 | 45 | * @param type |
|---|
| 46 | 46 | * @return |
|---|
| 47 | 47 | */ |
|---|
| 48 | + @SuppressWarnings("unchecked") |
|---|
| 48 | 49 | public static <T> T value(Object value, Class<T> type) { |
|---|
| 49 | 50 | |
|---|
| 50 | 51 | return (T) value; |
|---|
| .. | .. |
|---|
| 52 | 53 | |
|---|
| 53 | 54 | public static <T> T parseJSON(String json, Class<T> type) throws SeCurisException { |
|---|
| 54 | 55 | try { |
|---|
| 55 | | - if (json == null) |
|---|
| 56 | + if (json == null){ |
|---|
| 56 | 57 | return null; |
|---|
| 58 | + } |
|---|
| 57 | 59 | return MAPPER.readValue(json, type); |
|---|
| 58 | 60 | } catch (JsonParseException e) { |
|---|
| 59 | 61 | log.error("Error parsing JSON string to obejct: {}", json, e); |
|---|
| .. | .. |
|---|
| 78 | 80 | public static String toJSON(Object obj) throws SeCurisException { |
|---|
| 79 | 81 | // and could also do other configuration... |
|---|
| 80 | 82 | try { |
|---|
| 81 | | - if (obj == null) |
|---|
| 83 | + if (obj == null) { |
|---|
| 82 | 84 | return null; |
|---|
| 85 | + } |
|---|
| 83 | 86 | return MAPPER.writeValueAsString(obj); |
|---|
| 84 | 87 | } catch (JsonProcessingException e) { |
|---|
| 85 | 88 | log.error("Error formating JSON from object: {}", obj, e); |
|---|
| .. | .. |
|---|
| 100 | 103 | public static String toJSON(Object obj, boolean pretty) throws SeCurisException { |
|---|
| 101 | 104 | // and could also do other configuration... |
|---|
| 102 | 105 | try { |
|---|
| 103 | | - if (obj == null) |
|---|
| 106 | + if (obj == null) { |
|---|
| 104 | 107 | return null; |
|---|
| 108 | + } |
|---|
| 105 | 109 | MAPPER.enable(SerializationConfig.Feature.INDENT_OUTPUT); |
|---|
| 106 | 110 | String json = MAPPER.writeValueAsString(obj); |
|---|
| 107 | 111 | MAPPER.disable(SerializationConfig.Feature.INDENT_OUTPUT); |
|---|
| .. | .. |
|---|
| 124 | 128 | * String with json format |
|---|
| 125 | 129 | * @return |
|---|
| 126 | 130 | */ |
|---|
| 131 | + @SuppressWarnings("unchecked") |
|---|
| 127 | 132 | public static Map<String, Object> json2map(String json) throws JsonParseException { |
|---|
| 128 | 133 | |
|---|
| 129 | 134 | try { |
|---|
| 130 | | - if (json == null) |
|---|
| 135 | + if (json == null) { |
|---|
| 131 | 136 | return null; |
|---|
| 137 | + } |
|---|
| 132 | 138 | return MAPPER.readValue(json, Map.class); |
|---|
| 133 | 139 | } catch (JsonParseException e) { |
|---|
| 134 | 140 | log.error("Error parsing JSON string to map: {}", json, e); |
|---|
| .. | .. |
|---|
| 149 | 155 | public static String map2json(Map<String, Object> map) { |
|---|
| 150 | 156 | // and could also do other configuration... |
|---|
| 151 | 157 | try { |
|---|
| 152 | | - if (map == null) |
|---|
| 158 | + if (map == null) { |
|---|
| 153 | 159 | return null; |
|---|
| 160 | + } |
|---|
| 154 | 161 | return MAPPER.writeValueAsString(map); |
|---|
| 155 | 162 | } catch (JsonProcessingException e) { |
|---|
| 156 | 163 | log.error("Error formating JSON from map: {}", map, e); |
|---|
| .. | .. |
|---|
| 170 | 177 | * String with json format |
|---|
| 171 | 178 | * @return |
|---|
| 172 | 179 | */ |
|---|
| 173 | | - public static List<Object> json2list(String json) { |
|---|
| 180 | + @SuppressWarnings("unchecked") |
|---|
| 181 | + public static List<Object> json2list(String json) throws SeCurisException { |
|---|
| 174 | 182 | try { |
|---|
| 175 | 183 | return MAPPER.readValue(json, List.class); |
|---|
| 176 | 184 | } catch (JsonParseException e) { |
|---|
| 177 | 185 | log.error("Error converting JSON string to object {}", json, e); |
|---|
| 186 | + throw new SeCurisException("Error converting JSON to object", e); |
|---|
| 178 | 187 | } catch (IOException e) { |
|---|
| 179 | 188 | log.error("Error converting JSON string to object {}", json, e); |
|---|
| 189 | + throw new SeCurisException("Error converting JSON to object", e); |
|---|
| 180 | 190 | } |
|---|
| 181 | | - return null; |
|---|
| 182 | 191 | } |
|---|
| 183 | 192 | |
|---|
| 184 | 193 | public static <T> T json2object(String json, Class<T> classObject) throws SeCurisException { |
|---|