Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit dd36a36

Browse files
author
Adam Lindenthal
committed
JSONB integration
Change-Id: Ib3bbf3c625a3bd06799ea798828b0f8d19c3c4cf
1 parent 1f46147 commit dd36a36

File tree

96 files changed

+1326
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1326
-7
lines changed

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@
291291
<artifactId>jersey-media-json-processing</artifactId>
292292
<version>${project.version}</version>
293293
</dependency>
294+
<dependency>
295+
<groupId>org.glassfish.jersey.media</groupId>
296+
<artifactId>jersey-media-json-binding</artifactId>
297+
<version>${project.version}</version>
298+
</dependency>
294299
<dependency>
295300
<groupId>org.glassfish.jersey.media</groupId>
296301
<artifactId>jersey-media-kryo</artifactId>

bundles/jaxrs-ri/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
<artifactId>jersey-media-jaxb</artifactId>
9191
<version>${project.version}</version>
9292
</dependency>
93+
<dependency>
94+
<groupId>org.glassfish.jersey.media</groupId>
95+
<artifactId>jersey-media-json-binding</artifactId>
96+
<version>${project.version}</version>
97+
</dependency>
9398
<dependency>
9499
<groupId>org.glassfish.jersey.core</groupId>
95100
<artifactId>jersey-client</artifactId>

examples/json-binding/README.MD

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!--
2+
3+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
5+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
6+
7+
The contents of this file are subject to the terms of either the GNU
8+
General Public License Version 2 only ("GPL") or the Common Development
9+
and Distribution License("CDDL") (collectively, the "License"). You
10+
may not use this file except in compliance with the License. You can
11+
obtain a copy of the License at
12+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
13+
or packager/legal/LICENSE.txt. See the License for the specific
14+
language governing permissions and limitations under the License.
15+
16+
When distributing the software, include this License Header Notice in each
17+
file and include the License file at packager/legal/LICENSE.txt.
18+
19+
GPL Classpath Exception:
20+
Oracle designates this particular file as subject to the "Classpath"
21+
exception as provided by Oracle in the GPL Version 2 section of the License
22+
file that accompanied this code.
23+
24+
Modifications:
25+
If applicable, add the following below the License Header, with the fields
26+
enclosed by brackets [] replaced by your own identifying information:
27+
"Portions Copyright [year] [name of copyright owner]"
28+
29+
Contributor(s):
30+
If you wish your version of this file to be governed by only the CDDL or
31+
only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
elects to include this software in this distribution under the [CDDL or GPL
33+
Version 2] license." If you don't indicate a single choice of license, a
34+
recipient has the option to distribute your version of this file under
35+
either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
its licensees as provided above. However, if you add GPL Version 2 code
37+
and therefore, elected the GPL Version 2 license, then the option applies
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
44+
JAXB Example
45+
============
46+
47+
This example demonstrates how to use JSONB with resource classes.
48+
49+
Contents
50+
--------
51+
52+
The mapping of the URI path space is presented in the following table:
53+
54+
URI path | Resource class | HTTP methods
55+
--------------------------------------- | ------------------------ | --------------
56+
**_/jsonb/cats/one_** | JsonbResource | GET
57+
**_/jsonb/cats/all_** | JsonbResource | GET
58+
**_/jsonb/cats/add_** | JsonbResource | POST
59+
**_/jsonb/cats/addAll_** | JsonbResource | POST
60+
61+
Running the Example
62+
-------------------
63+
64+
Run the example as follows:
65+
66+
> mvn clean compile exec:java
67+
68+
This deploys the example using [Grizzly](http://grizzly.java.net/) container. You can access the application at:
69+
70+
- <http://localhost:8080/jsonb/cats/one>
71+
- <http://localhost:8080/jsonb/cats/all>
72+
73+
or you can post an xml entity:
74+
75+
> curl -v -X POST http://localhost:8080/jsonb/cats/add -H "Content-Type:application/json" -d '
76+
> {"name":"Darwin", domesticated:"true",color:"white",sort:"maine coon"}'
77+
78+
You can also use the built war file to deploy the app to a container of your choice.

examples/json-binding/pom.xml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44+
<modelVersion>4.0.0</modelVersion>
45+
<parent>
46+
<groupId>org.glassfish.jersey.examples</groupId>
47+
<artifactId>project</artifactId>
48+
<version>2.26-SNAPSHOT</version>
49+
</parent>
50+
51+
<artifactId>json-binding</artifactId>
52+
<packaging>war</packaging>
53+
<name>jersey-examples-json-binding</name>
54+
55+
<description>Jersey JAXB example.</description>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.glassfish.jersey.containers</groupId>
60+
<artifactId>jersey-container-grizzly2-http</artifactId>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.glassfish.jersey.containers</groupId>
65+
<artifactId>jersey-container-servlet</artifactId>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
70+
<artifactId>jersey-test-framework-provider-bundle</artifactId>
71+
<type>pom</type>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.glassfish.jersey.media</groupId>
77+
<artifactId>jersey-media-json-binding</artifactId>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.glassfish.jersey.inject</groupId>
82+
<artifactId>jersey-hk2</artifactId>
83+
</dependency>
84+
</dependencies>
85+
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.codehaus.mojo</groupId>
90+
<artifactId>exec-maven-plugin</artifactId>
91+
<configuration>
92+
<mainClass>org.glassfish.jersey.examples.jsonb.App</mainClass>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
98+
<profiles>
99+
<profile>
100+
<id>release</id>
101+
<build>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-assembly-plugin</artifactId>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</profile>
110+
</profiles>
111+
112+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.examples.jsonb;
41+
42+
import java.io.IOException;
43+
import java.net.URI;
44+
import java.util.logging.Level;
45+
import java.util.logging.Logger;
46+
47+
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
48+
49+
import org.glassfish.grizzly.http.server.HttpServer;
50+
51+
/**
52+
* Jersey JSONB example standalone application.
53+
*
54+
* @author Adam Lindenthal (adam.lindenthal at oracle.com)
55+
*/
56+
public class App {
57+
58+
private static final URI BASE_URI = URI.create("http://localhost:8080/jsonb/");
59+
60+
public static void main(String[] args) {
61+
try {
62+
System.out.println("JAXB Jersey Example App");
63+
64+
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new JsonbApplication(), false);
65+
Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
66+
server.start();
67+
68+
System.out.println(
69+
String.format("Application started.%nTry out %s%nStop the application using CTRL+C", BASE_URI));
70+
71+
Thread.currentThread().join();
72+
} catch (IOException | InterruptedException ex) {
73+
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
74+
}
75+
}
76+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.examples.jsonb;
41+
42+
/**
43+
* Example cat POJO for JSONB (un)marshalling.
44+
*
45+
* @author Adam Lindenthal (adam.lindenthal at oracle.com)
46+
*/
47+
public class Cat {
48+
private String name;
49+
private String sort;
50+
private String color;
51+
private boolean domesticated;
52+
53+
// json-b needs the default constructor
54+
public Cat() {
55+
super();
56+
}
57+
58+
public Cat(String name, String sort, String color, boolean domesticated) {
59+
this.name = name;
60+
this.sort = sort;
61+
this.color = color;
62+
this.domesticated = domesticated;
63+
}
64+
65+
public String getName() {
66+
return name;
67+
}
68+
69+
public Cat setName(String name) {
70+
this.name = name;
71+
return this;
72+
}
73+
74+
public String getSort() {
75+
return sort;
76+
}
77+
78+
public Cat setSort(String sort) {
79+
this.sort = sort;
80+
return this;
81+
}
82+
83+
public String getColor() {
84+
return color;
85+
}
86+
87+
public Cat setColor(String color) {
88+
this.color = color;
89+
return this;
90+
}
91+
92+
public boolean isDomesticated() {
93+
return domesticated;
94+
}
95+
96+
public Cat setDomesticated(boolean domesticated) {
97+
this.domesticated = domesticated;
98+
return this;
99+
}
100+
}

0 commit comments

Comments
 (0)