Serialize Java objects into JSON and XML formatted instances

1. Define a Java object person first:

2. Use Alibaba's fastjson-1.2 13.jar( http://maven.outofmemory.cn/com.alibaba/fastjson/1.2.13/ )The toolkit directly converts Java objects into string type JSON strings through the tojsonstring (object object) method of JSON class. The code is as follows:

4. Use xstream-1.4 9.jar( http://maven.outofmemory.cn/com.thoughtworks.xstream/xstream/1.4.9/ )Toolkit, just create an xStream object, and then use the toxml (object obj) method to realize the conversion from Java object to XML. The code is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>