fastjson convert generic classes(list) 2018-12-29 08:17

fastjson is excellent framework for handle json data. It can parse json string to generic classes. Here is sample code.

public class GenericityClient {
    private static TypeReference userListType = new TypeReference<List<User>>() {
    };

    public static void main(String[] args) {
        String json = "[{\"age\":30,\"name\":\"henry\"},{\"age\":31,\"name\":\"justin\"}]";
        List<User> list = JSON.parseObject(json, userListType.getType());
        System.out.println(list);
    }
}

EOF