Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fastjson转换对象时失败,对象中有两个map集合 #1189

Closed
taoduo1 opened this issue May 9, 2017 · 3 comments
Closed

fastjson转换对象时失败,对象中有两个map集合 #1189

taoduo1 opened this issue May 9, 2017 · 3 comments
Milestone

Comments

@taoduo1
Copy link

taoduo1 commented May 9, 2017

//这是javabean
package com.potevio.sp.util.root;

import java.util.List;
import java.util.Map;

public class JsonBean {
	private Map<String, String> body;
    private int headertemplateno;
    private Map<String, String> headerdestination;
    private String headernotificationtype;
    private String notificationType;
    
    
    
	public Map<String, String> getBody() {
		return body;
	}
	public void setBody(Map<String, String> body) {
		this.body = body;
	}
	public int getHeadertemplateno() {
		return headertemplateno;
	}
	public void setHeadertemplateno(int headertemplateno) {
		this.headertemplateno = headertemplateno;
	}
	public Map<String, String> getHeaderdestination() {
		return headerdestination;
	}
	public void setHeaderdestination(Map<String, String> headerdestination) {
		this.headerdestination = headerdestination;
	}
	public String getHeadernotificationtype() {
		return headernotificationtype;
	}
	public void setHeadernotificationtype(String headernotificationtype) {
		this.headernotificationtype = headernotificationtype;
	}
	public String getNotificationType() {
		return notificationType;
	}
	public void setNotificationType(String notificationType) {
		this.notificationType = notificationType;
	}
	public JsonBean(Map<String, String> body, int headertemplateno,
			Map<String, String> headerdestination,
			String headernotificationtype, String notificationType) {
		super();
		this.body = body;
		this.headertemplateno = headertemplateno;
		this.headerdestination = headerdestination;
		this.headernotificationtype = headernotificationtype;
		this.notificationType = notificationType;
	}
	public JsonBean() {
		super();
		// TODO Auto-generated constructor stub
	}
    
}

//这是转换的测试
public static void main(String[] args) {
		String str = new String("{\"headernotificationType\": \"PUSH\",\"headertemplateNo\": \"99\",\"headerdestination\": [{\"target\": \"all\",\"targetvalue\": \"all\"}],\"body\": [{\"title\": \"预约超时\",\"body\": \"您的预约已经超时\"}]}");
		System.out.println(str);
		//JsonsRootBean bean = JSON.parseObject(str, JsonsRootBean.class);
		//System.out.println(bean.getHeadernotificationtype());
		JsonBean objeclt = JSON.parseObject(str, JsonBean.class);
		Map<String, String> list =objeclt.getBody();
		System.out.println(list.get("body"));
	}
@wenshao
Copy link
Member

wenshao commented May 9, 2017

headerdestination是一个Map,但是返回的是一个数组。

@wenshao wenshao added this to the 1.2.32 milestone May 9, 2017
@wenshao
Copy link
Member

wenshao commented May 10, 2017

@wenshao wenshao closed this as completed May 10, 2017
@vipcxj
Copy link

vipcxj commented Jul 14, 2017

这个map变成数组是故意写成这样的,还是序列化后自然就变成这样了?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants