<Insert Picture Here>
JSR-353 : Java API for Processing JSON
Jitendra Kotamraju
2
The following is intended to outline our general product direction. It is
intended for information purposes only, and may not be incorporated
into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing
decisions. The development, release, and timing of any features or
functionality described for Oracles products remains at the sole
discretion of Oracle.
3
Agenda
?? Overview
?? JAX-RS Usage
?? Standardization
4
Overview
?? JSON is a light-weight data exchange format
–? Easy for humans/machines to read and write
–? For e.g.:
{"name":"Bob", "age":20, "phone":["276 1234", "123
4567"]}
?? JSON is used by popular web sites in their RESTful
web services
–? Facebook, Twitter, Amazon, …
–? Twitter Streaming API discontinues XML
JSON
5
Overview
JSON usages
?? Policy in Amazon SQS
{
...
"Statement": {
"Effect": "Allow",
"Principal": { "AWS": "123456789012” },
"Action": "sqs:SendMessage",
"Resource": "/987654321098/queue1"
}
}
6
Overview
?? Followers in Twitter API
{
"previous_cursor": 0,
"ids": [143206502, 143201767, 777925],
"previous_cursor_str": "0",
...
}
JSON usages
7
JAX-RS
?? JAX-RS applications handle XML using JAXP API
XML Usage
@Produces(“application/xml”)
public Source getBook(String id) {
return new StreamSource(…);
}
8
JAX-RS
?? JAX-RS applications handle XML using JAXB API
XML Usage
@Produces(“application/xml”)
public Book getBook(String id) {
return new Book(…);
}
9
JAX-RS
?? JAX-RS content negotiation
DataBinding
XML
JSON
JAX-RS
Book
@Produces({“application/xml”, “application/json”})
public Book getBook(String id) {
return new Book();
}
10
JAX-RS
?? A custom MessageBodyWriter that converts to JSON
–? JSONObject (For e.g. json.org’s API) → JSON
–? JAXB → StAX → JSON (For e.g. using jettison)
–? POJO/JAXB → JSON (For e.g. using jackson, eclipseLink
etc.)
?? No standard API
?? Some solutions have technical limitations
?? Applications/Frameworks need to bundle the libraries
JSON Solutions & Limitations
11
Standard API
?? Application can use standard types
?? Leaner, portable applications
Advantages
12
Standard API
?? Parsing/Processing JSON
?? Data binding : JSON text <-> Java Objects
?? Two JSRs: Processing/Parsing (JSON-P), Binding
(JSON-B)
–? Similar to JAXP and JAXB
–? Close collaboration between the two
Contents
13
Java API for Processing JSON (JSON-P)
?? Streaming API to produce/consume JSON
–? Similar to StAX API in XML world
?? Object model API to represent JSON
–? Similar to DOM API in XML world
?? Align with Java EE 7 schedules
?? JSR Supporters
–? fasterxml.com(Jackson), Doug Crockford(json.org)
JSR-353
14
JSR-353 : Status
Source: http://blogs.oracle.com/darcy/entry/pictorial_jcp
Here
15
JSR-353 Transparency
?? json-processing-spec java.net open source project is
used for JSR-353
?? Mailing lists:
–? users@json-processing-spec.java.net
–? jsr353-experts@json-processing-spec.java.net
?? Issue Tracker:
–? http://java.net/jira/browse/JSON_PROCESSING_SPEC
Open Source Project
16
Resources
?? http://json-processing-spec.java.net
17
Q&A
18
Parsing API
JSON Grammar
Source: http://json.org
19
Parsing API
JSON Grammar
Source: http://json.org
20
JSR-353 API
?? API initial proposal to EG
–? Based visitor pattern (similar to ASM, JSR 269 API, …)
–? Works nicely with streaming and tree API
–? Providers plug-in their implementations
Processing API
21
JSR-353 API
UML class diagram
22