Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit d9a619b

Browse files
committed
added sample for writing custom providers on JDK 9
Signed-off-by: Lukas Jungmann <[email protected]>
1 parent c21393b commit d9a619b

File tree

6 files changed

+588
-0
lines changed

6 files changed

+588
-0
lines changed

demos/customprovider-jdk9/pom.xml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
https://oss.oracle.com/licenses/CDDL+GPL-1.1
13+
or 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 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+
only if the new code is made subject to such option by the copyright
39+
holder.
40+
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/maven-v4_0_0.xsd">
44+
<modelVersion>4.0.0</modelVersion>
45+
46+
<parent>
47+
<groupId>org.glassfish.jsonp</groupId>
48+
<artifactId>demos</artifactId>
49+
<version>1.2-SNAPSHOT</version>
50+
<relativePath>../pom.xml</relativePath>
51+
</parent>
52+
53+
<url>http://maven.apache.org</url>
54+
<artifactId>customprovider-jdk9</artifactId>
55+
56+
<name>customprovider-jdk9</name>
57+
58+
<properties>
59+
<mod.dir>${project.build.directory}/mods</mod.dir>
60+
</properties>
61+
<build>
62+
<finalName>customprovider-jdk9</finalName>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-dependency-plugin</artifactId>
67+
<executions>
68+
<execution>
69+
<id>prepare-endorsed</id>
70+
<phase>validate</phase>
71+
<goals>
72+
<goal>copy-dependencies</goal>
73+
</goals>
74+
<configuration>
75+
<outputDirectory>${mod.dir}</outputDirectory>
76+
<silent>false</silent>
77+
<!--<scope>compile</scope>-->
78+
</configuration>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-surefire-plugin</artifactId>
85+
<version>2.20</version>
86+
<executions>
87+
<execution>
88+
<goals>
89+
<goal>test</goal>
90+
</goals>
91+
<id>test</id>
92+
</execution>
93+
</executions>
94+
<configuration>
95+
<argLine>
96+
--module-path ${project.build.directory}/classes:${mod.dir}:${project.build.directory}/test-classes
97+
--add-modules org.glassfish.java.json.demos.customprovider
98+
</argLine>
99+
<!--
100+
- -add-modules org.glassfish.java.json.demos.customprovider,org.glassfish.java.json,junit
101+
- -patch-module org.glassfish.java.json.demos.customprovider=${project.build.directory}/test-classes
102+
-->
103+
</configuration>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
<dependencies>
108+
<dependency>
109+
<groupId>org.glassfish</groupId>
110+
<artifactId>javax.json</artifactId>
111+
</dependency>
112+
<dependency>
113+
<groupId>junit</groupId>
114+
<artifactId>junit</artifactId>
115+
<scope>test</scope>
116+
</dependency>
117+
<dependency>
118+
<groupId>org.hamcrest</groupId>
119+
<artifactId>hamcrest-core</artifactId>
120+
<version>1.3</version>
121+
<scope>test</scope>
122+
</dependency>
123+
</dependencies>
124+
</project>
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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+
* https://oss.oracle.com/licenses/CDDL+GPL-1.1
12+
* or 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 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+
41+
package org.glassfish.json.customprovider;
42+
43+
import javax.json.JsonException;
44+
import javax.json.JsonValue;
45+
import javax.json.stream.JsonGenerator;
46+
import java.io.IOException;
47+
import java.io.Writer;
48+
import java.math.BigDecimal;
49+
import java.math.BigInteger;
50+
51+
/**
52+
* @author Jitendra Kotamraju
53+
*/
54+
public class TestGenerator implements JsonGenerator {
55+
private final Writer writer;
56+
57+
public TestGenerator(Writer writer) {
58+
this.writer = writer;
59+
}
60+
61+
@Override
62+
public void flush() {
63+
}
64+
65+
@Override
66+
public JsonGenerator writeStartObject() {
67+
return null;
68+
}
69+
70+
@Override
71+
public JsonGenerator writeStartObject(String name) {
72+
return null;
73+
}
74+
75+
@Override
76+
public JsonGenerator write(String name, String fieldValue) {
77+
return null;
78+
}
79+
80+
@Override
81+
public JsonGenerator write(String name, int value) {
82+
return null;
83+
}
84+
85+
@Override
86+
public JsonGenerator write(String name, long value) {
87+
return null;
88+
}
89+
90+
@Override
91+
public JsonGenerator write(String name, double value) {
92+
return null;
93+
}
94+
95+
@Override
96+
public JsonGenerator write(String name, BigInteger value) {
97+
return null;
98+
}
99+
100+
@Override
101+
public JsonGenerator write(String name, BigDecimal value) {
102+
return null;
103+
}
104+
105+
@Override
106+
public JsonGenerator write(String name, boolean value) {
107+
return null;
108+
}
109+
110+
@Override
111+
public JsonGenerator writeNull(String name) {
112+
return null;
113+
}
114+
115+
@Override
116+
public JsonGenerator write(JsonValue value) {
117+
return null;
118+
}
119+
120+
@Override
121+
public JsonGenerator writeStartArray() {
122+
try {
123+
writer.write("[");
124+
} catch(IOException ioe) {
125+
throw new JsonException("I/O error", ioe);
126+
}
127+
return this;
128+
}
129+
130+
@Override
131+
public JsonGenerator writeStartArray(String name) {
132+
return null;
133+
}
134+
135+
@Override
136+
public JsonGenerator write(String name, JsonValue value) {
137+
return null;
138+
}
139+
140+
@Override
141+
public JsonGenerator write(String value) {
142+
return null;
143+
}
144+
145+
146+
@Override
147+
public JsonGenerator write(int value) {
148+
return null;
149+
}
150+
151+
@Override
152+
public JsonGenerator write(long value) {
153+
return null;
154+
}
155+
156+
@Override
157+
public JsonGenerator write(double value) {
158+
return null;
159+
}
160+
161+
@Override
162+
public JsonGenerator write(BigInteger value) {
163+
return null;
164+
}
165+
166+
@Override
167+
public JsonGenerator write(BigDecimal value) {
168+
return null;
169+
}
170+
171+
@Override
172+
public JsonGenerator write(boolean value) {
173+
return null;
174+
}
175+
176+
@Override
177+
public JsonGenerator writeNull() {
178+
return null;
179+
}
180+
181+
@Override
182+
public JsonGenerator writeEnd() {
183+
try {
184+
writer.write("]");
185+
} catch(IOException ioe) {
186+
throw new JsonException("I/O error", ioe);
187+
}
188+
return this;
189+
}
190+
191+
@Override
192+
public void close() {
193+
try {
194+
writer.close();
195+
} catch(IOException ioe) {
196+
throw new JsonException("I/O error", ioe);
197+
}
198+
}
199+
200+
@Override
201+
public JsonGenerator writeKey(String string) {
202+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
203+
}
204+
205+
}

0 commit comments

Comments
 (0)