Public class JacksonJsonUtil {private static ObjectMapper mapper;/*** get ObjectMapper instance * @ param createNew method: true, new instance; false, existing mapper instance * @ return */public static synchronized ObjectMapper getMapperInstance (boolean createNew) {if (createNew) {return new ObjectMapper ();} else if (mapper = null) {mapper = new ObjectMapper ();} return mapper;}/*** converts a java object to a json string * @ param obj the object to be converted * @ retu Rn json String * @ throws Exception */public static String beanToJson (Object obj) throws Exception {try {ObjectMapper objectMapper = getMapperInstance (false); String json = objectMapper. writeValueAsString (obj); return json;} catch (Exception e) {throw new Exception (e. getMessage () ;}}/*** converts a java object to a json string * @ param obj: the object to be converted * @ param createNew ObjectMapper: true, new instance; false: The mapper instance * @ return json character. String * @ throws Exception */public static String beanToJson (Object obj, Boolean createNew) throws Exception {try {ObjectMapper objectMapper = getMapperInstance (createNew); String json = objectMapper. writeValueAsString (obj); return json;} catch (Exception e) {throw new Exception (e. getMessage ());}} /*** convert a json string to a java object * @ param json the json string to be converted * @ param cls the class to be converted * @ return * @ throws Exception */public s Tatic Object jsonToBean (String json, Class <?> Cls) throws Exception {try {ObjectMapper objectMapper = getMapperInstance (false); Object vo = objectMapper. readValue (json, cls); return vo;} catch (Exception e) {throw new Exception (e. getMessage ());}} /*** convert a json string to a java object * @ param json the json string to be converted * @ param cls the class to be converted * @ param createNew ObjectMapper instance method: true, new instance; false: mapper instance * @ return * @ throws Exception */public static Object jsonToBean (Stri Ng json, Class <?> Cls, Boolean createNew) throws Exception {try {ObjectMapper objectMapper = getMapperInstance (createNew); Object vo = objectMapper. readValue (json, cls); return vo;} catch (Exception e) {throw new Exception (e. getMessage ());}}}