SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
Updates to the Java API
for JSON Processing for
Java EE 8
Alex Soto & Mite Mitreski
#JSON #JAVAEE
Mite Mitreski
Software engineer
JSON-P 1.0
● JSR-353
● javax.json
○ Json, JsonReader,JsonWriter JsonString, JsonNumber...
● Implementations
○ RI in GlassFish
○ Jonzon
○ Genson
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
Agenda
● IETF RFC 7159 aka new JSON
● JsonArray and JsonObject transformations
● JSON Pointer
● JSON Patch, JSON Merge Patch
● JSON Queries
● Big JSON Processing
● Alignment with JSON-B
● Alignment with JAX-RS
RFC - 4627 - JSON - The application/json
Media Type for JavaScript Object
Notation
July 2006 JSON.org
On the 8th day, Douglas Crockford introduced JSON. And he saw that it was good.
IETF RFC 7159
The JavaScript Object Notation (JSON)
Data Interchange Format
Tim Bray - Google
2014 - Old new JSON
JSON-P 1.1
IETF RFC 7159 – New API
● Json
○ public static JsonString createValue(String value)
○ public static JsonNumber createValue(int value)
○ Similarly for long, double, BigInteger, and BigDecimal
● JsonReader
○ default JsonValue readValue()
● JsonWriter
○ default void write(JsonValue value)
JsonArray and
JsonObject
Transformations
JSON-P 1.1
● Transformation on immutable JsonArray and JsonObject
● Low level operations used in JsonPatch
● Use builder pattern
○ Create builders with initial JsonArray or JsonObject
○ Add editing operations to builders
○ Builder returns immutable JsonArray or JsonObject when done
JsonArray and JsonObject Transformations
Example : JSON array transformation
// Create the target
JsonArray target = Json.createArrayBuilder().add(…).build();
// Create a builder initialized with the target
JsonArrayBuilder builder = Json.createArrayBuilder(target);
// Operations on the array
JsonArray result = builder.add(99, "john")
.set(100, 1234)
.remove(3)
.build();
JSON Pointer
IETF RFC 6901
JSON Pointer
IETF RFC 6901
● String syntax for identifying a specific value
○ /author/name
○ /parents/0
● ‘/’ —> ‘~1’
● ‘~’ —> ‘~0’
● Absolute
JSON Pointer
JsonStructure beer = reader.read();
JsonPointer p = new JsonPointer("/brewery/key");
JsonValue name = p.getValue(beer);
{
"key":"guinness",
"title":"Guinness",
"brewery": {
"key": "guinness",
"title": "St. James's Gate Brewery"
}
}
JSON Pointer
● Apply operations to a pointer
○ add(JsonStructure, JsonValue)
○ replace(JsonStructure, JsonValue)
○ remove(JsonStructure)
JSON Pointer extra operations
JsonStructure beer = reader.read();
JsonPointer p = new JsonPointer("/brewery/key");
JsonStructure bewBeer = p.replace(beer, Json.createValue("GuinnessBrewery"));
"title":"Guinness",
"brewery": {
"key": "guinness"
}
"title":"Guinness",
"brewery": {
"key": "GuinessBrewery"
}
DEMO TIME
JSON Patch
IETF RFC 6902
JSON-P 1.1 JSON PATCH
● Standardise Update operation
● Sequence of modifications
○ test, remove, add, replace, move, copy
● JSON PATCH is a document
● HTTP PATCH method (application/json-patch+json)
JSON-PATCH — IETF RFC 6902
[
{"op":"replace", "path":"/brewery/key", “value”:"GuinessBrewery"},
{"op":"remove", "path": "/title"}
]
"title":"Guinness",
"brewery": {
"key": "guinness"
}
"brewery": {
"key": "GuinessBrewery"
}
JSON-PATCH — IETF RFC 6902
JsonArrayBuilder patchExpression = Json.createArrayBuilder();
//creates operation
JsonObjectBuilder patch = Json.createObjectBuilder()
.add("op", "replace")
.add("path", "/brewery/key")
.add("value", “GuinessBrewery");
patchExpression.add(patch);
JsonPatch jsonPatch = new JsonPatch(patchExpression.build());
JsonStructure beer = reader.read();
JsonStructure newBeer = jsonPatch.apply(beer);
JSON-PATCH — IETF RFC 6902
JsonPatchBuilder patchBuilder = new JsonPatchBuilder();
JsonStructure newBeer = patchBuilder
.replace("/brewery/key", "GuinessBrewery")
.remove("/title")
.apply(commit);
JSON-PATCH — extra operations
● Diff between two documents
○ Reverse operation
● Useful in case of conflicts
JSON-PATCH — extra operations
JsonArray diff = JsonPatch.diff(beer1, beer2);
[
{"op":"replace", "path":"/brewery/key", “value”:"GuinessBrewery"},
{"op":"remove", "path": "/title"}
]
DEMO TIME
JSON Merge Patch
IETF RFC 7386
JSON Merge patch
● Standardise Update operation
● Syntax that closely mimics the document being modified
● null value to delete
● JSON PATCH is a document
● HTTP PATCH method (application/json-patch+json)
JSON Merge patch
"title":"Guinness",
"brewery": {
"key": "guinness"
}
{"title":null}
"brewery": {
"key": "guinness"
}
JSON Merge patch
JsonStructure beer = reader.read();
JsonObject removeTitle = Json.createObjectBuilder()
.add("title", JsonValue.NULL)
.build();
JsonValue newBeer = JsonMergePatch.mergePatch(beer, removeTitle);
JSON Merge patch
● Diff between two documents
○ Reverse operation
● Useful in case of conflicts
JSON Merge patch
JsonValue diff = JsonMergePatch.diff(beer, newBeer);
{"title": null}
DEMO TIME
JSON Queries
Working with java.util.Stream
JSON queries
● A JsonObject is a Map, and a JsonArray is a List, so
queries can be implemented with Java’s stream
operations, using Lambda expressions
● Get concurrent processing for free
● We need collectors that return JsonArray or JsonObject
instead of List or Map.
JSON queries
● toJsonArray
○ Accumulates values in a JsonArray
● toJsonObject
○ Accumulates values in a JsonObject
● groupBy
○ Implements “group by” operations on the values
DEMO TIME
BIG JSON Data
JSON processing of large objects
JSON-P 1.1 Big JSON
● Too big to build data model in memory
● Dynamically generated JSON
● Usually interested only small fraction of data
JSON-P 1.1 Big JSON
● JsonParser parses JSON using streaming model
● Pull model, under user control
● Efficient in execution and memory usage
● Low level, token based
JSON-P 1.1 Big JSON
● skipArray
○ Skip tokens and advance the parser to END_ARRAY
● skipObject
○ Skip tokens and advance the parser to END_OBJECT
DEMO TIME
Alignment
with JSON-B and JAX-RS
JSON-B
● API to marshal/unmarshal Java objects to/from JSON
● From best practices of existing JSON binders
a. Gson, Jackson, Johnzon, ...
● Implementations compete on common ground
● MUST support binding of the JSON Processing API
JSON-B
Jsonb jsonb = JsonbBuilder.create();
// Unmarshal
Book book = jsonb.fromJson(new File(“book.json”), Book.class);
// Marshal
jsonb.toJson(book, new File(“book.json”));
JAX-RS
@Patch
@Consumes(MediaType.APPLICATION_JSON_PATCH)
public Response updateBook(..., JsonPatch patch){}
● integration with JSON-B
● Integration with JSON-P PATCH
JSON-P 1.1 Current status
● Early Draft Review
○ http://download.oracle.com/otndocs/jcp/json_p-1_1-edr-spec/index.html
● Roadmap
○ Q1 2016 Public Review
○ Q3 2016 Proposed Final Draft
○ H1 2017 Final Release
JSON-P 1.1 Expert Group
● Public Project Page
○ https://java.net/projects/json-processing-spec
● Public Communications
○ https://java.net/projects/json-processing-spec/lists
● Issue Tracking
○ https://java.net/jira/browse/JSON_PROCESSING_SPEC
JSON-P 1.1 Reference Implementation
● Public Project Page
○ https://java.net/projects/jsonp
○ https://jsonp.java.net/
● Source Code Repository
○ git://java.net/jsonp~git
○ https://github.com/json-processing-inofficial
● Issue Tracking
○ https://java.net/jira/browse/JSONP
QUESTIONS ?
● Alex Soto
○ @alexsotob
● Mite Mitreski
○ @mitemitreski

Más contenido relacionado

La actualidad más candente

Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDBMongoDB
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBMongoDB
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...mfrancis
 
MongoDB & Mongoid with Rails
MongoDB & Mongoid with RailsMongoDB & Mongoid with Rails
MongoDB & Mongoid with RailsJustin Smestad
 
Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopSteven Francia
 
AMD - Why, What and How
AMD - Why, What and HowAMD - Why, What and How
AMD - Why, What and HowMike Wilcox
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devmcantelon
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDBJames Williams
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBRob Tweed
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDBScott Hernandez
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOSgillygize
 

La actualidad más candente (20)

Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
Analyse Yourself
Analyse YourselfAnalyse Yourself
Analyse Yourself
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
MongoDB & Mongoid with Rails
MongoDB & Mongoid with RailsMongoDB & Mongoid with Rails
MongoDB & Mongoid with Rails
 
Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and Hadoop
 
AMD - Why, What and How
AMD - Why, What and HowAMD - Why, What and How
AMD - Why, What and How
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & Tricks
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal dev
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
Latinoware
LatinowareLatinoware
Latinoware
 

Similar a Updates to the java api for json processing for java ee 8

Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011sullis
 
Json in Postgres - the Roadmap
 Json in Postgres - the Roadmap Json in Postgres - the Roadmap
Json in Postgres - the RoadmapEDB
 
There is Javascript in my SQL
There is Javascript in my SQLThere is Javascript in my SQL
There is Javascript in my SQLPGConf APAC
 
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data typePostgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data typeJumping Bean
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportJsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportAlexander Korotkov
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013PostgresOpen
 
PostgreSQL 9.3 and JSON - talk at PgOpen 2013
PostgreSQL 9.3 and JSON - talk at PgOpen 2013PostgreSQL 9.3 and JSON - talk at PgOpen 2013
PostgreSQL 9.3 and JSON - talk at PgOpen 2013Andrew Dunstan
 
Javascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsJavascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsVelanSalis
 
JSON Support in DB2 for z/OS
JSON Support in DB2 for z/OSJSON Support in DB2 for z/OS
JSON Support in DB2 for z/OSJane Man
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problemstitanlambda
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
MongoDB and Web Scrapping with the Gyes Platform
MongoDB and Web Scrapping with the Gyes PlatformMongoDB and Web Scrapping with the Gyes Platform
MongoDB and Web Scrapping with the Gyes PlatformMongoDB
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cJim Czuprynski
 

Similar a Updates to the java api for json processing for java ee 8 (20)

Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Json in Postgres - the Roadmap
 Json in Postgres - the Roadmap Json in Postgres - the Roadmap
Json in Postgres - the Roadmap
 
9.4json
9.4json9.4json
9.4json
 
Play! with rest
Play! with restPlay! with rest
Play! with rest
 
There is Javascript in my SQL
There is Javascript in my SQLThere is Javascript in my SQL
There is Javascript in my SQL
 
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data typePostgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data type
 
Json
JsonJson
Json
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportJsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing support
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
 
PostgreSQL 9.3 and JSON - talk at PgOpen 2013
PostgreSQL 9.3 and JSON - talk at PgOpen 2013PostgreSQL 9.3 and JSON - talk at PgOpen 2013
PostgreSQL 9.3 and JSON - talk at PgOpen 2013
 
Introduction to Yasson
Introduction to YassonIntroduction to Yasson
Introduction to Yasson
 
Javascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsJavascript in C# for Lightweight Applications
Javascript in C# for Lightweight Applications
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
JSON Support in DB2 for z/OS
JSON Support in DB2 for z/OSJSON Support in DB2 for z/OS
JSON Support in DB2 for z/OS
 
Oxygen JSON Editor
Oxygen JSON EditorOxygen JSON Editor
Oxygen JSON Editor
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
MongoDB and Web Scrapping with the Gyes Platform
MongoDB and Web Scrapping with the Gyes PlatformMongoDB and Web Scrapping with the Gyes Platform
MongoDB and Web Scrapping with the Gyes Platform
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Updates to the java api for json processing for java ee 8

  • 1. Updates to the Java API for JSON Processing for Java EE 8 Alex Soto & Mite Mitreski #JSON #JAVAEE
  • 2.
  • 4. JSON-P 1.0 ● JSR-353 ● javax.json ○ Json, JsonReader,JsonWriter JsonString, JsonNumber... ● Implementations ○ RI in GlassFish ○ Jonzon ○ Genson <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.json</artifactId> <version>1.0.4</version> </dependency>
  • 5. Agenda ● IETF RFC 7159 aka new JSON ● JsonArray and JsonObject transformations ● JSON Pointer ● JSON Patch, JSON Merge Patch ● JSON Queries ● Big JSON Processing ● Alignment with JSON-B ● Alignment with JAX-RS
  • 6. RFC - 4627 - JSON - The application/json Media Type for JavaScript Object Notation July 2006 JSON.org On the 8th day, Douglas Crockford introduced JSON. And he saw that it was good.
  • 7. IETF RFC 7159 The JavaScript Object Notation (JSON) Data Interchange Format Tim Bray - Google 2014 - Old new JSON
  • 8. JSON-P 1.1 IETF RFC 7159 – New API ● Json ○ public static JsonString createValue(String value) ○ public static JsonNumber createValue(int value) ○ Similarly for long, double, BigInteger, and BigDecimal ● JsonReader ○ default JsonValue readValue() ● JsonWriter ○ default void write(JsonValue value)
  • 10. JSON-P 1.1 ● Transformation on immutable JsonArray and JsonObject ● Low level operations used in JsonPatch ● Use builder pattern ○ Create builders with initial JsonArray or JsonObject ○ Add editing operations to builders ○ Builder returns immutable JsonArray or JsonObject when done JsonArray and JsonObject Transformations
  • 11. Example : JSON array transformation // Create the target JsonArray target = Json.createArrayBuilder().add(…).build(); // Create a builder initialized with the target JsonArrayBuilder builder = Json.createArrayBuilder(target); // Operations on the array JsonArray result = builder.add(99, "john") .set(100, 1234) .remove(3) .build();
  • 13. JSON Pointer IETF RFC 6901 ● String syntax for identifying a specific value ○ /author/name ○ /parents/0 ● ‘/’ —> ‘~1’ ● ‘~’ —> ‘~0’ ● Absolute
  • 14. JSON Pointer JsonStructure beer = reader.read(); JsonPointer p = new JsonPointer("/brewery/key"); JsonValue name = p.getValue(beer); { "key":"guinness", "title":"Guinness", "brewery": { "key": "guinness", "title": "St. James's Gate Brewery" } }
  • 15. JSON Pointer ● Apply operations to a pointer ○ add(JsonStructure, JsonValue) ○ replace(JsonStructure, JsonValue) ○ remove(JsonStructure)
  • 16. JSON Pointer extra operations JsonStructure beer = reader.read(); JsonPointer p = new JsonPointer("/brewery/key"); JsonStructure bewBeer = p.replace(beer, Json.createValue("GuinnessBrewery")); "title":"Guinness", "brewery": { "key": "guinness" } "title":"Guinness", "brewery": { "key": "GuinessBrewery" }
  • 19. JSON-P 1.1 JSON PATCH ● Standardise Update operation ● Sequence of modifications ○ test, remove, add, replace, move, copy ● JSON PATCH is a document ● HTTP PATCH method (application/json-patch+json)
  • 20. JSON-PATCH — IETF RFC 6902 [ {"op":"replace", "path":"/brewery/key", “value”:"GuinessBrewery"}, {"op":"remove", "path": "/title"} ] "title":"Guinness", "brewery": { "key": "guinness" } "brewery": { "key": "GuinessBrewery" }
  • 21. JSON-PATCH — IETF RFC 6902 JsonArrayBuilder patchExpression = Json.createArrayBuilder(); //creates operation JsonObjectBuilder patch = Json.createObjectBuilder() .add("op", "replace") .add("path", "/brewery/key") .add("value", “GuinessBrewery"); patchExpression.add(patch); JsonPatch jsonPatch = new JsonPatch(patchExpression.build()); JsonStructure beer = reader.read(); JsonStructure newBeer = jsonPatch.apply(beer);
  • 22. JSON-PATCH — IETF RFC 6902 JsonPatchBuilder patchBuilder = new JsonPatchBuilder(); JsonStructure newBeer = patchBuilder .replace("/brewery/key", "GuinessBrewery") .remove("/title") .apply(commit);
  • 23. JSON-PATCH — extra operations ● Diff between two documents ○ Reverse operation ● Useful in case of conflicts
  • 24. JSON-PATCH — extra operations JsonArray diff = JsonPatch.diff(beer1, beer2); [ {"op":"replace", "path":"/brewery/key", “value”:"GuinessBrewery"}, {"op":"remove", "path": "/title"} ]
  • 27. JSON Merge patch ● Standardise Update operation ● Syntax that closely mimics the document being modified ● null value to delete ● JSON PATCH is a document ● HTTP PATCH method (application/json-patch+json)
  • 28. JSON Merge patch "title":"Guinness", "brewery": { "key": "guinness" } {"title":null} "brewery": { "key": "guinness" }
  • 29. JSON Merge patch JsonStructure beer = reader.read(); JsonObject removeTitle = Json.createObjectBuilder() .add("title", JsonValue.NULL) .build(); JsonValue newBeer = JsonMergePatch.mergePatch(beer, removeTitle);
  • 30. JSON Merge patch ● Diff between two documents ○ Reverse operation ● Useful in case of conflicts
  • 31. JSON Merge patch JsonValue diff = JsonMergePatch.diff(beer, newBeer); {"title": null}
  • 33. JSON Queries Working with java.util.Stream
  • 34. JSON queries ● A JsonObject is a Map, and a JsonArray is a List, so queries can be implemented with Java’s stream operations, using Lambda expressions ● Get concurrent processing for free ● We need collectors that return JsonArray or JsonObject instead of List or Map.
  • 35. JSON queries ● toJsonArray ○ Accumulates values in a JsonArray ● toJsonObject ○ Accumulates values in a JsonObject ● groupBy ○ Implements “group by” operations on the values
  • 37. BIG JSON Data JSON processing of large objects
  • 38. JSON-P 1.1 Big JSON ● Too big to build data model in memory ● Dynamically generated JSON ● Usually interested only small fraction of data
  • 39. JSON-P 1.1 Big JSON ● JsonParser parses JSON using streaming model ● Pull model, under user control ● Efficient in execution and memory usage ● Low level, token based
  • 40. JSON-P 1.1 Big JSON ● skipArray ○ Skip tokens and advance the parser to END_ARRAY ● skipObject ○ Skip tokens and advance the parser to END_OBJECT
  • 43. JSON-B ● API to marshal/unmarshal Java objects to/from JSON ● From best practices of existing JSON binders a. Gson, Jackson, Johnzon, ... ● Implementations compete on common ground ● MUST support binding of the JSON Processing API
  • 44. JSON-B Jsonb jsonb = JsonbBuilder.create(); // Unmarshal Book book = jsonb.fromJson(new File(“book.json”), Book.class); // Marshal jsonb.toJson(book, new File(“book.json”));
  • 45. JAX-RS @Patch @Consumes(MediaType.APPLICATION_JSON_PATCH) public Response updateBook(..., JsonPatch patch){} ● integration with JSON-B ● Integration with JSON-P PATCH
  • 46. JSON-P 1.1 Current status ● Early Draft Review ○ http://download.oracle.com/otndocs/jcp/json_p-1_1-edr-spec/index.html ● Roadmap ○ Q1 2016 Public Review ○ Q3 2016 Proposed Final Draft ○ H1 2017 Final Release
  • 47. JSON-P 1.1 Expert Group ● Public Project Page ○ https://java.net/projects/json-processing-spec ● Public Communications ○ https://java.net/projects/json-processing-spec/lists ● Issue Tracking ○ https://java.net/jira/browse/JSON_PROCESSING_SPEC
  • 48. JSON-P 1.1 Reference Implementation ● Public Project Page ○ https://java.net/projects/jsonp ○ https://jsonp.java.net/ ● Source Code Repository ○ git://java.net/jsonp~git ○ https://github.com/json-processing-inofficial ● Issue Tracking ○ https://java.net/jira/browse/JSONP
  • 49. QUESTIONS ? ● Alex Soto ○ @alexsotob ● Mite Mitreski ○ @mitemitreski