One of the additions of Java EE 7 was the JSON-P specification for processing JSON documents. But JSON-P spec is moving forward and for Java EE 8 it will come with a lot of new features like support for JSON Pointer (RFC6901), JSON Patch (RFC6902) or JSON Merge Patch (RFC7386). But also improvements on performance, Java 8 integration and how to process big JSON data.
The first part of this session presents the JSON Processing API that comes with Java EE 7 to understand the basis for improvements of next version. The second part of the session presents the updates that are coming on the Java API for JSON Processing that they will be added inside Java EE 8.
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();
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)
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
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”));
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