主要用於測試學習用jackson包實現json、對象、Map之間的轉換。java
一、準備測試用的Java類json
(1)Link類數組
- package test;
-
- public class Link
- {
- private String phone;
- private String address;
- private String qq;
-
- public String getPhone()
- {
- return phone;
- }
- public void setPhone(String phone)
- {
- this.phone = phone;
- }
- public String getAddress()
- {
- return address;
- }
- public void setAddress(String address)
- {
- this.address = address;
- }
- public String getQq()
- {
- return qq;
- }
- public void setQq(String qq)
- {
- this.qq = qq;
- }
- }
(2)User類app
Java代碼 學習
二、測試類,沒用Junit,用Main()方法輸出。測試
三、輸出結果this
- {"id":"01","name":"張三","age":33,"pay":6666.88,"valid":true,"one":"E","birthday":632448000000,"link":{"phone":"13899995555","address":"河南省濟源市","qq":"123456"},"map":{"aa":"this is aa","bb":"this is bb","cc":"this is cc"},"list":["普洱","大紅袍"],"set":["乒乓球","足球","籃球"]}
- pay:java.lang.Double
- valid:java.lang.Boolean
- birthday:java.lang.Long
- link:java.util.LinkedHashMap
- map:java.util.LinkedHashMap
- list:java.util.ArrayList
- set:java.util.ArrayList
- {"id":"01","name":"張三","age":33,"pay":6666.88,"valid":true,"one":"E","birthday":632448000000,"link":{"phone":"13899995555","address":"河南省濟源市","qq":"123456"},"map":{"aa":"this is aa","bb":"this is bb","cc":"this is cc"},"list":["普洱","大紅袍"],"set":["乒乓球","足球","籃球"]}
- pay:6666.88
- valid:true
- birthday:Tue Jan 16 08:00:00 CST 1990
- link:test.Link@350385f1
- map:{aa=this is aa, bb=this is bb, cc=this is cc}
- list:[普洱, 大紅袍]
- set:[足球, 乒乓球, 籃球]
摘抄自:http://rsy.iteye.com/blog/2303323spa