Your SlideShare is downloading. ×
0
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
SoftLeader Jackson Training
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

SoftLeader Jackson Training

150

Published on

Java Object and JSON data mapping by FasterXML Jackson

Java Object and JSON data mapping by FasterXML Jackson

Published in: Software
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
150
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SoftLeader Tech. Corp. 2014.07 Jackson Training
  • 2. Main Projects • jackson-core • jackson-annotations • jackson-databind • Third-party  Guava  Hibernate  HPPC  Joda  org.json  JSR-310 ( Java 8 Date )  JSR-353 ( Java JSON API )  JDK7
  • 3. Maven • groupId : com.fasterxml.jackson.core • artifactId:  jackson-core  jackson-databind  jackson-annotations • version  now is 2.4.0
  • 4. What is JSON format { "id": 1, "account": "admin", "name": "Administrator" } if in XML , too complex and bigger size. <root> <user id= "1"> <account>admin</account> <name>Administrator</name> </user> </root>
  • 5. JSON is simpler • Property {"attribute1 ": "string ", "attribute2 ": number} • List {"attribute3 ": ["Apple", "Banana", "Cherry"]} • Map/Object {"attribute4":{"field1":"value1", "field2":"value2"}}
  • 6. JSON Parser • Streaming • Tree Traversing • Data Binding
  • 7. Data Binding ObjectMapper objectMapper = new ObjectMapper(); mapper.readValue( src, MyBean.class); MyBean myBean = new MyBean(); mapper.writeValue(dst, myBean); • File • InputStream / OutputStream • Reader / Writer • String
  • 8. Java Mapping JSON Type Java Type object LinkedHashMap<String, Object> array ArrayList<Object> string String number ( no fraction) Integer, Long, BigInteger number ( fraction ) Double (  BigDecimal ) true/false Boolean null null
  • 9. Basic Annotations • @JsonProperty 對應到 json 的屬性值 • @JsonIgnore 忽略輸入與輸出 // property level • @JsonIgnoreProperties({.., ..}) // class level • @JsonIgnoreProperties(ignoreUnknown=true)
  • 10. parent-child • @JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="softleader@class") { "pets":[ { "name":"Mars", "softleader@class":"tw.com.softleader.json.jackson.entity.Question07Dog", "age":7 }, { "name":"Tiger", "softleader@class":"tw.com.softleader.json.jackson.entity.Question07Cat", "color":"yellow“ } ] }
  • 11. Joda-time • jackson-datatype-joda ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule());
  • 12. Q & A

×