Java Json to Object json2List(String json, Class beanClass)

Here you can find the source of json2List(String json, Class beanClass)

Description

json List

License

Apache License

Declaration

public static <T> List<T> json2List(String json, Class<T> beanClass) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;

public class Main {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static <T> List<T> json2List(String json, Class<T> beanClass) {
        try {/*from ww  w.ja v a2s  . c o  m*/

            return (List<T>) objectMapper.readValue(json, getCollectionType(List.class, beanClass));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
        return objectMapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
    }
}

Related

  1. deserialize(String json, Class clazz)
  2. deserialize(String json, Class targetType)
  3. deserialize(String jsonData, Class typeOfT)
  4. deserializeFromDataNode(JsonParser jp, DeserializationContext ctxt, String propertyName, TypeReference typeReference)
  5. deserializeJson(String content, Class valueType)
  6. json2map(String jsonStr)
  7. json2pojo(String jsonStr, Class clazz)
  8. jsonBigDecimal(JsonValue value)
  9. jsonStringToList(String jsonArrStr, Class clazz)