-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetting-started.html
More file actions
238 lines (217 loc) · 11.3 KB
/
getting-started.html
File metadata and controls
238 lines (217 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!doctype html>
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><html lang="en" class="no-js"> <![endif]-->
<html lang="en">
<head>
<title>JSON Binding (JSON-B) - Getting started</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="Java API for JSON Binding (JSON-B) Getting Started">
<meta name="author" content="Ehsan Zaery Moghaddam, Dmitry Kornilov">
<link rel="apple-touch-icon" sizes="57x57" href="/images/favico/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/images/favico/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/images/favico/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/images/favico/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/images/favico/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/images/favico/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/images/favico/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/images/favico/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/images/favico/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/images/favico/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favico/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/images/favico/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favico/favicon-16x16.png">
<link rel="manifest" href="/images/favico/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/images/favico/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- Bootstrap CSS -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Font Awesome CSS -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<!-- Highlight JS-->
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/default.min.css">
<link rel="stylesheet" type="text/css" href="styles/hjs-github-theme.css" media="screen">
<link href="style.css" rel="stylesheet"/>
<!--[if IE 8]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<!-- Start Navigation bar-->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">
{ "JSON" : "B" }
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Documentation <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Getting started</a></li>
<li><a href="users-guide.html">Users guide</a></li>
<li><a href="javadocs.html">JavaDocs</a></li>
</ul>
</li>
<li>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Contribute <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="mailing-lists.html">Mailing Lists</a></li>
<li><a href="https://www.jcp.org/en/jsr/detail?id=367" target="_blank">JSR 367 Page</a></li>
<li><a href="https://java.net/jira/browse/JSONB_SPEC/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel" target="_blank">Issue tracking</a></li>
<li><a href="contributors.html">Contributors</a></li>
</ul>
</li>
<li><a href="download.html">Download</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- End Navigation bar-->
<!-- Start General Heading -->
<div class="container-fluid" id="general-header-section">
<div class="row">
<div class="col-lg-11 col-sm-10">
<h3>
<span>{ "Getting" : "started" }</span>
</h3>
</div>
<div class="col-lg-1 col-sm-2 text-center general-header-logo">
<img src="jsonb-logo.png"/>
</div>
</div>
</div>
<!-- End General Heading-->
<!-- Start Download -->
<div class="container content-section">
<div class="row">
<div class="col-lg-12 text-left">
<h3>Download</h3>
<p>
You can download the latest version of JSON-B RI manually from
<a href="https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/persistence/jsonb-ri/1.0-SNAPSHOT">Version 1.0-SNAPSHOT</a>
or add the following dependency to your pom if you use Maven:
</p>
<pre><code class="xml"><dependency>
<groupId><b>org.eclipse.persistence</b></groupId>
<artifactId><b>jsonb-ri</b></artifactId>
<version><b>1.0-SNAPSHOT</b></version>
</dependency></code></pre>
</div>
</div>
</div>
<!-- End Download -->
<!-- Start Mapping an Object-->
<div class="container content-section">
<div class="row">
<div class="col-lg-12 text-left">
<h3>Mapping an object</h3>
<p>
The main JSON-B entry point is <code>Jsonb</code> class. It provides all necessary methods to serialize and
deserialize Java objects. <code>Jsonb</code> instances are thread safe. They can be cached and reused.
</p>
<pre><code class="java">public class Dog {
public String name;
public int age;
public bool bitable;
}
// Create a dog instance
Dog dog = new Dog();
dog.name = "Falco";
dog.age = 4;
dog.biteable = false;
// Create Jsonb and serialize
Jsonb jsonb = JsonbBuilder.create();
String result = jsonb.toJson(dog);
// Deserialize back
dog = jsonb.fromJson("{name:\"Falco\",age:4,bitable:false}", Dog.class);</code></pre>
</div>
</div>
</div>
<!-- End Mapping an Object-->
<!-- Start Mapping a collection -->
<div class="container content-section">
<div class="row">
<div class="col-lg-12 text-left">
<h3>Mapping a collection</h3>
<p>
JSON-B supports collections and generic collections handling. For proper deserialization the runtime
type of resulting object needs to be passed to JSON-B during deserialization. It can be done a way
shown below.
</p>
<pre><code class="java">// List of dogs
List<Dog> dogs = new ArrayList<>();
dogs.add(falco);
dogs.add(cassidy);
// Create Jsonb and serialize
Jsonb jsonb = JsonbBuilder.create();
String result = jsonb.toJson(dogs);
// Deserialize back
dogs = jsonb.fromJson(result, new ArrayList<Dog>(){}.getClass());</code></pre>
</div>
</div>
</div>
<!-- End Mapping a collection -->
<!-- Start Customized Mapping -->
<div class="container content-section">
<div class="row">
<div class="col-lg-12 text-left">
<h3>Customized mapping</h3>
<p>
Your mappings can be customized in many different ways. You can use JSON-B annotations for compile
time customizations and <code>JsonbConfig</code> class for runtime customizations. The sample below
shows a creation of custom configuration serializing null values (by default class properties with
null values are skipped).
</p>
<pre><code class="java">// Create custom configuration
JsonbConfig nillableConfig = new JsonbConfig().withNullValues(true);
// Create Jsonb with custom configuration
Jsonb jsonb = JsonbBuilder.create(nillableConfig);
// Use it!
String result = jsonb.toJson(pojo);</code></pre>
</div>
</div>
</div>
<!-- End Customized Mapping -->
<!-- Start footer section-->
<div class="container-fluid" id="footer-section">
<div class="row">
<div class="col-lg-12">
<p>Copyright © 2016 <a href="https://www.oracle.com" target="_blank">Oracle</a> Corporation. All Rights Reserved.</p>
</div>
</div>
</div>
<!-- End footer section-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.nicescroll/3.6.8-fix/jquery.nicescroll.min.js"></script>
<script>
$(document).ready(
function() {
$("html").niceScroll({
scrollSpeed: 30,
smoothscroll: true,
mousescrollstep: 70
});
}
);
</script>
</body>
</html>