jackson objectMapper.readValue 读取并存成想要的类型

两种方式:

java反射里面有个很有趣的东东,反射解析成list很难,故new TypeReference

 

package com.alibaba.fastjson;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

public class TypeReference {

    private final Type type;

    protected TypeReference(){
        Type superClass = getClass().getGenericSuperclass();

        type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
    }

    public Type getType() {
        return type;
    }
    
    public final static Type LIST_STRING = new TypeReference>() {}.getType();
}
 
List members = this.objectMapper.readValue(json, new TypeReference>(){});
 List> rawContatcs = mapper.readValue(appJson, List.class);

你可能感兴趣的:(javaweb,json,spring,mvc,springmvc)