Here you can find the source of jsonToObj(String json, Class
convert json string to class Object.License
Apache LicenseParameter
Parameter | Description |
---|---|
T | a parameter |
json | a parameter |
valueType | a parameter |
public static <T> T jsonToObj(String json, Class<T> valueType)
//package com.java2s; //License from project: Apache License import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { private static final ObjectMapper MAPPER = new ObjectMapper(); /**/* w ww.j a v a 2s. c o m*/ * <pre> * convert json string to class Object. * </pre> * * @param <T> * @param json * @param valueType * @return */ public static <T> T jsonToObj(String json, Class<T> valueType) { try { return MAPPER.readValue(json, valueType); } catch (Exception ex) { throw new RuntimeException(ex); } } public static <T> T jsonToObj(String json, TypeReference<T> typeRef) { try { return MAPPER.readValue(json, typeRef); } catch (Exception ex) { throw new RuntimeException(ex); } } }