使用jackson的ObjectMapper json转object

来源:互联网 发布:个性域名格式不正确 编辑:程序博客网 时间:2024/05/21 14:06


json 转 List<User>

CollectionType collectionType = MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, GroupUser.class);//the sieze of the list is dependon the str json length although the json content is not the POJO type maybeArrayList<GroupUser> groupUsers = MAPPER.readValue(res, collectionType);

json 转 数组


ArrayType arrayType = MAPPER.getTypeFactory().constructArrayType(User.class);User[] users = MAPPER.readValue(expected, arrayType);


json 转 boject

User user = MAPPER.readValue(expected, User.class);


Object 转json

     String test = MAPPER.writeValueAsString(users);

阅读全文
0 0
原创粉丝点击