com.fasterxml.jackson 可以忽略大小写,类内部可以使用List

    com.fasterxml.jackson.core
    jackson-databind
    2.9.8

    public static T xsonToBean(String jsonString,Class beanClass) throws JsonProcessingException {
    //Json字符串转为java对象
    ObjectMapper ob =new ObjectMapper();
    //忽略未定义字段
    ob.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    //json转bean时忽略大小写
    ob.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    T bean = ob.readValue(jsonString, beanClass);
    return bean;
    }
    public static List xsonToList(String jsonString,Class beanClass) throws JsonProcessingException {
    //Json字符串转为java对象
    ObjectMapper ob =new ObjectMapper();
    //忽略未定义字段
    ob.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    //json转bean时忽略大小写
    ob.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    List list = ob.readValue(jsonString, new TypeReference>() {});
    return list;
    }

    gson,不能直接忽略大小写,可以通过 @SerializedName(“custom_naming”) private final String someField; 或者UpperCamelCase
    内部有List时可以用

    com.google.code.gson
    gson
    2.8.5



    public static T gsonToBean(String jsonString, Class beanClass) {
    Gson gson = new Gson();
    T bean = gson.fromJson(jsonString, beanClass);
    return bean;
    }

    public static List gsonToBeanList(String jsonString, Class clazz) {
    Gson gson = new Gson();
    Type type = new ParameterizedTypeImpl(clazz);
    List list = gson.fromJson(jsonString, type);
    return list;
    }
    public class ParameterizedTypeImpl implements ParameterizedType {
    Class clazz;

    public ParameterizedTypeImpl(Class clz) {
    clazz = clz;
    }


    public Type[] getActualTypeArguments() {
    return new Type[]{clazz};
    }


    public Type getRawType() {
    return List.class;
    }


    public Type getOwnerType() {
    return null;
    }
    }


    net.sf.json 不能忽略大小写,而且类内部有List时,序列化有问题,需要借助单独定义Map参数解决

    net.sf.json-lib
    json-lib
    2.4
    jdk15

    public static List jsonToBeanList(String jsonString, Class beanClass) {
    JSONArray jsonArray = JSONArray.fromObject(jsonString);
    JSONObject jsonObject;
    T bean;
    int size = jsonArray.size();
    List list = new ArrayList(size);

    for (int i = 0; i < size; i++) {
    jsonObject = jsonArray.getJSONObject(i);
    bean = (T) JSONObject.toBean(jsonObject, beanClass);
    list.add(bean);
    }
    return list;
    }
    /*
    从一个JSON 对象字符格式中得到一个java对象

    @param jsonString
    @param beanCalss
    @return
    */

    @SuppressWarnings(“unchecked”)
    public static T jsonToBean(String jsonString, Class beanCalss) {

    JSONObject jsonObject = JSONObject.fromObject(jsonString);
    T bean = (T) JSONObject.toBean(jsonObject, beanCalss);

    return bean;
    }