(10)json字符转 转JavaBean,且bean中还有List属性 ,重点@JsonProperty("tags") [jackson]

public class VideoTagChangeDto {
	private Long vid;
	private Long uid;
	@JsonProperty("msgid")
	private Long msgId;
	@JsonProperty("createtime")
	private Long createTime;
	
	@JsonProperty("tags")
	private List tags;

	public Long getVid() {
		return vid;
	}

	public void setVid(Long vid) {
		this.vid = vid;
	}

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public List getTagList() {
		return tags;
	}

	public void setTagList(List tagList) {
		this.tags = tagList;
	}

	public Long getMsgId() {
		return msgId;
	}

	public void setMsgId(Long msgId) {
		this.msgId = msgId;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	@Override
	public String toString() {
		return JsonMapper.nonDefaultMapper().toJson(this);
	}
}


public class VideoTagBean {
   
    @JsonProperty("tag_id")
	private Integer tagId;
    @JsonProperty("tag_name")
    private String tagName;

  
    public Integer getTagId() {
		return tagId;
	}
	public void setTagId(Integer tagId) {
		this.tagId = tagId;
	}
	public String getTagName() {
		return tagName;
	}
	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	@Override
    public String toString() {
        return JsonMapper.nonDefaultMapper().toJson(this);
    }
}


public class VideoTagChangeRespDto extends CommonMQResp {
	
	
}

public class Test {

	public static void main(String[] args) {

		String respStr = "{\"msgs\":[{\"vid\":88,\"uid\":1,\"tags\":[{\"tag_id\":1,\"tag_name\":\"1name\"},{\"tag_id\":2,\"tag_name\":\"2name\"}]},{\"vid\":99,\"uid\":11,\"tags\":[{\"tag_id\":11,\"tag_name\":\"11name\"},{\"tag_id\":22,\"tag_name\":\"22name\"}]}]}";
		final VideoTagChangeRespDto resp = JsonMapper.nonEmptyMapper() .fromJson(respStr, VideoTagChangeRespDto.class);
		
		System.out.println(resp.getMsgs());
	}
}

[{"vid":88,"uid":1,"tagList":[{"tag_id":1,"tag_name":"1name"},{"tag_id":2,"tag_name":"2name"}],"tags":[{"tag_id":1,"tag_name":"1name"},{"tag_id":2,"tag_name":"2name"}]}, {"vid":99,"uid":11,"tagList":[{"tag_id":11,"tag_name":"11name"},{"tag_id":22,"tag_name":"22name"}],"tags":[{"tag_id":11,"tag_name":"11name"},{"tag_id":22,"tag_name":"22name"}]}]


import com.fasterxml.jackson.annotation.JsonProperty;





你可能感兴趣的:(Work,Info)