SlideShare uma empresa Scribd logo
1 de 83
Baixar para ler offline
Java 
API 
for 
JSON 
Binding 
Introduction 
and 
update 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Martin 
Grebac 
JSON-­‐B 
Spec 
lead 
Development 
Manager 
TopLink 
& 
Metro 
Oracle 
Accept: 
application/json
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Program 
Agenda 
Introduction 
JSR; 
Status; 
Next 
Steps 
API 
Integration 
Q 
& 
A 
1 
2 
3 
4 
5 
4
Safe 
Harbor 
Statement 
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 
Oracle’s 
products 
remains 
at 
the 
sole 
discretion 
of 
Oracle. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
5
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Introduction 
6
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
7
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
8 
public 
class 
Employee 
{ 
public 
int 
id; 
public 
String 
firstName; 
public 
String 
lastName; 
public 
String 
email; 
…. 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
9 
! 
Employee 
e 
= 
new 
Employee(); 
e.id 
= 
1111; 
e.firstName 
= 
“Martin”; 
e.lastName 
= 
“Grebac”; 
e.email 
= 
“martin.grebac@oracle.com”;
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
9 
! 
Employee 
e 
= 
new 
Employee(); 
e.id 
= 
1111; 
e.firstName 
= 
“Martin”; 
e.lastName 
= 
“Grebac”; 
e.email 
= 
“martin.grebac@oracle.com”;
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
9 
! 
Employee 
e 
= 
new 
Employee(); 
e.id 
= 
1111; 
e.firstName 
= 
“Martin”; 
e.lastName 
= 
“Grebac”; 
e.email 
= 
“martin.grebac@oracle.com”; 
{ 
"id": 
1111, 
"firstName" 
: 
"Martin", 
"lastName" 
: 
"Grebac", 
"email": 
"martin.grebac@oracle.com" 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
What 
is 
JSON 
Binding? 
• Converting 
Java 
objects 
to 
& 
from 
JSON 
10 
JAX-­‐RS 
Objects 
XML 
JSON 
JAXB 
JSON-­‐B
Standardizing 
current 
technology 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Many 
mature 
or 
emerging 
JSON 
binding 
frameworks 
out 
there 
11 
! 
• Jackson 
• Genson 
• Gson 
• EclipseLink 
MOXy 
• Fleece 
• JSON-­‐lib 
• Flexjson 
• Json-­‐io 
• JSONiJ 
• Xstream 
• …
Standardizing 
current 
technology 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Many 
mature 
or 
emerging 
JSON 
binding 
frameworks 
out 
there 
11 
! 
• Jackson 
• Genson 
• Gson 
• EclipseLink 
MOXy 
• Fleece 
• JSON-­‐lib 
• Flexjson 
• Json-­‐io 
• JSONiJ 
• Xstream 
• …
Standardizing 
current 
technology 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• Many 
mature 
or 
emerging 
JSON 
binding 
frameworks 
out 
there 
11 
! 
• Jackson 
• Genson 
• Gson 
• EclipseLink 
MOXy 
• Fleece 
• JSON-­‐lib 
• Flexjson 
• Json-­‐io 
• JSONiJ 
• Xstream 
• …
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Standard 
API 
-­‐ 
Advantages 
• Switch 
providers 
easily 
• Implementation 
compete 
on 
common 
ground 
(performance 
or 
feature-­‐ 
wise) 
• Loss 
of 
implementation/participant 
is 
no 
issue 
for 
standard 
• More 
people 
able 
to 
help 
on 
forums 
or 
stackoverflow 
;) 
even 
those 
not 
using 
your 
implementation 
of 
choice 
12
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
13
JSR; 
Status; 
Next 
Steps 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
14
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Status 
• JSR 
Proposal 
Submitted 
• https://www.jcp.org/en/jsr/detail?id=367 
15
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
16 
Proposal 
– 
In 
short 
• API 
with 
similar 
feel 
to 
JAXB 
! 
• javax.json.bind 
! 
• Spec 
project: 
http://jsonb-­‐spec.java.net 
(stay 
tuned) 
! 
• RI 
project: 
http://eclipselink.org 
! 
• Standalone, 
looking 
for 
Java 
EE 
8
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Status 
• JSR 
Proposal 
Submitted 
• https://www.jcp.org/en/jsr/detail?id=367 
• JSR 
Review 
period 
finished 
08/Sep/2014 
• JSR 
Review 
ballot 
finished 
22/Sep/2014 
17
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Status 
• JSR 
Proposal 
Submitted 
• https://www.jcp.org/en/jsr/detail?id=367 
• JSR 
Review 
period 
finished 
08/Sep/2014 
• JSR 
Review 
ballot 
finished 
22/Sep/2014 
17
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Status 
• JSR 
Proposal 
Submitted 
• https://www.jcp.org/en/jsr/detail?id=367 
• JSR 
Review 
period 
finished 
08/Sep/2014 
• JSR 
Review 
ballot 
finished 
22/Sep/2014 
! 
• Accepting 
EG 
nominations: 
• https://www.jcp.org/en/jsr/egnom?id=367 
18
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Next 
Steps 
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
19 
• Form 
Expert 
Group 
• Early 
Draft
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Next 
Steps 
JSR 
367 
– 
Java 
API 
for 
JSON 
Binding 
(JSON-­‐B) 
20 
• Form 
Expert 
Group 
• Early 
Draft
API 
– 
Goals, 
Non-­‐goals 
-­‐ 
Proposal 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
21
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
22 
Proposal 
– 
Goals 
• Binding 
JSON 
(RFC 
7159) 
documents 
• Maintain 
consistency 
with 
JAXB 
API 
and 
other 
Java 
SE 
& 
EE 
APIs 
where 
applicable 
• Define 
default 
object-­‐JSON 
mapping 
• Annotation 
based 
customizations 
for 
object-­‐JSON 
mapping 
• Support 
binding 
using 
JSON-­‐P 
APIs 
! 
• Explore 
mapping 
subset 
of 
Json 
documents 
(Json 
Pointer) 
• Explore 
options 
to 
map 
3rd 
party 
objects 
• Explore 
bi-­‐directional 
mappings
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
23 
Proposal 
– 
Non-­‐goals 
• JSON 
Schema 
• Tooltime 
• Roundtrip 
• JEP 
198 
-­‐ 
Lightweight 
JSON 
API
Runtime 
API 
-­‐ 
Proposal 
Anything 
subject 
to 
change 
anytime 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
24
Proposal 
– 
Runtime 
Initialization 
– 
Default 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
25 
import 
javax.json.bind.*; 
! 
public 
void 
init() 
{ 
! 
JsonContext 
context 
= 
JsonContext.newInstance(); 
! 
// 
JsonContext 
context 
= 
// 
JsonContext.newInstance(“com.provider.ProviderFactory"); 
! 
Marshaller 
marshaller 
= 
context.createMarshaller(); 
! 
Unmarshaller 
unmarshaller 
= 
context.createUnmarshaller; 
! 
}
Proposal 
– 
Runtime 
Initialization 
– 
Context 
Builder 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
26 
public 
void 
init() 
{ 
! 
JsonContext 
context 
= 
new 
JsonContextBuilder() 
.setScope 
(MyClass.class, 
…) 
.excludeField(“field”, 
MyClass.class) 
.addFilter(myContextFilterImplementation) 
.build(); 
}
Proposal 
– 
Runtime 
Initialization 
– 
Fluent 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
27 
public 
void 
init() 
{ 
! 
JsonContext 
context 
= 
JsonContext.newInstance(); 
! 
Marshaller 
marshaller 
= 
context.createMarshaller() 
.setProperty(Marshaller.PROPERTY) 
.setPrettyPrinting(true); 
! 
Unmarshaller 
unmarshaller 
= 
context.createUnmarshaller() 
.setCloseStreams(true); 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
28 
Proposal 
– 
Marshalling 
(Writing) 
public 
void 
marshal() 
{ 
!! 
Marshaller 
marshaller 
= 
jsonContext.createMarshaller(); 
! 
//to 
String 
String 
string 
= 
marshaller.marshal(myObject); 
! 
//to 
Writer 
marshaller.marshal(myObject, 
new 
FileWriter(“file.json”)); 
!! }
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
29 
Proposal 
– 
Marshalling 
(Writing) 
public 
void 
marshal() 
{ 
! 
Marshaller 
marshaller 
= 
jsonContext.createMarshaller(); 
! 
//to 
JSONP 
JsonGenerator 
FileWriter 
writer 
= 
new 
FileWriter(“file.json”); 
JsonGenerator 
generator 
= 
Json.createGenerator(writer); 
marshaller.marshal(myObject, 
generator); 
! 
//expose 
as 
JSONP 
JsonParser 
JsonParser 
parser 
= 
marshaller.getJsonParser(myObject); 
! 
//other 
JSONP 
constructs 
JsonObjectBuilder, 
… 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
30 
Proposal 
– 
Unmarshalling 
(Reading) 
public 
void 
unmarshal() 
{ 
! 
Unmarshaller 
unmarshaller 
= 
jsonContext.createUnmarshaller(); 
! 
//from 
String 
String 
s 
= 
"{"field":"Value"}"; 
MyClass 
myInstance1 
= 
(MyClass) 
unmarshaller.unmarshal(s); 
MyClass 
myInstance2 
= 
unmarshaller.unmarshal(s, 
MyClass.class); 
! 
//from 
Reader 
unmarshaller.unmarshal(new 
FileReader("file.json")); 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
31 
Proposal 
– 
Unmarshalling 
(Reading) 
public 
void 
unmarshal() 
{ 
! 
Unmarshaller 
unmarshaller 
= 
jsonContext.createUnmarshaller(); 
! 
//from 
JSONP 
JsonParser 
File 
stream 
= 
new 
FileInputStream(“file.json”); 
JsonParser 
jsonParser 
= 
Json.createParser(stream); 
! 
MyClass 
myInstance 
= 
unmarshaller.unmarshal(jsonParser); 
! 
//other 
JSONP 
constructs 
… 
JsonStructure, 
JsonObject, 
JsonArray 
… 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
32 
Proposal 
– 
Unmarshalling 
(Reading) 
public 
void 
unmarshal() 
{ 
! 
Unmarshaller 
u 
= 
jsonContext.createUnmarshaller(); 
! 
//expose 
JSONP 
JsonGenerator 
UnmarshallerJsonGenerator 
generator 
= 
u.getJsonGenerator(); 
generator.write(…); 
generator.write(…); 
… 
MyClass 
myInstance 
= 
(MyClass) 
generator.getResult(); 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
33 
Proposal 
– 
The 
Shortcut 
-­‐ 
Jsonb 
! 
String 
myString 
= 
Jsonb.marshal(myObject); 
! 
MyObject 
object 
= 
Jsonb.unmarshal(someJsonString, 
MyObject.class); 
! 
… 
!
Mapping 
API 
-­‐ 
Proposal 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
34
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
35 
Proposal 
– 
Default 
Mapping 
– 
Primitive 
types 
char 
_char; 
“_char" 
: 
"c", 
String 
_string; 
"_string" 
: 
“string”, 
! 
byte 
_byte; 
"_byte" 
: 
123, 
short 
_short; 
"_short" 
: 
32767, 
int 
_int; 
"_int" 
: 
2147483647, 
long 
_long; 
"_long" 
: 
9223372036854775807, 
float 
_float; 
"_float" 
: 
3.4028235E38, 
double 
_double; 
"_double" 
: 
1.7976931348623157E308, 
! 
boolean 
_boolean; 
"_boolean" 
: 
true, 
Boolean 
_Boolean; 
"_Boolean" 
: 
false, 
Byte 
_Byte; 
“_Byte" 
: 
127, 
Short 
_Short; 
"_Short" 
: 
32767, 
Integer 
_Integer; 
"_Integer" 
: 
2147483647, 
Long 
_Long; 
"_Long" 
: 
9223372036854775807, 
Float 
_Float; 
"_Float" 
: 
3.4028235E38, 
Double 
_Double; 
"_Double" 
: 
1.7976931348623157E308, 
! 
//defaults 
-­‐ 
Jackson: 
"NaN", 
Moxy: 
NaN 
//Genson 
throws 
exception 
… 
Float 
_NaNFloat 
= 
Float.NaN; 
! 
//same 
as 
above 
Double 
_NaNDouble 
= 
Double.NaN; 
BigInteger 
_BigInteger; 
"_BigInteger" 
: 
4611686014132, 
BigDecimal 
_BigDecimal; 
"_BigDecimal" 
: 
850705917302332501249, 
! 
String[] 
_stringArr; 
“_stringArr" 
: 
[ 
"abc", 
"def", 
"ghi" 
], 
int[] 
_intArray; 
"_intArr" 
: 
[ 
123, 
456, 
789 
], 
! 
String[] 
_stringArrSingle; 
"_stringArrSingle" 
: 
[ 
"abc" 
], 
int[] 
_intArrSingle; 
"_intArrSingle" 
: 
[ 
123 
]
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
36 
Proposal 
– 
Default 
Mapping 
– 
Dates 
• Date 
• Calendar 
• JDK 
8 
Date&Time 
API 
! 
• Adapter 
/ 
JsonDe/serializer, 
… 
• JsonFormat 
annotation 
• .useDateFormat(new 
SimpleDateFormat(…)) 
• .setDateFormat(new 
SimpleDateFormat(…))
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
37 
Proposal 
– 
Default 
Mapping 
-­‐ 
Dates 
-­‐ 
JsonAdapter 
public 
class 
DateAdapter 
implements 
JsonAdapter<Date> 
{ 
public 
String 
marshal(Date 
d) 
{…} 
public 
Date 
unmarshal(String 
s) 
{…} 
} 
! 
public 
class 
Parent 
{ 
@JsonJavaTypeAdapter(DateAdapter.class) 
public 
Date 
date; 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
38 
Proposal 
– 
Default 
Mapping 
-­‐ 
Enum 
@JsonEnum 
public 
enum 
Options 
{ 
@JsonEnumValue(“1”) 
OPTION_1, 
@JsonEnumValue(“2”) 
OPTION_2, 
@JsonEnumValue(“3”) 
OPTION_3; 
} 
{ 
“option” 
: 
1 
} 
! 
! 
! 
! 
! 
{ 
“option” 
: 
1 
} 
option 
: 
OPTION_1
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
39 
Proposal 
– 
Null 
value 
handling 
-­‐ 
Default 
public 
String 
longDescription; 
! 
{ 
} 
! 
! 
! 
! 
! 
! 
! 
{ 
} 
longDescription 
: 
null 
(do 
not 
redefine)
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
40 
Proposal 
– 
Null 
value 
handling 
-­‐ 
JsonNillable 
@JsonNillable(true) 
public 
String 
longDescription; 
! 
{ 
“longDescription” 
: 
null 
} 
! 
! 
! 
! 
! 
{ 
“longDescription” 
: 
null 
} 
longDescription 
: 
null
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
41 
Proposal 
– 
Customized 
Mapping 
-­‐ 
Names 
@JsonProperty(“longdesc”); 
public 
String 
longDescription; 
! 
{ 
“longdesc” 
: 
“This 
is 
long 
description”, 
} 
! 
! 
! 
! 
! 
{ 
“longdesc” 
: 
“This 
is 
long 
description”, 
} 
longDescription 
: 
“This 
is 
long 
description”
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
42 
Proposal 
– 
Customized 
Mapping 
-­‐ 
Names 
private 
String 
longDescription; 
! 
@JsonProperty(“long-­‐desc”); 
public 
String 
getLongDescription() 
{ 
return 
longDescription; 
} 
! 
@JsonProperty(“longDesc”); 
public 
void 
setLongDescription(String 
ld) 
{ 
this.longDescription 
= 
ld; 
} 
{ 
“longDesc” 
: 
“This 
is 
long 
description”, 
} 
! 
! 
! 
! 
! 
{ 
“long-­‐desc” 
: 
“This 
is 
long 
description”, 
} 
longDescription 
: 
“This 
is 
long 
description”
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
43 
Proposal 
– 
Customized 
Mapping 
– 
Ignoring 
fields,properties 
@JsonTransient 
public 
String 
longDescription; 
{ 
“longDesc” 
: 
“This 
is 
long 
description”, 
} 
! 
! 
! 
! 
! 
! 
{ 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
44 
Proposal 
– 
Customized 
Mapping 
– 
Ignoring 
fields,properties 
@JsonTransient 
public 
String 
longDescription; 
! 
! 
! 
! 
! 
! 
! 
! 
! 
{ 
} 
longDescription 
: 
“This 
is 
not 
the 
long 
description 
from 
json 
document”
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
45 
Proposal 
– 
Customized 
Mapping 
– 
Ignoring 
fields,properties 
private 
String 
longDescription; 
! 
@JsonTransient 
public 
String 
getLongDescription() 
{ 
return 
longDescription; 
} 
! 
public 
void 
setLongDescription(String 
ld) 
{ 
this.longDescription 
= 
ld; 
} 
{ 
“longDesc” 
: 
“This 
is 
long 
description”, 
} 
! 
! 
! 
! 
! 
{ 
} 
longDescription 
: 
“This 
is 
long 
description”
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
46 
Proposal 
– 
Customized 
Mapping 
– 
Ignoring 
fields,properties 
private 
String 
longDescription; 
! 
public 
String 
getLongDescription() 
{ 
return 
longDescription; 
} 
! 
@JsonTransient 
public 
void 
setLongDescription(String 
ld) 
{ 
this.longDescription 
= 
ld; 
} 
{ 
“longDesc” 
: 
“This 
is 
long 
description” 
} 
! 
! 
! 
! 
! 
{ 
“longDesc” 
: 
“Different 
description” 
} 
longDescription 
: 
“Different 
description”
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
47 
Proposal 
– 
Customized 
Mapping 
– 
Ordering 
@JsonPropertyOrder(“title”, 
“author”) 
public 
class 
Employee 
{ 
public 
String 
author; 
public 
String 
title; 
} 
! 
! 
! 
! 
! 
! 
! 
{ 
“title” 
: 
“Effective 
Java”, 
“author” 
: 
“Joshua 
Bloch” 
} 
Book: 
: 
author 
: 
title
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
48 
Proposal 
– 
Customized 
Mapping 
– 
Access 
@JsonAccessorType(JsonAccessType.FIELD) 
public 
class 
Employee 
{ 
private 
String 
author; 
private 
String 
title; 
} 
! 
NONE 
FIELD 
PUBLIC 
PROTECTED_PUBLIC 
ANY 
… 
?
Book: 
: 
title 
: 
author 
: 
longDescription 
: 
summary 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
49 
Proposal 
– 
Simple 
value 
mapping 
public 
class 
Description 
{ 
private 
String 
longDescription; 
! 
@JsonValue 
public 
String 
getLongDescription() 
{ 
return 
longDescription; 
} 
! 
public 
void 
setLongDescription(String 
ld) 
{ 
this.longDescription 
= 
ld; 
} 
} 
! 
! 
! 
! 
! 
! 
! 
! 
{ 
“title” 
: 
“Title”, 
“author” 
: 
“Author 
Name”, 
“description” 
Description: 
: 
longDescription 
= 
“This 
is 
long 
description” 
: 
“This 
is 
long 
description”, 
“summary” 
: 
“Summary”, 
}
Need 
joke 
to 
cool 
down 
… 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
50
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
@mgrebac 
51
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
http://www.tehnrd.com/ 
52
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
http://www.tehnrd.com/ 
53 
• Hear 
someone 
talking 
about 
how 
cool, 
efficient, 
and 
great 
to 
work 
with 
Jason 
is 
…
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
http://www.tehnrd.com/ 
54 
• Hear 
someone 
talking 
about 
how 
cool, 
efficient, 
and 
great 
to 
work 
with 
Jason 
is 
… 
! 
• … 
and 
then 
realizing 
they 
are 
talking 
about 
JSON!
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
55 
Proposal 
-­‐ 
Inheritance, 
Polymorphism 
@JsonDiscriminatorProperty(“type”) 
public 
abstract 
class 
ContactInfo 
{} 
!! 
public 
class 
Address 
extends 
ContactInfo 
{ 
public 
String 
street; 
} 
!! 
public 
class 
Email 
extends 
ContactInfo 
{ 
public 
String 
email; 
} 
!! 
public 
class 
Phone 
extends 
ContactInfo 
{ 
public 
String 
phoneNumber; 
} 
!
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
56 
Proposal 
-­‐ 
Inheritance, 
Polymorphism 
@JsonDiscriminatorProperty(“type”) 
public 
abstract 
class 
ContactInfo 
{} 
! 
@JsonDiscriminatorValue(“address-­‐type”) 
public 
class 
Address 
extends 
ContactInfo 
{ 
public 
String 
street; 
} 
! 
@JsonDiscriminatorValue(“email-­‐type”) 
public 
class 
Email 
extends 
ContactInfo 
{ 
public 
String 
email; 
} 
! 
@JsonDiscriminatorValue(“phone-­‐type”) 
public 
class 
Phone 
extends 
ContactInfo 
{ 
public 
String 
phoneNumber; 
} 
!
Address 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
56 
Proposal 
-­‐ 
Inheritance, 
Polymorphism 
@JsonDiscriminatorProperty(“type”) 
public 
abstract 
class 
ContactInfo 
{} 
! 
@JsonDiscriminatorValue(“address-­‐type”) 
public 
class 
Address 
extends 
ContactInfo 
{ 
public 
String 
street; 
} 
! 
@JsonDiscriminatorValue(“email-­‐type”) 
public 
class 
Email 
extends 
ContactInfo 
{ 
public 
String 
email; 
} 
! 
@JsonDiscriminatorValue(“phone-­‐type”) 
public 
class 
Phone 
extends 
ContactInfo 
{ 
public 
String 
phoneNumber; 
} 
! 
! 
{ 
“type” 
: 
“address-­‐type”, 
“street” 
: 
“1099 
Lombard 
Street” 
} 
! 
! 
Email 
! 
! 
{ 
“type” 
: 
“email-­‐type”, 
“email” 
: 
“larry.ellison@oracle.com” 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
57 
Proposal 
– 
Inheritance, 
Polymorphism 
supporting 
@JsonSeeAlso( 
{Address.class, 
Phone.class, 
Email.class} 
) 
@JsonDiscriminatorProperty(“type”) 
public 
abstract 
class 
ContactInfo 
{}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
58 
Proposal 
– 
Instantiation 
– 
Factories, 
Constructors 
public 
class 
CreatedClass 
{ 
@JsonCreator 
public 
static 
CreatedClass 
create() 
{ 
return 
new 
CreatedClass(); 
} 
} 
! 
public 
class 
ConstrClass 
{ 
public 
ConstrClass( 
@JsonProperty(“name”) 
name, 
@JsonProperty(“email”) 
email) 
{ 
… 
} 
} 
{ 
“created” 
: 
{ 
}, 
“constructed” 
: 
{ 
“email” 
: 
“larry.ellison@oracle.com”, 
“name” 
: 
“Larry 
Ellison” 
} 
} 
ParentClass 
{ 
// 
by 
CreatedClass.create() 
CreatedClass 
created; 
! 
/* 
by 
new 
ConstrClass( 
“larry.ellison@oracle.com”, 
“Larry 
Ellison” 
) 
*/ 
ConstructedClass 
constructed; 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
59 
Proposal 
– 
Lifecycle 
events 
@JsonPreUnmarshal 
@JsonPostUnmarshal 
! 
@JsonPreMarshal 
@JsonPostMarshal
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
60 
Explore 
mapping 
3rd 
party 
objects 
• Mix-­‐in 
annotations 
(Jackson) 
• External 
metadata 
format 
(MOXy) 
• …
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
61 
Explore 
binding 
JSON 
document 
subset 
-­‐ 
JSONPointer 
? 
{ 
"title": 
"Recent 
Uploads 
tagged 
javaone", 
"link": 
"http://www.flickr.com/photos/tags/javaone/", 
"description": 
"", 
"modified": 
"2014-­‐03-­‐22T16:40:19Z", 
"generator": 
"http://www.flickr.com/", 
"items": 
[ 
{ 
"title": 
"IMG_1377", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332491484/", 
"media": 
{"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T12:33:19-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:19Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:outdoor=0983 
vision:plant=0872" 
}, 
{ 
"title": 
"IMG_1388", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332247843/", 
"media": 
{"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T21:45:56-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:26Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:mountain=0853 
vision:sky=0722" 
}, 
… 
{ 
public 
class 
FlickrExtract 
{ 
! 
@JsonPointer(“/link”) 
public 
String 
linkUrl; 
@JsonPointer(“/items/0/title”) 
public 
String 
firstPictureTitle; 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
62 
Explore 
binding 
JSON 
document 
subset 
-­‐ 
JSONPointer 
? 
{ 
"title": 
"Recent 
Uploads 
tagged 
javaone", 
"link": 
"http://www.flickr.com/photos/tags/javaone/", 
"description": 
"", 
"modified": 
"2014-­‐03-­‐22T16:40:19Z", 
"generator": 
"http://www.flickr.com/", 
"items": 
[ 
{ 
"title": 
"IMG_1377", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332491484/", 
"media": 
{"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T12:33:19-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:19Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:outdoor=0983 
vision:plant=0872" 
}, 
{ 
"title": 
"IMG_1388", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332247843/", 
"media": 
{"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T21:45:56-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:26Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:mountain=0853 
vision:sky=0722" 
}, 
… 
{ 
public 
class 
FlickrExtract 
{ 
! 
@JsonPointer(“/items/0/media”) 
public 
Media 
media; 
! 
} 
! 
public 
class 
Media 
{ 
public 
String 
m; 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
63 
Explore 
binding 
JSON 
document 
subset 
-­‐ 
JSONPath 
? 
{ 
"title": 
"Recent 
Uploads 
tagged 
javaone", 
"link": 
"http://www.flickr.com/photos/tags/javaone/", 
"description": 
"", 
"modified": 
"2014-­‐03-­‐22T16:40:19Z", 
"generator": 
"http://www.flickr.com/", 
"items": 
[ 
{ 
"title": 
"IMG_1377", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332491484/", 
"media": 
{"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T12:33:19-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:19Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:outdoor=0983 
vision:plant=0872" 
}, 
{ 
"title": 
"IMG_1388", 
"link": 
"http://www.flickr.com/photos/soniaauv/13332247843/", 
"media": 
{"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, 
"date_taken": 
"2007-­‐05-­‐07T21:45:56-­‐08:00", 
"description": 
" 
<p>…</p> 
", 
"published": 
"2014-­‐03-­‐22T16:40:26Z", 
"author": 
"nobody@flickr.com 
(S.O.N.I.A. 
ETS)", 
"author_id": 
"117446064@N05", 
"tags": 
"javaone 
preparations 
2007 
vision:mountain=0853 
vision:sky=0722" 
}, 
… 
{ 
public 
class 
FlickrExtract 
{ 
! 
@JsonPath(“$.link”) 
public 
String 
linkUrl; 
@JsonPath(“$.items.*.title”) 
public 
String[] 
pictureTitles; 
! 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Integration 
64
Affected, 
used, 
under 
consideration 
specifications 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
• JSR 
353 
– 
Java 
API 
for 
JSON 
Processing 
(JSON-­‐P) 
• JSR 
339 
– 
Java 
API 
for 
RESTful 
services 
(JAX-­‐RS) 
• JSR 
349 
– 
Bean 
Validation 
(BV) 
• JSR 
??? 
– 
JEP 
198 
– 
Light-­‐Weight 
JSON 
API 
65
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
JAX-­‐RS 
• JAX-­‐RS 
allowed 
to 
standardize 
on 
JSON-­‐Binding 
• Custom 
JSON-­‐Binding 
66
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
JSON-­‐P 
• Already 
covered 
67
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
JPA 
Back-­‐reference 
(Inverse 
reference) 
support 
• Explore 
mapping 
bidirectional 
references 
68 
public 
class 
A 
{ 
@JsonManagedReference 
public 
B 
getB(); 
} 
! 
public 
class 
B 
{ 
@JsonBackReference 
public 
A 
getA(); 
} 
public 
class 
A 
{ 
public 
B 
getB(); 
} 
! 
! 
public 
class 
B 
{ 
@XmlInverseReference(mappedBy=“b”) 
public 
A 
getA(); 
}
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Call 
to 
ACTION! 
• Participate 
as 
an 
observer 
• users@jsonb-­‐spec.java.net 
• Join 
EG 
• https://jcp.org/en/jsr/detail?id=367 
69
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Q 
& 
A 
• Participate 
as 
an 
observer 
• users@jsonb-­‐spec.java.net 
• Join 
EG 
• https://jcp.org/en/jsr/detail?id=367 
70
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Related 
Talk(s) 
• CON5742 
-­‐ 
JSON 
Pointer 
and 
JSON 
Patch: 
Updates 
to 
the 
Java 
API 
for 
JSON 
Processing 
• Kin-­‐Man 
Chung 
• Tuesday, 
September 
30, 
4-­‐5pm, 
Cyril 
Magnin 
II/III 
71
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
Sources, 
References 
• https://jcp.org/en/jsr/detail?id=367 
• http://www.developer.com/lang/jscript/top-­‐7-­‐open-­‐source-­‐json-­‐binding-­‐ 
providers-­‐available-­‐today.html 
• http://goessner.net/articles/JsonPath/ 
• http://eclipselink.org 
72
My 
JSON 
joke 
fell 
flat 
because 
I 
got 
the 
quotes 
wrong. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
– Jeff 
Waugh’s 
tweet 
73
Safe 
Harbor 
Statement 
The 
preceding 
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 
Oracle’s 
products 
remains 
at 
the 
sole 
discretion 
of 
Oracle. 
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
74
Copyright 
© 
2014, 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
75
Java API for JSON Binding - Introduction and update
Java API for JSON Binding - Introduction and update

Mais conteúdo relacionado

Mais procurados

Java EE 6 Adoption in One of the World’s Largest Online Financial Systems
Java EE 6 Adoption in One of the World’s Largest Online Financial SystemsJava EE 6 Adoption in One of the World’s Largest Online Financial Systems
Java EE 6 Adoption in One of the World’s Largest Online Financial SystemsArshal Ameen
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEDown-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEReza Rahman
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7Shekhar Gulati
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot David Delabassee
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchReza Rahman
 
JSF 2.3 Adopt-a-JSR 10 Minute Infodeck
JSF 2.3 Adopt-a-JSR 10 Minute InfodeckJSF 2.3 Adopt-a-JSR 10 Minute Infodeck
JSF 2.3 Adopt-a-JSR 10 Minute InfodeckEdward Burns
 
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckServlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckEdward Burns
 
JSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksJSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksDmitry Kornilov
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375Finally, EE Security API JSR 375
Finally, EE Security API JSR 375Alex Kosowski
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015Edward Burns
 
Java EE 8: On the Horizon
Java EE 8:  On the HorizonJava EE 8:  On the Horizon
Java EE 8: On the HorizonJosh Juneau
 
WebSocket in Enterprise Applications 2015
WebSocket in Enterprise Applications 2015WebSocket in Enterprise Applications 2015
WebSocket in Enterprise Applications 2015Pavel Bucek
 
Is Enterprise Java Still Relevant (JavaOne 2015 session)
Is Enterprise Java Still Relevant (JavaOne 2015 session)Is Enterprise Java Still Relevant (JavaOne 2015 session)
Is Enterprise Java Still Relevant (JavaOne 2015 session)Ian Robinson
 
Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Edward Burns
 

Mais procurados (17)

Java on Azure
Java on AzureJava on Azure
Java on Azure
 
Java EE 6 Adoption in One of the World’s Largest Online Financial Systems
Java EE 6 Adoption in One of the World’s Largest Online Financial SystemsJava EE 6 Adoption in One of the World’s Largest Online Financial Systems
Java EE 6 Adoption in One of the World’s Largest Online Financial Systems
 
Down-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EEDown-to-Earth Microservices with Java EE
Down-to-Earth Microservices with Java EE
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
 
JSF 2.3 Adopt-a-JSR 10 Minute Infodeck
JSF 2.3 Adopt-a-JSR 10 Minute InfodeckJSF 2.3 Adopt-a-JSR 10 Minute Infodeck
JSF 2.3 Adopt-a-JSR 10 Minute Infodeck
 
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute InfodeckServlet 4.0 Adopt-a-JSR 10 Minute Infodeck
Servlet 4.0 Adopt-a-JSR 10 Minute Infodeck
 
JSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworksJSONB introduction and comparison with other frameworks
JSONB introduction and comparison with other frameworks
 
JavaCro'15 - HTTP2 Comes to Java! - David Delabassee
JavaCro'15 - HTTP2 Comes to Java! - David DelabasseeJavaCro'15 - HTTP2 Comes to Java! - David Delabassee
JavaCro'15 - HTTP2 Comes to Java! - David Delabassee
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375Finally, EE Security API JSR 375
Finally, EE Security API JSR 375
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
 
Java EE 8: On the Horizon
Java EE 8:  On the HorizonJava EE 8:  On the Horizon
Java EE 8: On the Horizon
 
WebSocket in Enterprise Applications 2015
WebSocket in Enterprise Applications 2015WebSocket in Enterprise Applications 2015
WebSocket in Enterprise Applications 2015
 
Is Enterprise Java Still Relevant (JavaOne 2015 session)
Is Enterprise Java Still Relevant (JavaOne 2015 session)Is Enterprise Java Still Relevant (JavaOne 2015 session)
Is Enterprise Java Still Relevant (JavaOne 2015 session)
 
JavaCro'15 - Java Cloud - Marin Tadić
JavaCro'15 - Java Cloud - Marin TadićJavaCro'15 - Java Cloud - Marin Tadić
JavaCro'15 - Java Cloud - Marin Tadić
 
Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015
 

Semelhante a Java API for JSON Binding - Introduction and update

What's new in the Java API for JSON Binding
What's new in the Java API for JSON BindingWhat's new in the Java API for JSON Binding
What's new in the Java API for JSON BindingDmitry Kornilov
 
What's coming in Java EE 8
What's coming in Java EE 8What's coming in Java EE 8
What's coming in Java EE 8David Delabassee
 
Configuration for Java EE and the Cloud
Configuration for Java EE and the CloudConfiguration for Java EE and the Cloud
Configuration for Java EE and the CloudDmitry Kornilov
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshotJava EE 8 - An instant snapshot
Java EE 8 - An instant snapshotDavid Delabassee
 
What’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON BindingWhat’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON BindingDmitry Kornilov
 
Configuration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaConfiguration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaDmitry Kornilov
 
What's Coming in Java EE 8
What's Coming in Java EE 8What's Coming in Java EE 8
What's Coming in Java EE 8PT.JUG
 
Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)Dmitry Kornilov
 
JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?Edward Burns
 
JavaOne 2014 Java EE 8 Booth Slides
JavaOne 2014 Java EE 8 Booth SlidesJavaOne 2014 Java EE 8 Booth Slides
JavaOne 2014 Java EE 8 Booth SlidesEdward Burns
 
Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)Logico
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)David Delabassee
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! David Delabassee
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersBruno Borges
 
Construindo aplicações com HTML5, WebSockets, e Java EE 7
Construindo aplicações com HTML5, WebSockets, e Java EE 7Construindo aplicações com HTML5, WebSockets, e Java EE 7
Construindo aplicações com HTML5, WebSockets, e Java EE 7Bruno Borges
 
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014David Delabassee
 
Oracle JET: Enterprise-Ready JavaScript Toolkit
Oracle JET: Enterprise-Ready JavaScript ToolkitOracle JET: Enterprise-Ready JavaScript Toolkit
Oracle JET: Enterprise-Ready JavaScript ToolkitGeertjan Wielenga
 

Semelhante a Java API for JSON Binding - Introduction and update (20)

What's new in the Java API for JSON Binding
What's new in the Java API for JSON BindingWhat's new in the Java API for JSON Binding
What's new in the Java API for JSON Binding
 
What's coming in Java EE 8
What's coming in Java EE 8What's coming in Java EE 8
What's coming in Java EE 8
 
Configuration for Java EE and the Cloud
Configuration for Java EE and the CloudConfiguration for Java EE and the Cloud
Configuration for Java EE and the Cloud
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshotJava EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
 
JSON-B for CZJUG
JSON-B for CZJUGJSON-B for CZJUG
JSON-B for CZJUG
 
What’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON BindingWhat’s new in JSR 367 Java API for JSON Binding
What’s new in JSR 367 Java API for JSON Binding
 
Java EE for the Cloud
Java EE for the CloudJava EE for the Cloud
Java EE for the Cloud
 
Configuration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaConfiguration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and Tamaya
 
What's Coming in Java EE 8
What's Coming in Java EE 8What's Coming in Java EE 8
What's Coming in Java EE 8
 
Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)Adopt-a-JSR session (JSON-B/P)
Adopt-a-JSR session (JSON-B/P)
 
JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?
 
JavaCro'15 - Java EE 8 - An instant snapshot - David Delabassee
JavaCro'15 - Java EE 8 - An instant snapshot - David DelabasseeJavaCro'15 - Java EE 8 - An instant snapshot - David Delabassee
JavaCro'15 - Java EE 8 - An instant snapshot - David Delabassee
 
JavaOne 2014 Java EE 8 Booth Slides
JavaOne 2014 Java EE 8 Booth SlidesJavaOne 2014 Java EE 8 Booth Slides
JavaOne 2014 Java EE 8 Booth Slides
 
Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)Java EE 8 Overview (Japanese)
Java EE 8 Overview (Japanese)
 
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
 
Construindo aplicações com HTML5, WebSockets, e Java EE 7
Construindo aplicações com HTML5, WebSockets, e Java EE 7Construindo aplicações com HTML5, WebSockets, e Java EE 7
Construindo aplicações com HTML5, WebSockets, e Java EE 7
 
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
 
Oracle JET: Enterprise-Ready JavaScript Toolkit
Oracle JET: Enterprise-Ready JavaScript ToolkitOracle JET: Enterprise-Ready JavaScript Toolkit
Oracle JET: Enterprise-Ready JavaScript Toolkit
 

Último

AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAlluxio, Inc.
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024Shane Coughlan
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersEmilyJiang23
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityamy56318795
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024vaibhav130304
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)Max Lee
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabbereGrabber
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems ApproachNeo4j
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionWave PLM
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Gáspár Nagy
 

Último (20)

AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 

Java API for JSON Binding - Introduction and update

  • 1.
  • 2.
  • 3. Java API for JSON Binding Introduction and update Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Martin Grebac JSON-­‐B Spec lead Development Manager TopLink & Metro Oracle Accept: application/json
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Program Agenda Introduction JSR; Status; Next Steps API Integration Q & A 1 2 3 4 5 4
  • 5. Safe Harbor Statement 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 Oracle’s products remains at the sole discretion of Oracle. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 5
  • 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Introduction 6
  • 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 7
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 8 public class Employee { public int id; public String firstName; public String lastName; public String email; …. }
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 9 ! Employee e = new Employee(); e.id = 1111; e.firstName = “Martin”; e.lastName = “Grebac”; e.email = “martin.grebac@oracle.com”;
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 9 ! Employee e = new Employee(); e.id = 1111; e.firstName = “Martin”; e.lastName = “Grebac”; e.email = “martin.grebac@oracle.com”;
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 9 ! Employee e = new Employee(); e.id = 1111; e.firstName = “Martin”; e.lastName = “Grebac”; e.email = “martin.grebac@oracle.com”; { "id": 1111, "firstName" : "Martin", "lastName" : "Grebac", "email": "martin.grebac@oracle.com" }
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. What is JSON Binding? • Converting Java objects to & from JSON 10 JAX-­‐RS Objects XML JSON JAXB JSON-­‐B
  • 13. Standardizing current technology Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Many mature or emerging JSON binding frameworks out there 11 ! • Jackson • Genson • Gson • EclipseLink MOXy • Fleece • JSON-­‐lib • Flexjson • Json-­‐io • JSONiJ • Xstream • …
  • 14. Standardizing current technology Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Many mature or emerging JSON binding frameworks out there 11 ! • Jackson • Genson • Gson • EclipseLink MOXy • Fleece • JSON-­‐lib • Flexjson • Json-­‐io • JSONiJ • Xstream • …
  • 15. Standardizing current technology Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • Many mature or emerging JSON binding frameworks out there 11 ! • Jackson • Genson • Gson • EclipseLink MOXy • Fleece • JSON-­‐lib • Flexjson • Json-­‐io • JSONiJ • Xstream • …
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Standard API -­‐ Advantages • Switch providers easily • Implementation compete on common ground (performance or feature-­‐ wise) • Loss of implementation/participant is no issue for standard • More people able to help on forums or stackoverflow ;) even those not using your implementation of choice 12
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 13
  • 18. JSR; Status; Next Steps Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 14
  • 19. JSR 367 – Java API for JSON Binding (JSON-­‐B) Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Status • JSR Proposal Submitted • https://www.jcp.org/en/jsr/detail?id=367 15
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 16 Proposal – In short • API with similar feel to JAXB ! • javax.json.bind ! • Spec project: http://jsonb-­‐spec.java.net (stay tuned) ! • RI project: http://eclipselink.org ! • Standalone, looking for Java EE 8
  • 21. JSR 367 – Java API for JSON Binding (JSON-­‐B) Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Status • JSR Proposal Submitted • https://www.jcp.org/en/jsr/detail?id=367 • JSR Review period finished 08/Sep/2014 • JSR Review ballot finished 22/Sep/2014 17
  • 22. JSR 367 – Java API for JSON Binding (JSON-­‐B) Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Status • JSR Proposal Submitted • https://www.jcp.org/en/jsr/detail?id=367 • JSR Review period finished 08/Sep/2014 • JSR Review ballot finished 22/Sep/2014 17
  • 23. JSR 367 – Java API for JSON Binding (JSON-­‐B) Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Status • JSR Proposal Submitted • https://www.jcp.org/en/jsr/detail?id=367 • JSR Review period finished 08/Sep/2014 • JSR Review ballot finished 22/Sep/2014 ! • Accepting EG nominations: • https://www.jcp.org/en/jsr/egnom?id=367 18
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Next Steps JSR 367 – Java API for JSON Binding (JSON-­‐B) 19 • Form Expert Group • Early Draft
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Next Steps JSR 367 – Java API for JSON Binding (JSON-­‐B) 20 • Form Expert Group • Early Draft
  • 26. API – Goals, Non-­‐goals -­‐ Proposal Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 21
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 22 Proposal – Goals • Binding JSON (RFC 7159) documents • Maintain consistency with JAXB API and other Java SE & EE APIs where applicable • Define default object-­‐JSON mapping • Annotation based customizations for object-­‐JSON mapping • Support binding using JSON-­‐P APIs ! • Explore mapping subset of Json documents (Json Pointer) • Explore options to map 3rd party objects • Explore bi-­‐directional mappings
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 23 Proposal – Non-­‐goals • JSON Schema • Tooltime • Roundtrip • JEP 198 -­‐ Lightweight JSON API
  • 29. Runtime API -­‐ Proposal Anything subject to change anytime Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 24
  • 30. Proposal – Runtime Initialization – Default Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 25 import javax.json.bind.*; ! public void init() { ! JsonContext context = JsonContext.newInstance(); ! // JsonContext context = // JsonContext.newInstance(“com.provider.ProviderFactory"); ! Marshaller marshaller = context.createMarshaller(); ! Unmarshaller unmarshaller = context.createUnmarshaller; ! }
  • 31. Proposal – Runtime Initialization – Context Builder Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 26 public void init() { ! JsonContext context = new JsonContextBuilder() .setScope (MyClass.class, …) .excludeField(“field”, MyClass.class) .addFilter(myContextFilterImplementation) .build(); }
  • 32. Proposal – Runtime Initialization – Fluent Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 27 public void init() { ! JsonContext context = JsonContext.newInstance(); ! Marshaller marshaller = context.createMarshaller() .setProperty(Marshaller.PROPERTY) .setPrettyPrinting(true); ! Unmarshaller unmarshaller = context.createUnmarshaller() .setCloseStreams(true); ! }
  • 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 28 Proposal – Marshalling (Writing) public void marshal() { !! Marshaller marshaller = jsonContext.createMarshaller(); ! //to String String string = marshaller.marshal(myObject); ! //to Writer marshaller.marshal(myObject, new FileWriter(“file.json”)); !! }
  • 34. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 29 Proposal – Marshalling (Writing) public void marshal() { ! Marshaller marshaller = jsonContext.createMarshaller(); ! //to JSONP JsonGenerator FileWriter writer = new FileWriter(“file.json”); JsonGenerator generator = Json.createGenerator(writer); marshaller.marshal(myObject, generator); ! //expose as JSONP JsonParser JsonParser parser = marshaller.getJsonParser(myObject); ! //other JSONP constructs JsonObjectBuilder, … ! }
  • 35. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 30 Proposal – Unmarshalling (Reading) public void unmarshal() { ! Unmarshaller unmarshaller = jsonContext.createUnmarshaller(); ! //from String String s = "{"field":"Value"}"; MyClass myInstance1 = (MyClass) unmarshaller.unmarshal(s); MyClass myInstance2 = unmarshaller.unmarshal(s, MyClass.class); ! //from Reader unmarshaller.unmarshal(new FileReader("file.json")); ! }
  • 36. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 31 Proposal – Unmarshalling (Reading) public void unmarshal() { ! Unmarshaller unmarshaller = jsonContext.createUnmarshaller(); ! //from JSONP JsonParser File stream = new FileInputStream(“file.json”); JsonParser jsonParser = Json.createParser(stream); ! MyClass myInstance = unmarshaller.unmarshal(jsonParser); ! //other JSONP constructs … JsonStructure, JsonObject, JsonArray … ! }
  • 37. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 32 Proposal – Unmarshalling (Reading) public void unmarshal() { ! Unmarshaller u = jsonContext.createUnmarshaller(); ! //expose JSONP JsonGenerator UnmarshallerJsonGenerator generator = u.getJsonGenerator(); generator.write(…); generator.write(…); … MyClass myInstance = (MyClass) generator.getResult(); ! }
  • 38. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 33 Proposal – The Shortcut -­‐ Jsonb ! String myString = Jsonb.marshal(myObject); ! MyObject object = Jsonb.unmarshal(someJsonString, MyObject.class); ! … !
  • 39. Mapping API -­‐ Proposal Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 34
  • 40. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 35 Proposal – Default Mapping – Primitive types char _char; “_char" : "c", String _string; "_string" : “string”, ! byte _byte; "_byte" : 123, short _short; "_short" : 32767, int _int; "_int" : 2147483647, long _long; "_long" : 9223372036854775807, float _float; "_float" : 3.4028235E38, double _double; "_double" : 1.7976931348623157E308, ! boolean _boolean; "_boolean" : true, Boolean _Boolean; "_Boolean" : false, Byte _Byte; “_Byte" : 127, Short _Short; "_Short" : 32767, Integer _Integer; "_Integer" : 2147483647, Long _Long; "_Long" : 9223372036854775807, Float _Float; "_Float" : 3.4028235E38, Double _Double; "_Double" : 1.7976931348623157E308, ! //defaults -­‐ Jackson: "NaN", Moxy: NaN //Genson throws exception … Float _NaNFloat = Float.NaN; ! //same as above Double _NaNDouble = Double.NaN; BigInteger _BigInteger; "_BigInteger" : 4611686014132, BigDecimal _BigDecimal; "_BigDecimal" : 850705917302332501249, ! String[] _stringArr; “_stringArr" : [ "abc", "def", "ghi" ], int[] _intArray; "_intArr" : [ 123, 456, 789 ], ! String[] _stringArrSingle; "_stringArrSingle" : [ "abc" ], int[] _intArrSingle; "_intArrSingle" : [ 123 ]
  • 41. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 36 Proposal – Default Mapping – Dates • Date • Calendar • JDK 8 Date&Time API ! • Adapter / JsonDe/serializer, … • JsonFormat annotation • .useDateFormat(new SimpleDateFormat(…)) • .setDateFormat(new SimpleDateFormat(…))
  • 42. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 37 Proposal – Default Mapping -­‐ Dates -­‐ JsonAdapter public class DateAdapter implements JsonAdapter<Date> { public String marshal(Date d) {…} public Date unmarshal(String s) {…} } ! public class Parent { @JsonJavaTypeAdapter(DateAdapter.class) public Date date; }
  • 43. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 38 Proposal – Default Mapping -­‐ Enum @JsonEnum public enum Options { @JsonEnumValue(“1”) OPTION_1, @JsonEnumValue(“2”) OPTION_2, @JsonEnumValue(“3”) OPTION_3; } { “option” : 1 } ! ! ! ! ! { “option” : 1 } option : OPTION_1
  • 44. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 39 Proposal – Null value handling -­‐ Default public String longDescription; ! { } ! ! ! ! ! ! ! { } longDescription : null (do not redefine)
  • 45. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 40 Proposal – Null value handling -­‐ JsonNillable @JsonNillable(true) public String longDescription; ! { “longDescription” : null } ! ! ! ! ! { “longDescription” : null } longDescription : null
  • 46. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 41 Proposal – Customized Mapping -­‐ Names @JsonProperty(“longdesc”); public String longDescription; ! { “longdesc” : “This is long description”, } ! ! ! ! ! { “longdesc” : “This is long description”, } longDescription : “This is long description”
  • 47. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 42 Proposal – Customized Mapping -­‐ Names private String longDescription; ! @JsonProperty(“long-­‐desc”); public String getLongDescription() { return longDescription; } ! @JsonProperty(“longDesc”); public void setLongDescription(String ld) { this.longDescription = ld; } { “longDesc” : “This is long description”, } ! ! ! ! ! { “long-­‐desc” : “This is long description”, } longDescription : “This is long description”
  • 48. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 43 Proposal – Customized Mapping – Ignoring fields,properties @JsonTransient public String longDescription; { “longDesc” : “This is long description”, } ! ! ! ! ! ! { }
  • 49. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 44 Proposal – Customized Mapping – Ignoring fields,properties @JsonTransient public String longDescription; ! ! ! ! ! ! ! ! ! { } longDescription : “This is not the long description from json document”
  • 50. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 45 Proposal – Customized Mapping – Ignoring fields,properties private String longDescription; ! @JsonTransient public String getLongDescription() { return longDescription; } ! public void setLongDescription(String ld) { this.longDescription = ld; } { “longDesc” : “This is long description”, } ! ! ! ! ! { } longDescription : “This is long description”
  • 51. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 46 Proposal – Customized Mapping – Ignoring fields,properties private String longDescription; ! public String getLongDescription() { return longDescription; } ! @JsonTransient public void setLongDescription(String ld) { this.longDescription = ld; } { “longDesc” : “This is long description” } ! ! ! ! ! { “longDesc” : “Different description” } longDescription : “Different description”
  • 52. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 47 Proposal – Customized Mapping – Ordering @JsonPropertyOrder(“title”, “author”) public class Employee { public String author; public String title; } ! ! ! ! ! ! ! { “title” : “Effective Java”, “author” : “Joshua Bloch” } Book: : author : title
  • 53. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 48 Proposal – Customized Mapping – Access @JsonAccessorType(JsonAccessType.FIELD) public class Employee { private String author; private String title; } ! NONE FIELD PUBLIC PROTECTED_PUBLIC ANY … ?
  • 54. Book: : title : author : longDescription : summary Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 49 Proposal – Simple value mapping public class Description { private String longDescription; ! @JsonValue public String getLongDescription() { return longDescription; } ! public void setLongDescription(String ld) { this.longDescription = ld; } } ! ! ! ! ! ! ! ! { “title” : “Title”, “author” : “Author Name”, “description” Description: : longDescription = “This is long description” : “This is long description”, “summary” : “Summary”, }
  • 55. Need joke to cool down … Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 50
  • 56. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. @mgrebac 51
  • 57. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. http://www.tehnrd.com/ 52
  • 58. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. http://www.tehnrd.com/ 53 • Hear someone talking about how cool, efficient, and great to work with Jason is …
  • 59. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. http://www.tehnrd.com/ 54 • Hear someone talking about how cool, efficient, and great to work with Jason is … ! • … and then realizing they are talking about JSON!
  • 60. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 55 Proposal -­‐ Inheritance, Polymorphism @JsonDiscriminatorProperty(“type”) public abstract class ContactInfo {} !! public class Address extends ContactInfo { public String street; } !! public class Email extends ContactInfo { public String email; } !! public class Phone extends ContactInfo { public String phoneNumber; } !
  • 61. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 56 Proposal -­‐ Inheritance, Polymorphism @JsonDiscriminatorProperty(“type”) public abstract class ContactInfo {} ! @JsonDiscriminatorValue(“address-­‐type”) public class Address extends ContactInfo { public String street; } ! @JsonDiscriminatorValue(“email-­‐type”) public class Email extends ContactInfo { public String email; } ! @JsonDiscriminatorValue(“phone-­‐type”) public class Phone extends ContactInfo { public String phoneNumber; } !
  • 62. Address Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 56 Proposal -­‐ Inheritance, Polymorphism @JsonDiscriminatorProperty(“type”) public abstract class ContactInfo {} ! @JsonDiscriminatorValue(“address-­‐type”) public class Address extends ContactInfo { public String street; } ! @JsonDiscriminatorValue(“email-­‐type”) public class Email extends ContactInfo { public String email; } ! @JsonDiscriminatorValue(“phone-­‐type”) public class Phone extends ContactInfo { public String phoneNumber; } ! ! { “type” : “address-­‐type”, “street” : “1099 Lombard Street” } ! ! Email ! ! { “type” : “email-­‐type”, “email” : “larry.ellison@oracle.com” }
  • 63. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 57 Proposal – Inheritance, Polymorphism supporting @JsonSeeAlso( {Address.class, Phone.class, Email.class} ) @JsonDiscriminatorProperty(“type”) public abstract class ContactInfo {}
  • 64. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 58 Proposal – Instantiation – Factories, Constructors public class CreatedClass { @JsonCreator public static CreatedClass create() { return new CreatedClass(); } } ! public class ConstrClass { public ConstrClass( @JsonProperty(“name”) name, @JsonProperty(“email”) email) { … } } { “created” : { }, “constructed” : { “email” : “larry.ellison@oracle.com”, “name” : “Larry Ellison” } } ParentClass { // by CreatedClass.create() CreatedClass created; ! /* by new ConstrClass( “larry.ellison@oracle.com”, “Larry Ellison” ) */ ConstructedClass constructed; }
  • 65. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 59 Proposal – Lifecycle events @JsonPreUnmarshal @JsonPostUnmarshal ! @JsonPreMarshal @JsonPostMarshal
  • 66. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 60 Explore mapping 3rd party objects • Mix-­‐in annotations (Jackson) • External metadata format (MOXy) • …
  • 67. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 61 Explore binding JSON document subset -­‐ JSONPointer ? { "title": "Recent Uploads tagged javaone", "link": "http://www.flickr.com/photos/tags/javaone/", "description": "", "modified": "2014-­‐03-­‐22T16:40:19Z", "generator": "http://www.flickr.com/", "items": [ { "title": "IMG_1377", "link": "http://www.flickr.com/photos/soniaauv/13332491484/", "media": {"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, "date_taken": "2007-­‐05-­‐07T12:33:19-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:19Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:outdoor=0983 vision:plant=0872" }, { "title": "IMG_1388", "link": "http://www.flickr.com/photos/soniaauv/13332247843/", "media": {"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, "date_taken": "2007-­‐05-­‐07T21:45:56-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:26Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:mountain=0853 vision:sky=0722" }, … { public class FlickrExtract { ! @JsonPointer(“/link”) public String linkUrl; @JsonPointer(“/items/0/title”) public String firstPictureTitle; ! }
  • 68. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 62 Explore binding JSON document subset -­‐ JSONPointer ? { "title": "Recent Uploads tagged javaone", "link": "http://www.flickr.com/photos/tags/javaone/", "description": "", "modified": "2014-­‐03-­‐22T16:40:19Z", "generator": "http://www.flickr.com/", "items": [ { "title": "IMG_1377", "link": "http://www.flickr.com/photos/soniaauv/13332491484/", "media": {"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, "date_taken": "2007-­‐05-­‐07T12:33:19-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:19Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:outdoor=0983 vision:plant=0872" }, { "title": "IMG_1388", "link": "http://www.flickr.com/photos/soniaauv/13332247843/", "media": {"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, "date_taken": "2007-­‐05-­‐07T21:45:56-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:26Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:mountain=0853 vision:sky=0722" }, … { public class FlickrExtract { ! @JsonPointer(“/items/0/media”) public Media media; ! } ! public class Media { public String m; }
  • 69. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 63 Explore binding JSON document subset -­‐ JSONPath ? { "title": "Recent Uploads tagged javaone", "link": "http://www.flickr.com/photos/tags/javaone/", "description": "", "modified": "2014-­‐03-­‐22T16:40:19Z", "generator": "http://www.flickr.com/", "items": [ { "title": "IMG_1377", "link": "http://www.flickr.com/photos/soniaauv/13332491484/", "media": {"m":"http://farm4.staticflickr.com/3788/13332491484_a96c2599e8_m.jpg"}, "date_taken": "2007-­‐05-­‐07T12:33:19-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:19Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:outdoor=0983 vision:plant=0872" }, { "title": "IMG_1388", "link": "http://www.flickr.com/photos/soniaauv/13332247843/", "media": {"m":"http://farm3.staticflickr.com/2824/13332247843_f5805b59fd_m.jpg"}, "date_taken": "2007-­‐05-­‐07T21:45:56-­‐08:00", "description": " <p>…</p> ", "published": "2014-­‐03-­‐22T16:40:26Z", "author": "nobody@flickr.com (S.O.N.I.A. ETS)", "author_id": "117446064@N05", "tags": "javaone preparations 2007 vision:mountain=0853 vision:sky=0722" }, … { public class FlickrExtract { ! @JsonPath(“$.link”) public String linkUrl; @JsonPath(“$.items.*.title”) public String[] pictureTitles; ! }
  • 70. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Integration 64
  • 71. Affected, used, under consideration specifications Copyright © 2014, Oracle and/or its affiliates. All rights reserved. • JSR 353 – Java API for JSON Processing (JSON-­‐P) • JSR 339 – Java API for RESTful services (JAX-­‐RS) • JSR 349 – Bean Validation (BV) • JSR ??? – JEP 198 – Light-­‐Weight JSON API 65
  • 72. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. JAX-­‐RS • JAX-­‐RS allowed to standardize on JSON-­‐Binding • Custom JSON-­‐Binding 66
  • 73. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. JSON-­‐P • Already covered 67
  • 74. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. JPA Back-­‐reference (Inverse reference) support • Explore mapping bidirectional references 68 public class A { @JsonManagedReference public B getB(); } ! public class B { @JsonBackReference public A getA(); } public class A { public B getB(); } ! ! public class B { @XmlInverseReference(mappedBy=“b”) public A getA(); }
  • 75. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Call to ACTION! • Participate as an observer • users@jsonb-­‐spec.java.net • Join EG • https://jcp.org/en/jsr/detail?id=367 69
  • 76. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Q & A • Participate as an observer • users@jsonb-­‐spec.java.net • Join EG • https://jcp.org/en/jsr/detail?id=367 70
  • 77. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Related Talk(s) • CON5742 -­‐ JSON Pointer and JSON Patch: Updates to the Java API for JSON Processing • Kin-­‐Man Chung • Tuesday, September 30, 4-­‐5pm, Cyril Magnin II/III 71
  • 78. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Sources, References • https://jcp.org/en/jsr/detail?id=367 • http://www.developer.com/lang/jscript/top-­‐7-­‐open-­‐source-­‐json-­‐binding-­‐ providers-­‐available-­‐today.html • http://goessner.net/articles/JsonPath/ • http://eclipselink.org 72
  • 79. My JSON joke fell flat because I got the quotes wrong. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. – Jeff Waugh’s tweet 73
  • 80. Safe Harbor Statement The preceding 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 Oracle’s products remains at the sole discretion of Oracle. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 74
  • 81. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 75