Json转换详细解析

1、将Object转换成Json格式

// 将Object转换成Json格式
public void setReadingList(List readingList) {
        this.content = JacksonUtil.toJson(readingList);
    }

setReadingList方法中调用了JacksonUtil.toJson();
toJson():

public static String toJson(Object object) {
        return toJson(object, mapper);
    }

由此可见,readingList就是Object,经过Json转换后由this.content引用
2、解析Json格式,转换成Object

public List getReadingList() {
        return JacksonUtil.parse(this.content, JacksonUtil.buildListJavaType(ReadingBO.class));
    }

parse():

public static  T parse(String json, JavaType valueType) {
        return parse(json, valueType, mapper);
    }

this.content=String json:
JacksonUtil.buildListJavaType(ReadingBO.class)=JavaType valueType

你可能感兴趣的:(java)