From ca4f38f1305667758c2c2e90b45cd19bdb532721 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Thu, 18 Sep 2014 14:07:32 +0000
Subject: [PATCH] #0 feature - Fixed some SonarQube issues

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

diff --git a/src/main/java/net/curisit/securis/utils/JsonUtils.java b/src/main/java/net/curisit/securis/utils/JsonUtils.java
index 382178f..c134c05 100644
--- a/src/main/java/net/curisit/securis/utils/JsonUtils.java
+++ b/src/main/java/net/curisit/securis/utils/JsonUtils.java
@@ -45,6 +45,7 @@
 	 * @param type
 	 * @return
 	 */
+	@SuppressWarnings("unchecked")
 	public static <T> T value(Object value, Class<T> type) {
 
 		return (T) value;
@@ -52,8 +53,9 @@
 
 	public static <T> T parseJSON(String json, Class<T> type) throws SeCurisException {
 		try {
-			if (json == null)
+			if (json == null){
 				return null;
+			}
 			return MAPPER.readValue(json, type);
 		} catch (JsonParseException e) {
 			log.error("Error parsing JSON string to obejct: {}", json, e);
@@ -78,8 +80,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 (JsonProcessingException e) {
 			log.error("Error formating JSON from object: {}", obj, e);
@@ -100,8 +103,9 @@
 	public static String toJSON(Object obj, boolean pretty) throws SeCurisException {
 		// and could also do other configuration...
 		try {
-			if (obj == null)
+			if (obj == null) {
 				return null;
+			}
 			MAPPER.enable(SerializationConfig.Feature.INDENT_OUTPUT);
 			String json = MAPPER.writeValueAsString(obj);
 			MAPPER.disable(SerializationConfig.Feature.INDENT_OUTPUT);
@@ -124,11 +128,13 @@
 	 *            String with json format
 	 * @return
 	 */
+	@SuppressWarnings("unchecked")
 	public static Map<String, Object> json2map(String json) throws JsonParseException {
 
 		try {
-			if (json == null)
+			if (json == null) {
 				return null;
+			}
 			return MAPPER.readValue(json, Map.class);
 		} catch (JsonParseException e) {
 			log.error("Error parsing JSON string to map: {}", json, e);
@@ -149,8 +155,9 @@
 	public static String map2json(Map<String, Object> map) {
 		// and could also do other configuration...
 		try {
-			if (map == null)
+			if (map == null) {
 				return null;
+			}
 			return MAPPER.writeValueAsString(map);
 		} catch (JsonProcessingException e) {
 			log.error("Error formating JSON from map: {}", map, e);
@@ -170,15 +177,17 @@
 	 *            String with json format
 	 * @return
 	 */
-	public static List<Object> json2list(String json) {
+	@SuppressWarnings("unchecked")
+	public static List<Object> json2list(String json) throws SeCurisException {
 		try {
 			return MAPPER.readValue(json, List.class);
 		} catch (JsonParseException e) {
 			log.error("Error converting JSON string to object {}", json, e);
+			throw new SeCurisException("Error converting JSON to object", e);
 		} catch (IOException e) {
 			log.error("Error converting JSON string to object {}", json, e);
+			throw new SeCurisException("Error converting JSON to object", e);
 		}
-		return null;
 	}
 
 	public static <T> T json2object(String json, Class<T> classObject) throws SeCurisException {

--
Gitblit v1.3.2