IE parseerror with JSON&jQuery

Recently my project has a page which will load amount of data, as this project use jQuery heavily even use it in wrong way, say return data from DB and then java layer only wraps it to Object, with JBoss Resteasy, this Object is transferred to javascript layer as JSON type.

After this, big challenge comes to Browser, JS would iterate this complex Object to get demanded data, this process involves loop, filtering and sorting, even second level loop for filter duplicated data. The time to this process is as long as IE Browser complaints with

Error message: "A script on this page is causing Internet Explorer to run slowly"

Under this circumstance, we would like to withdraw data handling work from JS to Java, we define below java data structure:

public class TurbineAuxiliary {
	private List<Customer> customers = new ArrayList<TurbineAuxiliary.Customer>(); 
	private List<Site> sites = new ArrayList<TurbineAuxiliary.Site>();
	private List<Country> countries = new ArrayList<TurbineAuxiliary.Country>();
	private List<SiteTurbine> siteTurbines = new ArrayList<TurbineAuxiliary.SiteTurbine>();
	private List<UnitAttr> unitAttrs = new ArrayList<TurbineAuxiliary.UnitAttr>();
	private List<Technology> techs = new ArrayList<TurbineAuxiliary.Technology>();
	private Set<String> regions = new LinkedHashSet<String>();
	private Set<String> outageTypes = new LinkedHashSet<String>();
	private Set<String> contractRaxs = new LinkedHashSet<String>();
	private Set<String> csaTriggers = new LinkedHashSet<String>();

However, after JSON transform, I got below JSON data structure (even some fields are lost), it is very strange:


Anyway, if no data is lost, then corrupted data structure would not block data extracting. This data structure works fine in Chrome, but failed in IE, IE just reports 

status: 200
textstatus:parsererror
errorThrown: Expected '}'

I tried to search Internet in the hope of getting some hint or solution on this, several feasible solutions for others come to me, but no luck with tries. like:

My colleague change another idea, as he doubts JAXB would not recognize (or incompatible with ) Java Set, consequently the generic String cannto be parsed correctly, so he tried to use List instead of Set as well as String wrapping. The updated Java data structure is as following:

@XmlRootElement
public class TurbineAuxiliary {
     private List<Customer> customers = new ArrayList<TurbineAuxiliary.Customer>(); 
     private List<Site> sites = new ArrayList<TurbineAuxiliary.Site>();
     private List<Country> countries = new ArrayList<TurbineAuxiliary.Country>();
     private List<SiteTurbine> siteTurbines = new ArrayList<TurbineAuxiliary.SiteTurbine>();
     private List<UnitAttr> unitAttrs = new ArrayList<TurbineAuxiliary.UnitAttr>();
     private List<Technology> techs = new ArrayList<TurbineAuxiliary.Technology>();
     private List<StringWrapperForJAXB> regions = new ArrayList<StringWrapperForJAXB>();
     private List<StringWrapperForJAXB> outageTypes = new ArrayList<StringWrapperForJAXB>();
     private List<StringWrapperForJAXB> contractRaxs = new ArrayList<StringWrapperForJAXB>();
     private List<StringWrapperForJAXB> csaTriggers = new ArrayList<StringWrapperForJAXB>();
public static class StringWrapperForJAXB implements Comparable<StringWrapperForJAXB>{
	private String core;

	public StringWrapperForJAXB() {
	}

	public StringWrapperForJAXB(String core) {
		super();
		this.core = core;
	}

	@Override
	public int compareTo(StringWrapperForJAXB o) {
		return this.core.compareTo(o.getCore());
	}

	public String getCore() {
		return core;
	}

	public void setCore(String core) {
		this.core = core;
	} 
}

After this change, we are getting correct JSON successfully and no data is lost, see:


From my experience, I found 2 points needs to be remarked:

  • java.util.Set is not compatible with JAXB
  • When use java generic, direclty use List<String> cannot be parsed correctly by JAXB, but need to have a wrapper for String.

Not have a test to verify my comments, need someone to correct me if I am wrong. This note is for future reference.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值