SlideShare a Scribd company logo
1 of 16
JSON vs GSON vs
JACKSON
- Vinaykumar Hebballi
Topics to cover
 Overview of JSON
 The working of GSON
 The working of JACKSON
 Comparison of JSON,GSON and JACKSON.
 Conclusion
2JSON vs GSON vs JACKSON06/21/16
What is JSON
 JSON is a lightweight data interchange format .
 The most important aspects of JSON are
 Simplicity
 Extensibility
 Interoperability
 Openness and Human readability.
3JSON vs GSON vs JACKSON06/21/16
The working of GSON
 GSON is an Java library to serialize and deserialize Java
objects to (and from) JSON.
 It provides two methods :-
 Gson.toJson to serialize java objects.
 Gson.fromJson to deserialize json objects.
4JSON vs GSON vs JACKSON06/21/16
GSON Example
 Serialization:-
 Gson gson = new Gson();
Car audi = new Car("Audi", "A4", 1.8, false);
Car skoda = new Car(“Skoda", "Octavia", 2.0, true);
Car[] cars = {audi, skoda};
Person johnDoe = new Person("John", "Doe", 245987453, 35,
cars);
System.out.println(gson.toJson(johnDoe));
5JSON vs GSON vs JACKSON06/21/16
GSON Example
 Deserialization:-
 Gson gson = new Gson();
String json = "{"name":"John","surname":"Doe","cars":
[{"manufacturer":"Audi","model":"A4","capacity":1.8,"a
ccident":false},
{"manufacturer":"Škoda","model":"Octavia","capacity":2.
0,"accident":true}], "phone":245987453}";
Person johnDoe = gson.fromJson(json, Person.class);
System.out.println(johnDoe.toString());
6JSON vs GSON vs JACKSON06/21/16
The working of JACKSON
 It is a Java library for processing JSON.
 Jackson aims to be the best possible combination of fast,
correct, lightweight, and friendly for developers.
 Jackson offers three alternative methods:-
 Stream API
 Tree Model
 Data Binding
7JSON vs GSON vs JACKSON06/21/16
JACKSON Example- Data Binding
 Read the Values from JSON file:-
 ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(new File("user.json"), User.class);
 Write the values To the JSON file:-
 mapper.writeValue(new File("user-modified.json"), user);
8JSON vs GSON vs JACKSON06/21/16
JACKSON Example- Tree Model
 Tree Model:-
 ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = mapper.createArrayNode();
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("Firstname", student.getFirstName());
objectNode.put("Lastname",student.getLastName());
objectNode.put("age", student.getAge());
objectNode.put("address", student.getAddress());
objectNode.put("studentId", student.getStudentId());
arrayNode.add(objectNode);
9JSON vs GSON vs JACKSON06/21/16
JACKSON Example- Stream API
 Writing to File:-
JsonFactory f = new JsonFactory();
JsonGenerator g =f.createJsonGenerator(new File("user.json"));
g.writeStartObject();
g.writeStartArray();
g.writeEndArray();
g.writeEndObject();
g.close();
06/21/16 JSON vs GSON vs JACKSON 10
JACKSON Example- Stream API
JsonFactory jfactory = new JsonFactory();
JsonParser jParser = jfactory.createJsonParser(new File("c://temp/user.json"));
while (jParser.nextToken() != JsonToken.END_OBJECT) {
if ("name".equals(fieldname)) {
jParser.nextToken();
System.out.println(jParser.getText()); }
if ("age".equals(fieldname)) {
jParser.nextToken();
System.out.println(jParser.getIntValue()); }
if ("messages".equals(fieldname)) {
jParser.nextToken();
while (jParser.nextToken() != JsonToken.END_ARRAY) {
System.out.println(jParser.getText()); }}
06/21/16 JSON vs GSON vs JACKSON 11
COMPARISON-Big File
12JSON vs GSON vs JACKSON06/21/16
COMPARISON-Small File
13JSON vs GSON vs JACKSON06/21/16
CONCLUSION
 If you are dealing with big JSON files, then Jackson is your
library of interest.
 If you are dealing with with lots of small JSON requests then
GSON is your library of interest.
 If you end up having to often deal with both types of files,
then JSON.simple. Neither Jackson nor GSON perform as
well across multiple files sizes.
14JSON vs GSON vs JACKSON06/21/16
References:
 www.json.org
 http://wiki.fasterxml.com/JacksonHome
 https://google-
gson.googlecode.com/svn/trunk/gson/docs/javadocs/c
om/google/gson/Gson.html
15JSON vs GSON vs JACKSON06/21/16
Thank you

More Related Content

What's hot

Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Jakarta EE: Today and Tomorrow
Jakarta EE: Today and TomorrowJakarta EE: Today and Tomorrow
Jakarta EE: Today and TomorrowDmitry Kornilov
 
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020AWSKRUG - AWS한국사용자모임
 
5 collection framework
5 collection framework5 collection framework
5 collection frameworkMinal Maniar
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdfSumirVats
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 

What's hot (20)

Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Jakarta EE: Today and Tomorrow
Jakarta EE: Today and TomorrowJakarta EE: Today and Tomorrow
Jakarta EE: Today and Tomorrow
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
Amplify를 통해 클라우드 기반 모바일 앱 개발하기 - 박태성(IDEASAM) :: AWS Community Day 2020
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
String Handling
String HandlingString Handling
String Handling
 
Java I/O
Java I/OJava I/O
Java I/O
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Apache spark
Apache sparkApache spark
Apache spark
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdf
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 

Similar to Json vs Gson vs Jackson

Similar to Json vs Gson vs Jackson (20)

Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Working with JSON.pptx
Working with JSON.pptxWorking with JSON.pptx
Working with JSON.pptx
 
Json
JsonJson
Json
 
java script json
java script jsonjava script json
java script json
 
JSON(JavaScript Object Notation) Presentation transcript
JSON(JavaScript Object Notation) Presentation transcriptJSON(JavaScript Object Notation) Presentation transcript
JSON(JavaScript Object Notation) Presentation transcript
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
JSON - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object Notation
 
Mongodb
MongodbMongodb
Mongodb
 
Json
JsonJson
Json
 
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 
An introduction to json
An introduction to jsonAn introduction to json
An introduction to json
 
Json
JsonJson
Json
 
JSON
JSONJSON
JSON
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
Unit-2 JSON.pdf
Unit-2 JSON.pdfUnit-2 JSON.pdf
Unit-2 JSON.pdf
 
JSON and The Argonauts
JSON and The ArgonautsJSON and The Argonauts
JSON and The Argonauts
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Gson
GsonGson
Gson
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 

Recently uploaded

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 

Recently uploaded (20)

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 

Json vs Gson vs Jackson

  • 1. JSON vs GSON vs JACKSON - Vinaykumar Hebballi
  • 2. Topics to cover  Overview of JSON  The working of GSON  The working of JACKSON  Comparison of JSON,GSON and JACKSON.  Conclusion 2JSON vs GSON vs JACKSON06/21/16
  • 3. What is JSON  JSON is a lightweight data interchange format .  The most important aspects of JSON are  Simplicity  Extensibility  Interoperability  Openness and Human readability. 3JSON vs GSON vs JACKSON06/21/16
  • 4. The working of GSON  GSON is an Java library to serialize and deserialize Java objects to (and from) JSON.  It provides two methods :-  Gson.toJson to serialize java objects.  Gson.fromJson to deserialize json objects. 4JSON vs GSON vs JACKSON06/21/16
  • 5. GSON Example  Serialization:-  Gson gson = new Gson(); Car audi = new Car("Audi", "A4", 1.8, false); Car skoda = new Car(“Skoda", "Octavia", 2.0, true); Car[] cars = {audi, skoda}; Person johnDoe = new Person("John", "Doe", 245987453, 35, cars); System.out.println(gson.toJson(johnDoe)); 5JSON vs GSON vs JACKSON06/21/16
  • 6. GSON Example  Deserialization:-  Gson gson = new Gson(); String json = "{"name":"John","surname":"Doe","cars": [{"manufacturer":"Audi","model":"A4","capacity":1.8,"a ccident":false}, {"manufacturer":"Škoda","model":"Octavia","capacity":2. 0,"accident":true}], "phone":245987453}"; Person johnDoe = gson.fromJson(json, Person.class); System.out.println(johnDoe.toString()); 6JSON vs GSON vs JACKSON06/21/16
  • 7. The working of JACKSON  It is a Java library for processing JSON.  Jackson aims to be the best possible combination of fast, correct, lightweight, and friendly for developers.  Jackson offers three alternative methods:-  Stream API  Tree Model  Data Binding 7JSON vs GSON vs JACKSON06/21/16
  • 8. JACKSON Example- Data Binding  Read the Values from JSON file:-  ObjectMapper mapper = new ObjectMapper(); User user = mapper.readValue(new File("user.json"), User.class);  Write the values To the JSON file:-  mapper.writeValue(new File("user-modified.json"), user); 8JSON vs GSON vs JACKSON06/21/16
  • 9. JACKSON Example- Tree Model  Tree Model:-  ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); ObjectNode objectNode = mapper.createObjectNode(); objectNode.put("Firstname", student.getFirstName()); objectNode.put("Lastname",student.getLastName()); objectNode.put("age", student.getAge()); objectNode.put("address", student.getAddress()); objectNode.put("studentId", student.getStudentId()); arrayNode.add(objectNode); 9JSON vs GSON vs JACKSON06/21/16
  • 10. JACKSON Example- Stream API  Writing to File:- JsonFactory f = new JsonFactory(); JsonGenerator g =f.createJsonGenerator(new File("user.json")); g.writeStartObject(); g.writeStartArray(); g.writeEndArray(); g.writeEndObject(); g.close(); 06/21/16 JSON vs GSON vs JACKSON 10
  • 11. JACKSON Example- Stream API JsonFactory jfactory = new JsonFactory(); JsonParser jParser = jfactory.createJsonParser(new File("c://temp/user.json")); while (jParser.nextToken() != JsonToken.END_OBJECT) { if ("name".equals(fieldname)) { jParser.nextToken(); System.out.println(jParser.getText()); } if ("age".equals(fieldname)) { jParser.nextToken(); System.out.println(jParser.getIntValue()); } if ("messages".equals(fieldname)) { jParser.nextToken(); while (jParser.nextToken() != JsonToken.END_ARRAY) { System.out.println(jParser.getText()); }} 06/21/16 JSON vs GSON vs JACKSON 11
  • 12. COMPARISON-Big File 12JSON vs GSON vs JACKSON06/21/16
  • 13. COMPARISON-Small File 13JSON vs GSON vs JACKSON06/21/16
  • 14. CONCLUSION  If you are dealing with big JSON files, then Jackson is your library of interest.  If you are dealing with with lots of small JSON requests then GSON is your library of interest.  If you end up having to often deal with both types of files, then JSON.simple. Neither Jackson nor GSON perform as well across multiple files sizes. 14JSON vs GSON vs JACKSON06/21/16
  • 15. References:  www.json.org  http://wiki.fasterxml.com/JacksonHome  https://google- gson.googlecode.com/svn/trunk/gson/docs/javadocs/c om/google/gson/Gson.html 15JSON vs GSON vs JACKSON06/21/16