公共类jackjson test {
publicstaticvoidmain (stringlysbargs ) throws的淡泊行人0
useruser=newuser('ABC ',' id ',10 );
objectmapperobjectmapper=new对象映射器(;
string JSON=object mapper.writevalueasstring (user );
userjsonuser=object mapper.read value (JSON,User.class );
列表列表=new ArrayList (;
list.add (新用户(ABC 1、id1、101 );
list.add (新用户(ABC2)、id2 )、102 );
list.add (新用户(ABC3)、id3 )、103 );
string list JSON=object mapper.writevalueasstring (列表);
listbeanlist=object mapper.read value (list JSON,new TypeReference () ) )。
);
for (用户资源列表: bean列表)
}
}
}
类用户{
私有字符串名称;
私有字符串id;
私有集成器Age;
@JSONproperty(value='AAA ) ) ) )。
公共字符串getname
返回名称;
}
@JSONproperty(value='AAA ) ) ) )。
公共语音集名称(字符串名称) {
this.name=name;
}
@JsonIgnore
公共字符串getid
返回id;
}
公共语音设置(stringid ) {
this.id=id;
}
公共integer get age
返回age;
}
公共语音设置(integer age ) {
this.age=age;
}
公共用户() }
}
公共用户(字符串名称、字符串id、Integer age ) {
this.name=name;
this.id=id;
this.age=age;
}
@Override
公共字符串字符串
return ' user { ' CK dxl/p ' name=' ' name '' CK dxl/p ',id='' id ''' ckdxl/p ',age=' age ckdxl/p '} '
}
}