Java Json Create toList(String json, Class clz)

Here you can find the source of toList(String json, Class clz)

Description

to List

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> List<T> toList(String json, Class<T> clz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> List<T> toList(String json, Class<T> clz) {
        return (List<T>) readValue(json, clz);
    }/*from ww w .  ja v a 2 s.c o m*/

    public static <T> T readValue(String jsonStr, Class<T> valueType) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return objectMapper.readValue(jsonStr, valueType);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. toJson(E e)
  2. toJSON(Map map)
  3. toJson(Object object)
  4. toJson(Object object, String dateFormat)
  5. toJsonString(Map map)
  6. toLocalJson(Object value, int depth)