import com.fasterxml.jackson.databind.ObjectMapper;import java.io.IOException;import java.util.List;import java.util.Map;public class JsonUtils { private static ObjectMapper objectMapper = new ObjectMapper(); public static String object2Json(Object obj){ if (obj == null) { return ""; } String result = null; try { result = objectMapper.writeValueAsString(obj); } catch (IOException e) { e.printStackTrace(); } return result; } public static Map jsonToMap(String json){ return json2Object(json, Map.class); } public static T json2Object(String json, Class cls){ T result = null; try { result = objectMapper.readValue(json, cls); } catch (IOException e) { e.printStackTrace(); } return result; } public static T conveterObject(Object srcObject, Class destObjectType) { String jsonContent = object2Json(srcObject); return json2Object(jsonContent, destObjectType); } public static List fromJsonList(String json, Class clazz) throws IOException { return objectMapper.readValue(json,objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); }}
com.fasterxml.jackson.core jackson-databind 2.4.2