Remember Fastjson generic to object the first time can turn normally, the second time becomes jsonarray problem

Source: Internet
Author: User

When parsing JSON data, when using generic objects:

 Public class Implements Serializable {    privatestaticfinallong serialversionuid = 123L  ;     Private int ResultCode;     Private E resultobject;     Private String resultmsg;  Get set}

First time in use

  New Typereference<resultmsgdto<list<articledto>>>() {});

It is possible to convert the JSON string to the corresponding generic object, because I add a data, after retrieving the JSON character from the server again, when I call the method above again, this time it is not successful, but the Jsonarray type of data

The solution was then found online:

1, https://github.com/alibaba/fastjson/issues/569 there is a problem but it has been solved this time you have to look at your Fastjson jar package version, you can change a higher version of the test

2, if you change the high version or not, it is estimated that you made the same mistake as me

This time you need to look at your code, there is no use of generics and direct use of resultmsgdto, such as the following example of the error :

  New Typereference<resultmsgdto>() {});

This is the time to add the generic type in the statement, even if you don't use the object he's on, but you need to add generics

Remember: the solution: Using generic types uniformly, there is no problem with resultmsgdto that do not have generic types in the project.

Reference: http://blog.csdn.net/ykdsg/article/details/50432494 thank the classmate for his selfless dedication.

Remember Fastjson generic to object the first time can turn normally, the second time becomes jsonarray problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.