SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

오픈플랫폼(Open platform) 개요 및 사례
오픈플랫폼(Open platform) 개요 및 사례오픈플랫폼(Open platform) 개요 및 사례
오픈플랫폼(Open platform) 개요 및 사례Youngjo Seong
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleVodqaBLR
 
MongoDB Atlas Data Lake 집중 분석 [MongoDB]
MongoDB Atlas Data Lake 집중 분석 [MongoDB]MongoDB Atlas Data Lake 집중 분석 [MongoDB]
MongoDB Atlas Data Lake 집중 분석 [MongoDB]MongoDB
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesecosio GmbH
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomasintuit_india
 
Azure DevOps - Um case de sucesso
Azure DevOps - Um case de sucessoAzure DevOps - Um case de sucesso
Azure DevOps - Um case de sucessoArmando Junior
 
Open source apm scouter를 통한 관제 관리 jadecross 정환열 수석
Open source apm scouter를 통한 관제  관리 jadecross 정환열 수석Open source apm scouter를 통한 관제  관리 jadecross 정환열 수석
Open source apm scouter를 통한 관제 관리 jadecross 정환열 수석uEngine Solutions
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react jsdhanushkacnd
 
Performance testing with Apache JMeter
Performance testing with Apache JMeterPerformance testing with Apache JMeter
Performance testing with Apache JMeterRedBlackTree
 
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축Sungmin Kim
 
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Jemin Huh
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 

Mais procurados (20)

오픈플랫폼(Open platform) 개요 및 사례
오픈플랫폼(Open platform) 개요 및 사례오픈플랫폼(Open platform) 개요 및 사례
오픈플랫폼(Open platform) 개요 및 사례
 
GraalVM
GraalVMGraalVM
GraalVM
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
MongoDB Atlas Data Lake 집중 분석 [MongoDB]
MongoDB Atlas Data Lake 집중 분석 [MongoDB]MongoDB Atlas Data Lake 집중 분석 [MongoDB]
MongoDB Atlas Data Lake 집중 분석 [MongoDB]
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
 
REST vs SOAP
REST vs SOAPREST vs SOAP
REST vs SOAP
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
Optimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest ApiOptimizing and Profiling Golang Rest Api
Optimizing and Profiling Golang Rest Api
 
Azure DevOps - Um case de sucesso
Azure DevOps - Um case de sucessoAzure DevOps - Um case de sucesso
Azure DevOps - Um case de sucesso
 
Open source apm scouter를 통한 관제 관리 jadecross 정환열 수석
Open source apm scouter를 통한 관제  관리 jadecross 정환열 수석Open source apm scouter를 통한 관제  관리 jadecross 정환열 수석
Open source apm scouter를 통한 관제 관리 jadecross 정환열 수석
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
 
Performance testing with Apache JMeter
Performance testing with Apache JMeterPerformance testing with Apache JMeter
Performance testing with Apache JMeter
 
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축
AWS Personalize 중심으로 살펴본 추천 시스템 원리와 구축
 
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Gherkin /BDD intro
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 

Semelhante a Json vs Gson vs Jackson

Semelhante a 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
 
XKE PlayFramework's Json in scala
XKE PlayFramework's Json in scalaXKE PlayFramework's Json in scala
XKE PlayFramework's Json in scala
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

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