SlideShare a Scribd company logo
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

More Related Content

What's hot

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
 

What's hot (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 to 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 to 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
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 

Recently uploaded (20)

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

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