├── .gitignore ├── CONTRIBUTING.md ├── LICENCE.html ├── LICENCE.txt ├── README.md ├── api ├── pom.xml └── src │ └── main │ ├── java │ ├── javax │ │ └── json │ │ │ └── bind │ │ │ ├── Jsonb.java │ │ │ ├── JsonbBuilder.java │ │ │ ├── JsonbConfig.java │ │ │ ├── JsonbException.java │ │ │ ├── adapter │ │ │ ├── JsonbAdapter.java │ │ │ └── package-info.java │ │ │ ├── annotation │ │ │ ├── JsonbAnnotation.java │ │ │ ├── JsonbCreator.java │ │ │ ├── JsonbDateFormat.java │ │ │ ├── JsonbNillable.java │ │ │ ├── JsonbNumberFormat.java │ │ │ ├── JsonbProperty.java │ │ │ ├── JsonbPropertyOrder.java │ │ │ ├── JsonbTransient.java │ │ │ ├── JsonbTypeAdapter.java │ │ │ ├── JsonbTypeDeserializer.java │ │ │ ├── JsonbTypeSerializer.java │ │ │ ├── JsonbVisibility.java │ │ │ └── package-info.java │ │ │ ├── config │ │ │ ├── BinaryDataStrategy.java │ │ │ ├── PropertyNamingStrategy.java │ │ │ ├── PropertyOrderStrategy.java │ │ │ ├── PropertyVisibilityStrategy.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── serializer │ │ │ ├── DeserializationContext.java │ │ │ ├── JsonbDeserializer.java │ │ │ ├── JsonbSerializer.java │ │ │ ├── SerializationContext.java │ │ │ └── package-info.java │ │ │ └── spi │ │ │ ├── JsonbProvider.java │ │ │ └── package-info.java │ └── module-info.java │ └── javadoc │ └── doc-files │ └── spec-license.html ├── docs ├── pom.xml └── src │ └── docs │ └── user-guide.adoc ├── etc └── config │ ├── checkstyle.xml │ ├── copyright-exclude │ └── copyright.txt ├── examples ├── pom.xml └── runtime │ ├── nb-configuration.xml │ ├── pom.xml │ └── src │ └── main │ └── java │ ├── com │ └── example │ │ └── jsonb │ │ └── CustomJsonbBuilder.java │ └── examples │ ├── mapping │ ├── CustomMapping.java │ ├── DefaultMapping.java │ ├── DefaultMappingDates.java │ ├── DefaultMappingGenerics.java │ ├── IJsonCompatibility.java │ └── Utils.java │ ├── model │ ├── Author.java │ ├── Book.java │ └── Language.java │ └── runtime │ └── Runtime.java └── spec ├── spec.docx └── spec.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # maven noise 2 | target 3 | 4 | # osx noise 5 | .DS_Store 6 | profile 7 | 8 | #IntelliJ Idea noise 9 | .idea 10 | *.iws 11 | *.ipr 12 | *.iml 13 | 14 | # TeX build noise 15 | *.aux 16 | *.bbl 17 | *.blg 18 | *.log 19 | *.out 20 | *.tex~ 21 | *.thm 22 | *.toc 23 | /spec/Makefile.fdb_latexmk 24 | /spec/Makefile.fls 25 | /spec/spec.synctex.gz 26 | /spec/spec.xwm 27 | 28 | # eclipse noise 29 | .settings/ 30 | .classpath 31 | .project 32 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | --- 4 | 5 | # Source Code Submissions 6 | We welcome your contributions and look forward to collaborating with you. We can only accept source code repository 7 | submissions from users who have signed and returned the Oracle 8 | Contributor Agreement. You will find details and the agreement to sign at this OTN web page: 9 | [Oracle Contributor Agreement](http://www.oracle.com/technetwork/community/oca-486395.html). 10 | 11 | # Other Contributions 12 | For all project Submissions other than source code repository contributions, the following also applies: Oracle does 13 | not claim ownership of Your Submissions. However, in order to fulfill 14 | the purposes of this project, You must give Oracle and all Users 15 | the right to post, access, discuss, use, publish, disseminate, and refine 16 | Your Submissions. 17 | 18 | In legalese: *You hereby grant to Oracle and all 19 | Users a royalty-free, perpetual, irrevocable, worldwide, non-exclusive, 20 | and fully sub-licensable right and license, under Your intellectual 21 | property rights, to reproduce, modify, adapt, publish, translate, create 22 | derivative works from, distribute, perform, display, and use Your 23 | Submissions (in whole or part) and to incorporate or implement them in 24 | other works in any form, media, or technology now known or later 25 | developed, all subject to the obligation to retain any copyright notices 26 | included in Your Submissions. All Users, Oracle, and their 27 | sublicensees are responsible for any modifications they make to the 28 | Submissions of others.* 29 | 30 | Copyright © 2017 Oracle and/or its affiliates. All rights reserved. 31 | -------------------------------------------------------------------------------- /LICENCE.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee/jsonb-spec/dc81f781f490e26ca545f98c50a7319551f724e2/LICENCE.html -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee/jsonb-spec/dc81f781f490e26ca545f98c50a7319551f724e2/LICENCE.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java API for JSON Binding (JSON-B) 2 | 3 | :warning: This project is now part of the EE4J initiative. This repository has been archived as all activities are now happening in the [corresponding Eclipse repository](https://github.com/eclipse-ee4j/jsonb-api). See [here](https://www.eclipse.org/ee4j/status.php) for the overall EE4J transition status. 4 | 5 | ## Links 6 | 7 | - JSON-B community web site: http://json-b.net 8 | - Eclipse Project for JSON-B: https://projects.eclipse.org/projects/ee4j.jsonb 9 | - Discussion groups: jsonb-dev@eclipse.org 10 | - JSR-367 page on JCP site: https://jcp.org/en/jsr/detail?id=367 11 | - Yasson (Reference Implementation): https://github.com/eclipse-ee4j/yasson 12 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/Jsonb.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | package javax.json.bind; 41 | 42 | import java.io.InputStream; 43 | import java.io.OutputStream; 44 | import java.io.Reader; 45 | import java.io.Writer; 46 | import java.lang.reflect.Type; 47 | 48 | /** 49 | *

{@code Jsonb} provides an abstraction over the JSON Binding framework operations:

50 | * 51 | * 55 | * 56 | *

Instance of this class is created using {@link javax.json.bind.JsonbBuilder JsonbBuilder} 57 | * builder methods:

58 | *
{@code
 59 |  * // Example 1 - Creating Jsonb using default JsonbBuilder instance provided by default JsonbProvider
 60 |  * Jsonb jsonb = JsonbBuilder.create();
 61 |  *
 62 |  * // Example 2 - Creating Jsonb instance for a specific provider specified by a class name
 63 |  * Jsonb jsonb = JsonbBuilder.newBuilder("foo.bar.ProviderImpl).build();
 64 |  *
 65 |  * // Example 3 - Creating Jsonb instance from a custom provider implementation
 66 |  * Jsonb jsonb = new CustomJsonbBuilder().build();
 67 |  * }
68 | * 69 | * Deserializing (reading) JSON
70 | *
71 | * Can de-serialize JSON data that represents either an entire JSON 72 | * document or a subtree of a JSON document. 73 | *
74 | *
75 | * Reading (deserializing) object content tree from a File:

76 | *
 77 |  *     Jsonb jsonb = JsonbBuilder.create();
 78 |  *     Book book = jsonb.fromJson(new FileReader("jsonfile.json"), Book.class);
79 | * If the deserialization process is unable to deserialize the JSON content to an object 80 | * content tree, fatal error is reported that terminates processing by 81 | * throwing JsonbException. 82 | *
83 | * 84 | *

Serializing (writing) to JSON

85 | *
86 | * Serialization writes the representation of a Java object content tree into 87 | * JSON data. 88 | *
89 | *
90 | * Writing (serializing) object content tree to a File:

91 | *
 92 |  *     jsonb.toJson(object, new FileWriter("foo.json"));
93 | * Writing (serializing) to a Writer:

94 | *
 95 |  *     jsonb.toJson(object, new PrintWriter(System.out));
 96 |  *    
97 | *
98 | * 99 | *

Encoding

100 | *
101 | * In deserialization operations ({@code fromJson}), encoding of JSON data is detected automatically. 102 | * Use the {@link javax.json.bind.JsonbConfig JsonbConfig} API to configure expected 103 | * input encoding used within deserialization operations. Client applications are 104 | * expected to supply a valid character encoding as defined in the 105 | * RFC 7159 and supported by Java Platform. 106 | * 107 | * In serialization operations ({@code toJson}), UTF-8 encoding is used by default 108 | * for writing JSON data. 109 | * Use the {@link javax.json.bind.JsonbConfig JsonbConfig} API to configure the 110 | * output encoding used within serialization operations. Client applications are 111 | * expected to supply a valid character encoding as defined in the 112 | * RFC 7159 and supported by Java Platform. 113 | *
114 | * 115 | *

For optimal use, {@code JsonbBuilder} and {@code Jsonb} instances should be 116 | * reused - for a typical use-case, only one {@code Jsonb} instance is 117 | * required by an application.

118 | * 119 | *

All the methods in this class are safe for use by multiple concurrent threads.

120 | * 121 | *

Calling {@code Closable.close()} method will cleanup all CDI managed components 122 | * (such as adapters with CDI dependencies) created during interaction with Jsonb. 123 | * Calling {@code close()} must be done after all threads has finished interaction with Jsonb. 124 | * If there are remaining threads working with Jsonb and {@code close()} is called, behaviour is undefined. 125 | *

126 | * 127 | * @see Jsonb 128 | * @see JsonbBuilder 129 | * @see java.util.ServiceLoader 130 | * @since JSON Binding 1.0 131 | */ 132 | public interface Jsonb extends AutoCloseable { 133 | 134 | /** 135 | * Reads in a JSON data from the specified string and return the resulting 136 | * content tree. 137 | * 138 | * @param str 139 | * The string to deserialize JSON data from. 140 | * @param type 141 | * Type of the content tree's root object. 142 | * @param 143 | * Type of the content tree's root object. 144 | * 145 | * @return the newly created root object of the java content tree 146 | * 147 | * @throws JsonbException 148 | * If any unexpected error(s) occur(s) during deserialization. 149 | * @throws NullPointerException 150 | * If any of the parameters is {@code null}. 151 | */ 152 | T fromJson(String str, Class type) throws JsonbException; 153 | 154 | /** 155 | * Reads in a JSON data from the specified string and return the resulting 156 | * content tree. 157 | * 158 | * @param str 159 | * The string to deserialize JSON data from. 160 | * @param runtimeType 161 | * Runtime type of the content tree's root object. 162 | * @param 163 | * Type of the content tree's root object. 164 | * 165 | * @return the newly created root object of the java content tree 166 | * 167 | * @throws JsonbException 168 | * If any unexpected error(s) occur(s) during deserialization. 169 | * @throws NullPointerException 170 | * If any of the parameters is {@code null}. 171 | */ 172 | T fromJson(String str, Type runtimeType) throws JsonbException; 173 | 174 | /** 175 | * Reads in a JSON data from the specified Reader and return the 176 | * resulting content tree. 177 | * 178 | * @param reader 179 | * The character stream is read as a JSON data. 180 | * @param type 181 | * Type of the content tree's root object. 182 | * @param 183 | * Type of the content tree's root object. 184 | * 185 | * @return the newly created root object of the java content tree 186 | * 187 | * @throws JsonbException 188 | * If any unexpected error(s) occur(s) during deserialization. 189 | * @throws NullPointerException 190 | * If any of the parameters is {@code null}. 191 | */ 192 | T fromJson(Reader reader, Class type) throws JsonbException; 193 | 194 | /** 195 | * Reads in a JSON data from the specified Reader and return the 196 | * resulting content tree. 197 | * 198 | * @param reader 199 | * The character stream is read as a JSON data. 200 | * 201 | * @param runtimeType 202 | * Runtime type of the content tree's root object. 203 | * 204 | * @param 205 | * Type of the content tree's root object. 206 | * 207 | * @return the newly created root object of the java content tree 208 | * 209 | * @throws JsonbException 210 | * If any unexpected error(s) occur(s) during deserialization. 211 | * @throws NullPointerException 212 | * If any of the parameters is {@code null}. 213 | */ 214 | T fromJson(Reader reader, Type runtimeType) throws JsonbException; 215 | 216 | /** 217 | * Reads in a JSON data from the specified InputStream and return the 218 | * resulting content tree. 219 | * 220 | * @param stream 221 | * The stream is read as a JSON data. Upon a 222 | * successful completion, the stream will be closed by this method. 223 | * @param type 224 | * Type of the content tree's root object. 225 | * @param 226 | * Type of the content tree's root object. 227 | * 228 | * @return the newly created root object of the java content tree 229 | * 230 | * @throws JsonbException 231 | * If any unexpected error(s) occur(s) during deserialization. 232 | * @throws NullPointerException 233 | * If any of the parameters is {@code null}. 234 | */ 235 | T fromJson(InputStream stream, Class type) throws JsonbException; 236 | 237 | /** 238 | * Reads in a JSON data from the specified InputStream and return the 239 | * resulting content tree. 240 | * 241 | * @param stream 242 | * The stream is read as a JSON data. Upon a 243 | * successful completion, the stream will be closed by this method. 244 | * 245 | * @param runtimeType 246 | * Runtime type of the content tree's root object. 247 | * 248 | * @param 249 | * Type of the content tree's root object. 250 | * 251 | * @return the newly created root object of the java content tree 252 | * 253 | * @throws JsonbException 254 | * If any unexpected error(s) occur(s) during deserialization. 255 | * @throws NullPointerException 256 | * If any of the parameters is {@code null}. 257 | */ 258 | T fromJson(InputStream stream, Type runtimeType) throws JsonbException; 259 | 260 | /** 261 | * Writes the Java object tree with root object {@code object} to a String 262 | * instance as JSON. 263 | * 264 | * @param object 265 | * The root object of the object content tree to be serialized. Must not be null. 266 | * 267 | * @return String instance with serialized JSON data. 268 | * 269 | * @throws JsonbException If any unexpected problem occurs during the 270 | * serialization, such as I/O error. 271 | * @throws NullPointerException 272 | * If any of the parameters is {@code null}. 273 | * 274 | * @since JSON Binding 1.0 275 | */ 276 | String toJson(Object object) throws JsonbException; 277 | 278 | /** 279 | * Writes the Java object tree with root object {@code object} to a String 280 | * instance as JSON. 281 | * 282 | * @param object 283 | * The root object of the object content tree to be serialized. Must not be null. 284 | * 285 | * @param runtimeType 286 | * Runtime type of the content tree's root object. 287 | * 288 | * @return String instance with serialized JSON data. 289 | * 290 | * @throws JsonbException If any unexpected problem occurs during the 291 | * serialization, such as I/O error. 292 | * @throws NullPointerException 293 | * If any of the parameters is {@code null}. 294 | * 295 | * @since JSON Binding 1.0 296 | */ 297 | String toJson(Object object, Type runtimeType) throws JsonbException; 298 | 299 | /** 300 | * Writes the object content tree into a Writer character stream. 301 | * 302 | * @param object 303 | * The object content tree to be serialized. 304 | * @param writer 305 | * The JSON will be sent as a character stream to the given 306 | * {@link Writer}. 307 | * 308 | * @throws JsonbException If any unexpected problem occurs during the 309 | * serialization. 310 | * @throws NullPointerException 311 | * If any of the parameters is {@code null}. 312 | * 313 | * @since JSON Binding 1.0 314 | */ 315 | void toJson(Object object, Writer writer) throws JsonbException; 316 | 317 | /** 318 | * Writes the object content tree into a Writer character stream. 319 | * 320 | * @param object 321 | * The object content tree to be serialized. 322 | * 323 | * @param runtimeType 324 | * Runtime type of the content tree's root object. 325 | * 326 | * @param writer 327 | * The JSON will be sent as a character stream to the given 328 | * {@link Writer}. 329 | * 330 | * @throws JsonbException If any unexpected problem occurs during the 331 | * serialization. 332 | * @throws NullPointerException 333 | * If any of the parameters is {@code null}. 334 | * 335 | * @since JSON Binding 1.0 336 | */ 337 | void toJson(Object object, Type runtimeType, Writer writer) throws JsonbException; 338 | 339 | /** 340 | * Writes the object content tree into output stream. 341 | * 342 | * @param object 343 | * The object content tree to be serialized. 344 | * @param stream 345 | * The JSON will be sent as a byte stream to the given 346 | * {@link OutputStream}. Upon a successful completion, the stream will be closed 347 | * by this method. 348 | * 349 | * @throws JsonbException If any unexpected problem occurs during the 350 | * serialization. 351 | * @throws NullPointerException 352 | * If any of the parameters is {@code null}. 353 | * 354 | * @since JSON Binding 1.0 355 | */ 356 | void toJson(Object object, OutputStream stream) throws JsonbException; 357 | 358 | /** 359 | * Writes the object content tree into output stream. 360 | * 361 | * @param object 362 | * The object content tree to be serialized. 363 | * 364 | * @param runtimeType 365 | * Runtime type of the content tree's root object. 366 | * 367 | * @param stream 368 | * The JSON will be sent as a byte stream to the given 369 | * {@link OutputStream}. Upon a successful completion, the stream will be closed 370 | * by this method. 371 | * 372 | * @throws JsonbException If any unexpected problem occurs during the 373 | * serialization. 374 | * @throws NullPointerException 375 | * If any of the parameters is {@code null}. 376 | * 377 | * @since JSON Binding 1.0 378 | */ 379 | void toJson(Object object, Type runtimeType, OutputStream stream) throws JsonbException; 380 | } 381 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/JsonbBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | package javax.json.bind; 41 | 42 | import javax.json.bind.spi.JsonbProvider; 43 | import javax.json.spi.JsonProvider; 44 | 45 | /** 46 | * JsonbBuilder class provides the client's entry point to the JSON Binding 47 | * API. It builds {@link javax.json.bind.Jsonb Jsonb} instances based on all 48 | * parameters and configuration provided before calling {@code build()} method. 49 | * 50 | * For most use-cases, only one instance of JsonbBuilder is required within the 51 | * application. 52 | * 53 | * @see Jsonb 54 | * @see java.util.ServiceLoader 55 | * @since JSON Binding 1.0 56 | */ 57 | public interface JsonbBuilder { 58 | 59 | /** 60 | * Set configuration which will be set to the newly created 61 | * {@link javax.json.bind.Jsonb Jsonb} instance. 62 | * 63 | * @param config 64 | * Configuration for {@link javax.json.bind.Jsonb Jsonb} instance. 65 | * 66 | * @return This {@code JsonbBuilder} instance. 67 | */ 68 | JsonbBuilder withConfig(JsonbConfig config); 69 | 70 | /** 71 | * Provides a JSON-P provider 72 | * to be used for all JSON-P related operations. 73 | * 74 | * @param jsonpProvider 75 | * {@link javax.json.spi.JsonProvider JsonProvider} instance 76 | * to be used by Jsonb to lookup JSON-P implementation. 77 | * 78 | * @return This {@code JsonbBuilder} instance. 79 | */ 80 | JsonbBuilder withProvider(JsonProvider jsonpProvider); 81 | 82 | /** 83 | * Returns a new instance of {@link javax.json.bind.Jsonb Jsonb} based on the 84 | * parameters and configuration specified previously in this builder. 85 | * 86 | * @return Jsonb A new instance of {@link javax.json.bind.Jsonb Jsonb} class. 87 | * Always a non-null valid object. 88 | * 89 | * @throws javax.json.bind.JsonbException If an error was encountered while 90 | * creating the Jsonb instance, such as (but not limited to) no JSON 91 | * Binding provider found, or classes provide conflicting annotations. 92 | * 93 | * @throws IllegalArgumentException If there's an error processing the set 94 | * parameters, such as the non-null parameter is assigned null value, or 95 | * unrecognized property is set in 96 | * {@link javax.json.bind.JsonbConfig JsonbConfig}. 97 | */ 98 | Jsonb build(); 99 | 100 | /** 101 | * Create a new {@link javax.json.bind.Jsonb} instance using the default 102 | * {@code JsonbBuilder} implementation provided as returned from 103 | * {@link javax.json.bind.spi.JsonbProvider#provider()} method. 104 | * 105 | * @return new {@link javax.json.bind.Jsonb Jsonb} instance. 106 | */ 107 | static Jsonb create() { 108 | return JsonbProvider.provider().create().build(); 109 | } 110 | 111 | /** 112 | * Create a new {@link javax.json.bind.Jsonb} instance using the default 113 | * {@code JsonbBuilder} implementation provided as returned from 114 | * {@link javax.json.bind.spi.JsonbProvider#provider()} method, configured 115 | * with provided configuration. 116 | * 117 | * @param config 118 | * Provided configuration for {@link javax.json.bind.Jsonb} instance. 119 | * 120 | * @return new {@link javax.json.bind.Jsonb Jsonb} instance. 121 | */ 122 | static Jsonb create(JsonbConfig config) { 123 | return JsonbProvider.provider().create().withConfig(config).build(); 124 | } 125 | 126 | /** 127 | * Create a new {@code JsonbBuilder} instance as returned by the default 128 | * {@link javax.json.bind.spi.JsonbProvider#provider()} method. 129 | * 130 | * @return new {@code JsonbBuilder} instance. 131 | */ 132 | static JsonbBuilder newBuilder() { 133 | return JsonbProvider.provider().create(); 134 | } 135 | 136 | /** 137 | * Create a new {@code JsonbBuilder} instance as returned by 138 | * {@link javax.json.bind.spi.JsonbProvider#provider(String)} 139 | * method. 140 | * 141 | * @param providerName 142 | * Provider class name to be looked up by {@link java.util.ServiceLoader ServiceLoader}. 143 | * 144 | * @return new {@code JsonbBuilder} instance. 145 | */ 146 | static JsonbBuilder newBuilder(final String providerName) { 147 | return JsonbProvider.provider(providerName).create(); 148 | } 149 | 150 | /** 151 | * Create a new {@code JsonbBuilder} instance as returned by 152 | * {@code provider#create} call. 153 | * 154 | * @param provider 155 | * {@link javax.json.spi.JsonProvider JsonProvider} instance 156 | * used for creating {@code JsonBuilder instances}. 157 | * 158 | * @return new {@code JsonbBuilder} instance. 159 | */ 160 | static JsonbBuilder newBuilder(final JsonbProvider provider) { 161 | return provider.create(); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/JsonbException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind; 42 | 43 | /** 44 | * Root class for all JSON Binding exceptions. 45 | * 46 | * @since JSON Binding 1.0 47 | */ 48 | public class JsonbException extends RuntimeException { 49 | 50 | private static final long serialVersionUID = 1L; 51 | 52 | /** 53 | * Constructs a new runtime exception with the specified detail message. 54 | * The cause is not initialized, and may subsequently be initialized by a 55 | * call to {@link #initCause}. 56 | * 57 | * @param message 58 | * The detail message. The detail message is saved for 59 | * later retrieval by the {@link #getMessage()} method. 60 | */ 61 | public JsonbException(final String message) { 62 | super(message); 63 | } 64 | 65 | /** 66 | * Constructs a new runtime exception with the specified detail message and 67 | * cause.

Note that the detail message associated with 68 | * {@code cause} is not automatically incorporated in 69 | * this runtime exception's detail message. 70 | * 71 | * @param message 72 | * The detail message (which is saved for later retrieval 73 | * by the {@link #getMessage()} method). 74 | * @param cause 75 | * The cause (which is saved for later retrieval by the 76 | * {@link #getCause()} method). (A {@code null} value is 77 | * permitted, and indicates that the cause is nonexistent or 78 | * unknown.) 79 | */ 80 | public JsonbException(final String message, final Throwable cause) { 81 | super(message, cause); 82 | } 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/adapter/JsonbAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | package javax.json.bind.adapter; 41 | 42 | /** 43 | *

Allows to define custom mapping for given java type. The target type could be string or some 44 | * mappable java type.

45 | * 46 | *

On serialization "Original" type is converted into "Adapted" type. After that "Adapted" type is serialized to 47 | * JSON the standard way.

48 | * 49 | *

On deserialization it works the reverse way: JSON data are deserialized into "Adapted" type which is converted 50 | * to "Original" type after that.

51 | * 52 | *

Adapters are registered using {@link javax.json.bind.JsonbConfig#withAdapters(JsonbAdapter[])} method 53 | * or using {@link javax.json.bind.annotation.JsonbTypeAdapter} annotation on class field.

54 | * 55 | * @param The type that JSONB doesn't know how to handle 56 | * @param The type that JSONB knows how to handle out of the box 57 | * 58 | *

Adapter runtime "Original" and "Adapted" generic types are inferred from subclassing information, 59 | * which is mandatory for adapter to work.

60 | * 61 | *

Sample 1:

62 | *
 63 |  * {@code
 64 |  *      // Generic information is provided by subclassing.
 65 |  *      class BoxToCrateAdapter implements JsonbAdapter, Crate> {...};
 66 |  *      jsonbConfig.withAdapters(new BoxToCrateAdapter());
 67 |  *
 68 |  *      // Generic information is provided by subclassing with anonymous class
 69 |  *      jsonbConfig.withAdapters(new JsonbAdapter, Crate> {...});
 70 |  * }
 71 |  * 
72 | * 73 | *

Sample 2:

74 | *
 75 |  * {@code
 76 |  *      BoxToCrateAdapter implements JsonbAdapter, Integer> {...};
 77 |  *
 78 |  *      // Bad way: Generic type information is lost due to type erasure
 79 |  *      jsonbConfig.withAdapters(new BoxToCrateAdapter());
 80 |  *
 81 |  *      // Proper way: Anonymous class holds generic type information
 82 |  *      jsonbConfig.withAdapters(new BoxToCrateAdapter(){});
 83 |  * }
 84 |  * 
85 | * 86 | * @see javax.json.bind.JsonbConfig 87 | * @see javax.json.bind.annotation.JsonbTypeAdapter 88 | * @since JSON Binding 1.0 89 | */ 90 | public interface JsonbAdapter { 91 | 92 | /** 93 | * This method is used on serialization only. It contains a conversion logic from type Original to type Adapted. 94 | * After conversion Adapted type will be mapped to JSON the standard way. 95 | * 96 | * @param obj 97 | * Object to convert. 98 | * @return Converted object which will be serialized to JSON. 99 | * @throws Exception if there is an error during the conversion. 100 | */ 101 | Adapted adaptToJson(Original obj) throws Exception; 102 | 103 | /** 104 | * This method is used on deserialization only. It contains a conversion logic from type Adapted to type Original. 105 | * 106 | * @param obj 107 | * Object to convert. 108 | * @return Converted object representing pojo to be set into object graph. 109 | * @throws Exception if there is an error during the conversion. 110 | */ 111 | Original adaptFromJson(Adapted obj) throws Exception; 112 | } 113 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/adapter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | /** 42 | *

43 | * Defines adapter related classes. 44 | *

45 | * 46 | * @since JSON Binding 1.0 47 | */ 48 | package javax.json.bind.adapter; 49 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.annotation; 42 | 43 | import java.lang.annotation.Documented; 44 | import java.lang.annotation.Retention; 45 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 46 | 47 | /** 48 | * Marks any relevant JSON Binding annotations. Includes 49 | * {@code @Documented} and {@code @Retention(RUNTIME)} definitions. 50 | * 51 | * @since JSON Binding 1.0 52 | */ 53 | 54 | @Documented 55 | @Retention(RUNTIME) 56 | public @interface JsonbAnnotation { } 57 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | package javax.json.bind.annotation; 41 | 42 | import java.lang.annotation.ElementType; 43 | import java.lang.annotation.Retention; 44 | import java.lang.annotation.RetentionPolicy; 45 | import java.lang.annotation.Target; 46 | 47 | /** 48 | *

This annotation identifies the custom constructor or factory method to use when creating an instance 49 | * of the associated class.

50 | * 51 | *

Only one constructor or static factory method can be annotated with {@code JsonbCreator} in a given class.

52 | * 53 | *

The {@code @JsonbCreator} annotation is intended to be used with constructors/methods with parameters. 54 | * Such parameters could be annotated for instance with {@code @JsonbProperty}.

55 | * 56 | *

Usage

57 | *

The {@code @JsonbCreator} annotation can be used with the followingprogram elements:

58 | *
    59 | *
  • method
  • 60 | *
  • constructor
  • 61 | *
62 | * 63 | * @since JSON Binding 1.0 64 | */ 65 | @JsonbAnnotation 66 | @Retention(RetentionPolicy.RUNTIME) 67 | @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) 68 | public @interface JsonbCreator { 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbDateFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | package javax.json.bind.annotation; 41 | 42 | import java.lang.annotation.ElementType; 43 | import java.lang.annotation.Retention; 44 | import java.lang.annotation.RetentionPolicy; 45 | import java.lang.annotation.Target; 46 | 47 | /** 48 | *

Annotation provides way how to set custom date format to field or JavaBean property.

49 | * 50 | *

The pattern format is specified in {@link java.time.format.DateTimeFormatter}

51 | * 52 | *

Usage

53 | *

The {@code @JsonbDateFormat} annotation can be used with the following program elements:

54 | *
    55 | *
  • field
  • 56 | *
  • getter/setter
  • 57 | *
  • type
  • 58 | *
  • parameter
  • 59 | *
  • package
  • 60 | *
61 | * 62 | * @since JSON Binding 1.0 63 | */ 64 | @JsonbAnnotation 65 | @Retention(RetentionPolicy.RUNTIME) 66 | @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, 67 | ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER, ElementType.PACKAGE}) 68 | public @interface JsonbDateFormat { 69 | 70 | /** 71 | * Value that indicates that default {@link java.util.Locale}. 72 | */ 73 | String DEFAULT_LOCALE = "##default"; 74 | 75 | /** 76 | * Value that indicates the default format. 77 | */ 78 | String DEFAULT_FORMAT = "##default"; 79 | 80 | /** 81 | * Special date format which serializes given date as milliseconds. 82 | * Such date is serialized as a number. 83 | */ 84 | String TIME_IN_MILLIS = "##time-in-millis"; 85 | 86 | /** 87 | * Specifies the date pattern to use. 88 | * 89 | * @return Date pattern to use. 90 | */ 91 | String value() default DEFAULT_FORMAT; 92 | 93 | /** 94 | * Custom {@link java.util.Locale} to use. 95 | * 96 | * @return Locale to use. 97 | */ 98 | String locale() default DEFAULT_LOCALE; 99 | 100 | } 101 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbNillable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.annotation; 42 | 43 | import java.lang.annotation.Retention; 44 | import java.lang.annotation.RetentionPolicy; 45 | import java.lang.annotation.Target; 46 | 47 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 48 | import static java.lang.annotation.ElementType.PACKAGE; 49 | import static java.lang.annotation.ElementType.TYPE; 50 | 51 | /** 52 | *

Specifies how fields having null values are serialized into JSON.

53 | * 54 | *

There are two possible values which can be specified. In case of true, fields are serialized as 55 | * key/value pair with value null. In case of false, fields will not be serialized (default behaviour).

56 | * 57 | *

Annotation can be specified on type or on package and affects all underlying properties and classes.,

58 | * 59 | *

For similar functionality on a property level see {@link JsonbProperty}. 60 | * 61 | * @since JSON Binding 1.0 62 | */ 63 | @JsonbAnnotation 64 | @Retention(RetentionPolicy.RUNTIME) 65 | @Target({ANNOTATION_TYPE, TYPE, PACKAGE}) 66 | public @interface JsonbNillable { 67 | 68 | /** 69 | * Switches on/off serialization of properties with null value. 70 | * 71 | * @return True if field with null value should be serialized as key/value pair into JSON with null value. 72 | */ 73 | boolean value() default true; 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbNumberFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | package javax.json.bind.annotation; 41 | 42 | import java.lang.annotation.ElementType; 43 | import java.lang.annotation.Retention; 44 | import java.lang.annotation.RetentionPolicy; 45 | import java.lang.annotation.Target; 46 | 47 | /** 48 | *

Annotation provides way how to set custom number format to field or JavaBean property.

49 | * 50 | *

The pattern format is specified in {@link java.text.DecimalFormat}

51 | * 52 | *

Usage

53 | *

The {@code @JsonbNumberFormat} annotation can be used with the following program elements:

54 | *
    55 | *
  • field
  • 56 | *
  • getter/setter
  • 57 | *
  • type
  • 58 | *
  • parameter
  • 59 | *
  • package
  • 60 | *
61 | * 62 | * @since JSON Binding 1.0 63 | */ 64 | @JsonbAnnotation 65 | @Retention(RetentionPolicy.RUNTIME) 66 | @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, 67 | ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER, ElementType.PACKAGE}) 68 | public @interface JsonbNumberFormat { 69 | 70 | /** 71 | * Value that indicates that default {@link java.util.Locale}. 72 | */ 73 | String DEFAULT_LOCALE = "##default"; 74 | 75 | /** 76 | * Specifies the number pattern to use. 77 | * 78 | * @return Number pattern to use. 79 | */ 80 | String value() default ""; 81 | 82 | /** 83 | * Custom {@link java.util.Locale} to use. 84 | * 85 | * @return Custom locale to use. 86 | */ 87 | String locale() default DEFAULT_LOCALE; 88 | } 89 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.annotation; 42 | 43 | import java.lang.annotation.ElementType; 44 | import java.lang.annotation.Retention; 45 | import java.lang.annotation.RetentionPolicy; 46 | import java.lang.annotation.Target; 47 | 48 | /** 49 | *

Allows customization of field (or JavaBean property) name.This name is used either in serialization or 50 | * in deserialization.

51 | * 52 | *

Usage

53 | *

The {@code @JsonbProperty} annotation can be used with the following program elements:

54 | *
    55 | *
  • a JavaBean property
  • 56 | *
  • field
  • 57 | *
  • parameter
  • 58 | *
59 | * 60 | * @since JSON Binding 1.0 61 | */ 62 | @JsonbAnnotation 63 | @Retention(RetentionPolicy.RUNTIME) 64 | @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 65 | public @interface JsonbProperty { 66 | 67 | /** 68 | * Customized name of the field (or JavaBean property). 69 | * 70 | * @return Customized property name. 71 | */ 72 | String value() default ""; 73 | 74 | /** 75 | * Switches o/off serialization of null values. 76 | * 77 | * @return True if field with null value should be serialized as key/value pair into JSON with null value. 78 | */ 79 | boolean nillable() default false; 80 | } 81 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbPropertyOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.annotation; 42 | 43 | import java.lang.annotation.ElementType; 44 | import java.lang.annotation.Retention; 45 | import java.lang.annotation.RetentionPolicy; 46 | import java.lang.annotation.Target; 47 | 48 | /** 49 | *

Specifies order in which properties are serialized.

50 | * 51 | *

Partial mapping can also be specified. In that case, properties included 52 | * in annotation declaration will be serialized first (in defined order), followed 53 | * by any properties not included in the definition. The order of properties not 54 | * included in the definition is not guaranteed.

55 | * 56 | * @since JSON Binding 1.0 57 | */ 58 | @JsonbAnnotation 59 | @Retention(RetentionPolicy.RUNTIME) 60 | @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) 61 | public @interface JsonbPropertyOrder { 62 | 63 | /** 64 | * Order in which properties are serialized. Names must correspond to original 65 | * names defined in Java class before any customization applied. 66 | * 67 | * @return Array of property names which defines an order. 68 | */ 69 | String[] value(); 70 | } 71 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbTransient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.annotation; 42 | 43 | import java.lang.annotation.Retention; 44 | import java.lang.annotation.RetentionPolicy; 45 | import java.lang.annotation.Target; 46 | 47 | import static java.lang.annotation.ElementType.FIELD; 48 | import static java.lang.annotation.ElementType.METHOD; 49 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 50 | 51 | /** 52 | *

Prevents mapping of a Java Bean property, field or type to JSON representation.

53 | * 54 | *

Usage

55 | *

The {@code @JsonbTransient} annotation can be used with the following program elements:

56 | *
    57 | *
  • getter/setter
  • 58 | *
  • field
  • 59 | *
60 | * 61 | *

{@code @JsonbTransient} is mutually exclusive with all other JSON Binding defined annotations.

62 | * 63 | *

If a class field is annotated with {@code @JsonbTransient}, exception is thrown when this field, 64 | * getter or setter is annotated with other JSON Binding annotations.

65 | * 66 | *

If a getter is annotated with {@code @JsonbTransient}, exception is thrown if when the field 67 | * or this getter are annotated with other JSON Binding annotations. Exception is not thrown 68 | * if JSON Binding annotations are presented on the setter.

69 | * 70 | *

If a setter is annotated with {@code @JsonbTransient}, exception is thrown if when the field 71 | * or this setter are annotated with other JSON Binding annotations. Exception is not thrown 72 | * if JSON Binding annotations are presented on the getter.

73 | * 74 | * @since JSON Binding 1.0 75 | */ 76 | @JsonbAnnotation 77 | @Retention(RetentionPolicy.RUNTIME) 78 | @Target({ANNOTATION_TYPE, FIELD, METHOD}) 79 | public @interface JsonbTransient { } 80 | 81 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbTypeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | package javax.json.bind.annotation; 41 | 42 | import javax.json.bind.adapter.JsonbAdapter; 43 | import java.lang.annotation.ElementType; 44 | import java.lang.annotation.Retention; 45 | import java.lang.annotation.RetentionPolicy; 46 | import java.lang.annotation.Target; 47 | 48 | /** 49 | *

Annotation provides way how to set custom JsonbAdapter to field or JavaBean property.

50 | * 51 | *

Usage

52 | *

The {@code @JsonbTypeAdapter} annotation can be used with the following program elements:

53 | *
    54 | *
  • type
  • 55 | *
  • field
  • 56 | *
  • method
  • 57 | *
58 | * 59 | * @since JSON Binding 1.0 60 | */ 61 | @JsonbAnnotation 62 | @Retention(RetentionPolicy.RUNTIME) 63 | @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD}) 64 | public @interface JsonbTypeAdapter { 65 | 66 | /** 67 | * Custom JsonbAdapter which provides custom mapping for given field or JavaBean property. 68 | * 69 | * @return Adapter to use. 70 | */ 71 | Class value(); 72 | } 73 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbTypeDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | 42 | package javax.json.bind.annotation; 43 | 44 | 45 | import javax.json.bind.serializer.JsonbDeserializer; 46 | import java.lang.annotation.ElementType; 47 | import java.lang.annotation.Retention; 48 | import java.lang.annotation.RetentionPolicy; 49 | import java.lang.annotation.Target; 50 | 51 | /** 52 | *

53 | * Annotation provides way how to set custom JsonbDeserializer to field or JavaBean property. 54 | *

55 | * 56 | *

Usage

57 | *

The {@code @JsonbDeserializer} annotation can be used with the following 58 | * program elements: 59 | *

    60 | *
  • type
  • 61 | *
  • field
  • 62 | *
  • method
  • 63 | *
64 | * 65 | * @since JSON Binding 1.0 66 | */ 67 | @JsonbAnnotation 68 | @Retention(RetentionPolicy.RUNTIME) 69 | @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD}) 70 | public @interface JsonbTypeDeserializer { 71 | 72 | /** 73 | * Custom {@link JsonbDeserializer} which provides custom mapping for given field or JavaBean property. 74 | * 75 | * @return Deserializer to use. 76 | */ 77 | Class value(); 78 | } 79 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbTypeSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | 42 | package javax.json.bind.annotation; 43 | 44 | 45 | import javax.json.bind.serializer.JsonbSerializer; 46 | import java.lang.annotation.ElementType; 47 | import java.lang.annotation.Retention; 48 | import java.lang.annotation.RetentionPolicy; 49 | import java.lang.annotation.Target; 50 | 51 | /** 52 | *

Annotation provides way how to set custom JsonbSerializer to field or JavaBean property.

53 | * 54 | *

Usage

55 | *

The {@code @JsonbSerializer} annotation can be used with the following program elements:

56 | *
    57 | *
  • type
  • 58 | *
  • field
  • 59 | *
  • method
  • 60 | *
61 | * 62 | * @since JSON Binding 1.0 63 | */ 64 | @JsonbAnnotation 65 | @Retention(RetentionPolicy.RUNTIME) 66 | @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD}) 67 | public @interface JsonbTypeSerializer { 68 | 69 | /** 70 | * Custom {@link JsonbSerializer} which provides custom mapping for given field or JavaBean property. 71 | * 72 | * @return Serializaer to use. 73 | */ 74 | Class value(); 75 | } 76 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/JsonbVisibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.annotation; 42 | 43 | import javax.json.bind.config.PropertyVisibilityStrategy; 44 | import java.lang.annotation.ElementType; 45 | import java.lang.annotation.Retention; 46 | import java.lang.annotation.RetentionPolicy; 47 | import java.lang.annotation.Target; 48 | 49 | /** 50 | *

Annotation provides way how to customize visibility strategy of the JSON Binding.

51 | * 52 | *

It allows for example to specify, that only public getters and setter should be visible.

53 | * 54 | *

Usage

55 | *

The {@code @JsonbVisibility} annotation can be used with the following program elements:

56 | *
    57 | *
  • type
  • 58 | *
  • package
  • 59 | *
60 | * 61 | * @since JSON Binding 1.0 62 | */ 63 | @JsonbAnnotation 64 | @Retention(RetentionPolicy.RUNTIME) 65 | @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.PACKAGE}) 66 | public @interface JsonbVisibility { 67 | 68 | /** 69 | * Custom property visibility strategy used to resolve visibility of the members. 70 | * 71 | * @return Visibility strategy to use. 72 | */ 73 | Class value(); 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | /** 42 | *

43 | * Defines annotations for customizing the mapping between Java program elements 44 | * and JSON documents. 45 | *

46 | * 47 | * @since JSON Binding 1.0 48 | */ 49 | package javax.json.bind.annotation; 50 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/config/BinaryDataStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.config; 42 | 43 | /** 44 | * Specifies predefined binary data handling strategies. 45 | * This strategy can be set via {@link javax.json.bind.JsonbConfig#withBinaryDataStrategy(String)}. 46 | * 47 | * @see javax.json.bind.JsonbConfig 48 | * @since JSON Binding 1.0 49 | */ 50 | public final class BinaryDataStrategy { 51 | 52 | /** 53 | * Private constructor to disallow instantiation. 54 | */ 55 | private BinaryDataStrategy() { }; 56 | 57 | /** 58 | * Using this strategy, binary data is encoded as a byte array. 59 | * Default encoding strategy. 60 | */ 61 | public static final String BYTE = "BYTE"; 62 | 63 | /** 64 | * Using this strategy, binary data is encoded using 65 | * the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. 66 | */ 67 | public static final String BASE_64 = "BASE_64"; 68 | 69 | /** 70 | * Using this strategy, binary data is encoded using 71 | * the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648. 72 | */ 73 | public static final String BASE_64_URL = "BASE_64_URL"; 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/config/PropertyNamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.config; 42 | 43 | /** 44 | *

Allows to define custom property naming strategy. 45 | * Specifies predefined property naming strategies. 46 | * Does not override JsonbProperty value.

47 | * 48 | *

This strategy can be set via {@link javax.json.bind.JsonbConfig}.

49 | * 50 | * @see javax.json.bind.JsonbConfig 51 | * @since JSON Binding 1.0 52 | */ 53 | public interface PropertyNamingStrategy { 54 | /** 55 | * Using this strategy, the property name is unchanged. 56 | */ 57 | String IDENTITY = "IDENTITY"; 58 | 59 | /** 60 | * Using this strategy, the property name is transformed to lower case with dashes. 61 | * The dashes are on the positions of different case boundaries in the original field name (camel case). 62 | */ 63 | String LOWER_CASE_WITH_DASHES = "LOWER_CASE_WITH_DASHES"; 64 | 65 | /** 66 | * Using this strategy, the property name is transformed to lower case with underscores. 67 | * The underscores are on the positions of different case boundaries in the original field name (camel case). 68 | */ 69 | String LOWER_CASE_WITH_UNDERSCORES = "LOWER_CASE_WITH_UNDERSCORES"; 70 | 71 | /** 72 | * Using this strategy, the first character will be capitalized. 73 | */ 74 | String UPPER_CAMEL_CASE = "UPPER_CAMEL_CASE"; 75 | 76 | /** 77 | * Using this strategy, the first character will be capitalized and the words 78 | * will be separated by spaces. 79 | */ 80 | String UPPER_CAMEL_CASE_WITH_SPACES = "UPPER_CAMEL_CASE_WITH_SPACES"; 81 | 82 | /** 83 | * Using this strategy, the serialization will be same as identity. 84 | * Deserialization will be case insensitive. E.g. property in JSON with name 85 | * PropertyNAME, will be mapped to field propertyName. 86 | */ 87 | String CASE_INSENSITIVE = "CASE_INSENSITIVE"; 88 | 89 | /** 90 | * Translates the property name into its JSON field name representation. 91 | * 92 | * @param propertyName Name of the property to translate. 93 | * @return Translated JSON field name. 94 | */ 95 | String translateName(String propertyName); 96 | } 97 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/config/PropertyOrderStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.config; 42 | 43 | /** 44 | * Specifies predefined property order strategies. 45 | * This strategy can be set via {@link javax.json.bind.JsonbConfig#withPropertyOrderStrategy(String)} 46 | * 47 | * @see javax.json.bind.JsonbConfig 48 | * @since JSON Binding 1.0 49 | */ 50 | public final class PropertyOrderStrategy { 51 | 52 | /** 53 | * Private constructor to disallow instantiation. 54 | */ 55 | private PropertyOrderStrategy() { }; 56 | 57 | /** 58 | * Using this strategy, the order of properties is lexicographical. 59 | */ 60 | public static final String LEXICOGRAPHICAL = "LEXICOGRAPHICAL"; 61 | 62 | /** 63 | * Using this strategy, the order of properties 64 | * is not guaranteed to retain any order. 65 | */ 66 | public static final String ANY = "ANY"; 67 | 68 | /** 69 | * Using this strategy, the order of properties is in reverse order 70 | * to lexicographical order. 71 | */ 72 | public static final String REVERSE = "REVERSE"; 73 | } 74 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/config/PropertyVisibilityStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 javax.json.bind.config; 42 | 43 | import java.lang.reflect.Field; 44 | import java.lang.reflect.Method; 45 | 46 | /** 47 | *

Provides mechanism how to define customized property visibility strategy.

48 | * 49 | *

This strategy can be set via {@link javax.json.bind.JsonbConfig}.

50 | * 51 | * @see javax.json.bind.JsonbConfig 52 | * @since JSON Binding 1.0 53 | */ 54 | public interface PropertyVisibilityStrategy { 55 | 56 | /** 57 | * Responds whether the given field should be considered 58 | * as the JsonbProperty. 59 | * 60 | * @param field member of the class 61 | * @return true if member should be visible 62 | */ 63 | boolean isVisible(Field field); 64 | 65 | /** 66 | * Responds whether the given method should be considered 67 | * as the JsonbProperty. 68 | * 69 | * @param method member of the class 70 | * @return true if member should be visible 71 | */ 72 | boolean isVisible(Method method); 73 | } 74 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | /** 42 | *

43 | * Defines strategies and policies for customizing the mapping between Java program elements 44 | * and JSON documents. 45 | *

46 | * 47 | * @since JSON Binding 1.0 48 | */ 49 | package javax.json.bind.config; 50 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | /** 42 | * Provides JSON Binding API, which enables binding Java objects from and to 43 | * JSON documents. 44 | * 45 | * Main user entry points to the API is {@link javax.json.bind.JsonbBuilder JsonbBuilder} 46 | * which builds {@link javax.json.bind.Jsonb Jsonb} instances. 47 | * 48 | * @since JSON Binding 1.0 49 | */ 50 | package javax.json.bind; 51 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/serializer/DeserializationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.serializer; 42 | 43 | 44 | import javax.json.stream.JsonParser; 45 | import java.lang.reflect.Type; 46 | 47 | /** 48 | * Provides JSONB Mapper functionality on top of JSONP parser. 49 | * 50 | * @see JsonbDeserializer 51 | * @since JSON Binding 1.0 52 | */ 53 | public interface DeserializationContext { 54 | 55 | /** 56 | *

57 | * Deserialize JSON stream into instance of provided class using {@link javax.json.stream.JsonParser}. 58 | * JsonParser cursor have to be at KEY_NAME before START_OBJECT / START_ARRAY, or at START_OBJECT / START_ARRAY 59 | * to call this method. After deserialization is complete JsonParser will be at END_OBJECT / END_ARRAY 60 | * for deserialized JSON structure. 61 | *

62 | * 63 | *

64 | * If method is called for the same type, which is deserializer bound to, deserializer recursion is suppressed. 65 | * Otherwise deserializers are reentrant during deserialization process started by this method. 66 | *

67 | * 68 | * {@link JsonParser} instance of JSONB runtime is shared with custom deserializer. 69 | * 70 | * @param clazz 71 | * Type to deserialize into. No arg constructor required. 72 | * @param parser 73 | * JSONP parser to drive. 74 | * @param 75 | * Type of class. 76 | * @return Deserialized instance. 77 | */ 78 | T deserialize(Class clazz, JsonParser parser); 79 | 80 | /** 81 | *

82 | * Deserialize JSON stream into instance of provided class using {@link javax.json.stream.JsonParser}. 83 | * JsonParser cursor have to be at KEY_NAME before START_OBJECT / START_ARRAY, or at START_OBJECT / START_ARRAY 84 | * to call this method. After deserialization is complete JsonParser will be at END_OBJECT / END_ARRAY 85 | * for deserialized JSON structure. 86 | *

87 | * 88 | *

89 | * If method is called for the same type, which is deserializer bound to, deserializer recursion is suppressed. 90 | * Otherwise deserializers are reentrant during deserialization process started by this method. 91 | *

92 | * 93 | * {@link JsonParser} instance of JSONB runtime is shared with custom deserializer. 94 | * 95 | * @param type 96 | * Type to deserialize into. No arg constructor required. 97 | * @param parser 98 | * JSONP parser to drive. 99 | * @param 100 | * Type to deserialize into. 101 | * @return Deserialized instance. 102 | */ 103 | T deserialize(Type type, JsonParser parser); 104 | } 105 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/serializer/JsonbDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.serializer; 42 | 43 | import javax.json.stream.JsonParser; 44 | import java.lang.reflect.Type; 45 | 46 | /** 47 | *

Interface representing a custom deserializer for a given type. It provides a low-level API for java object 48 | * deserialization from JSON stream using {@link JsonParser}. Unlike {@link javax.json.bind.adapter.JsonbAdapter}, 49 | * which acts more as converter from one java type to another, deserializer provides more fine grained control over 50 | * deserialization process.

51 | * 52 | *

{@link DeserializationContext} acts as JSONB runtime, able to deserialize any java object provided.

53 | * 54 | *

Sample of custom Deserializer:

55 | *
 56 |  *     class Box {
 57 |  *         public BoxInner boxInnerObject;
 58 |  *         public String name;
 59 |  *     }
 60 |  *
 61 |  *     BoxDeserializer implements JsonbDeserializer<Box> {
 62 |  *         public Box deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
 63 |  *             Box = new Box();
 64 |  *
 65 |  *             while (parser.hasNext()) {
 66 |  *                 Event event = parser.next();
 67 |  *
 68 |  *                 if (event == JsonParser.Event.KEY_NAME && parser.getString().equals("boxInnerObject") {
 69 |  *                     // Deserialize inner object
 70 |  *                     box.boxInnerObject = ctx.deserialize(BoxInner.class, jsonParser);
 71 |  *
 72 |  *                 } else if (event == JsonParser.Event.KEY_NAME && parser.getString().equals("name") {
 73 |  *                     // Deserialize name property
 74 |  *                     parser.next(); // move to VALUE
 75 |  *                     box.name = parser.getString();
 76 |  *                 }
 77 |  *             }
 78 |  *
 79 |  *             return box;
 80 |  *         }
 81 |  *     }
 82 |  * 
83 | * 84 | *

Deserializers are registered using {@link javax.json.bind.JsonbConfig#withDeserializers(JsonbDeserializer[])} 85 | * method or using {@link javax.json.bind.annotation.JsonbTypeDeserializer} annotation on type.

86 | * 87 | * @param Type to bind deserializer for. 88 | * @see javax.json.bind.JsonbConfig 89 | * @see javax.json.bind.annotation.JsonbTypeDeserializer 90 | * @see JsonbSerializer 91 | * @see javax.json.bind.adapter.JsonbAdapter 92 | * @since JSON Binding 1.0 93 | */ 94 | public interface JsonbDeserializer { 95 | 96 | /** 97 | * Deserialize JSON stream into object. 98 | * 99 | * @param parser 100 | * Json parser. 101 | * @param ctx 102 | * Deserialization context. 103 | * @param rtType 104 | * Type of returned object. 105 | * @return Deserialized instance. 106 | */ 107 | T deserialize(JsonParser parser, DeserializationContext ctx, Type rtType); 108 | } 109 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/serializer/JsonbSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.serializer; 42 | 43 | import javax.json.stream.JsonGenerator; 44 | 45 | /** 46 | *

Interface representing a custom serializer for given type. Unlike {@link javax.json.bind.adapter.JsonbAdapter} 47 | * serializer provides more fine grained control over serialization process by writing java object directly into 48 | * JSON stream using {@link JsonGenerator}. {@link SerializationContext} acts as JSONB runtime, able to serialize 49 | * any java object provided.

50 | * 51 | *

Serializers are registered using {@link javax.json.bind.JsonbConfig#withSerializers(JsonbSerializer[])} 52 | * method or using {@link javax.json.bind.annotation.JsonbTypeSerializer} annotation on type

53 | * 54 | *

Sample of custom Serializer:

55 | *
56 |  * class Box {
57 |  *     public BoxInner boxInnerObject;
58 |  *     public String name;
59 |  * }
60 |  *
61 |  * class BoxSerializer implements JsonbSerializer<Box> {
62 |  *      public void serialize(Box box, JsonGenerator generator, SerializationContext ctx) {
63 |  *          generator.write("name", box.name);
64 |  *          ctx.serialize("boxInnerObject", generator);
65 |  *      }
66 |  * }
67 |  * 
68 | * 69 | * @param Type to bind serializer for. 70 | * @see javax.json.bind.JsonbConfig 71 | * @see javax.json.bind.annotation.JsonbTypeSerializer 72 | * @see JsonbDeserializer 73 | * @see javax.json.bind.adapter.JsonbAdapter 74 | * @since JSON Binding 1.0 75 | */ 76 | public interface JsonbSerializer { 77 | 78 | /** 79 | * Serializes object into JSON stream. 80 | * 81 | * @param obj 82 | * Object to serialize. 83 | * @param generator 84 | * JSON generator used to write java object to JSON stream. 85 | * @param ctx 86 | * JSONB mapper context. Use it to serialize sub-objects. 87 | */ 88 | void serialize(T obj, JsonGenerator generator, SerializationContext ctx); 89 | } 90 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/serializer/SerializationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.serializer; 42 | 43 | import javax.json.stream.JsonGenerator; 44 | 45 | /** 46 | * Provides JSONB internals for custom serializers. 47 | * 48 | * @see JsonbSerializer 49 | * @since JSON Binding 1.0 50 | */ 51 | public interface SerializationContext { 52 | 53 | /** 54 | * Serializes arbitrary object to JSON, using current {@link javax.json.stream.JsonGenerator} instance. 55 | * Serialization is ran as serialization of a root type from user {@link JsonbSerializer}. {@link JsonGenerator} 56 | * instance is shared with JSONB and user serializer. 57 | * 58 | * @param key 59 | * JSON key name. 60 | * @param object 61 | * Object to serialize. 62 | * @param generator 63 | * JSONP generator to serialize with. 64 | * @param 65 | * Type of serialized object. 66 | */ 67 | void serialize(String key, T object, JsonGenerator generator); 68 | 69 | /** 70 | * Serializes arbitrary object to JSON, using current {@link javax.json.stream.JsonGenerator} instance. 71 | * Serialization is ran as serialization of a root type from user {@link JsonbSerializer}. {@link JsonGenerator} 72 | * instance is shared with JSONB and user serializer. 73 | * 74 | * Method without key parameter is intended to serialize inside JSON_ARRAYs. 75 | * 76 | * @param object 77 | * Object to serialize. 78 | * @param generator 79 | * JSONP generator to serialize with. 80 | * @param 81 | * Type of serialized object. 82 | */ 83 | void serialize(T object, JsonGenerator generator); 84 | } 85 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/serializer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 | /** 42 | *

43 | * Defines serializer depending classes. 44 | *

45 | * @since JSON Binding 1.0 46 | */ 47 | package javax.json.bind.serializer; 48 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/spi/JsonbProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016, 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 javax.json.bind.spi; 42 | 43 | import javax.json.bind.JsonbBuilder; 44 | import javax.json.bind.JsonbException; 45 | import java.util.Iterator; 46 | import java.util.ServiceLoader; 47 | 48 | /** 49 | * Service provider for JSON Binding implementations. 50 | * 51 | * Provider implementors must implement all abstract methods. 52 | * 53 | * API clients can obtain instance of default provider by calling: 54 | *
 55 |  * {@code
 56 |  * JsonbProvider provider = JsonbProvider.provider();
 57 |  * }}
58 | * 59 | * Specific provider instance lookup: 60 | *
 61 |  * {@code
 62 |  * JsonbProvider provider;
 63 |  * try {
 64 |  *   JsonbProvider.provider("foo.bar.ProviderImpl");
 65 |  * } catch (JsonbException e) {
 66 |  *   // provider not found or could not be instantiated
 67 |  * }}
68 | * where '{@code foo.bar.ProviderImpl}' is a vendor implementation class extending 69 | * {@link javax.json.bind.spi.JsonbProvider} and identified to service loader as 70 | * specified in {@link java.util.ServiceLoader} documentation. 71 | *
72 | * All the methods in this class are allowed to be called by multiple concurrent 73 | * threads. 74 | * 75 | * @see javax.json.bind.Jsonb 76 | * @see java.util.ServiceLoader 77 | * @since JSON Binding 1.0 78 | */ 79 | public abstract class JsonbProvider { 80 | 81 | /** 82 | * A constant representing the name of the default 83 | * {@link javax.json.bind.spi.JsonbProvider JsonbProvider} implementation class. 84 | */ 85 | private static final String DEFAULT_PROVIDER = "org.eclipse.yasson.JsonBindingProvider"; 86 | 87 | /** 88 | * Protected constructor. 89 | */ 90 | protected JsonbProvider() { 91 | } 92 | 93 | /** 94 | * Creates a JSON Binding provider object by using the 95 | * {@link java.util.ServiceLoader#load(Class)} method. The first provider of 96 | * {@code JsonbProvider} class from list of providers returned by 97 | * {@code ServiceLoader.load} call is returned. If there are no available 98 | * service providers, this method tries to load the default service provider using 99 | * {@link Class#forName(String)} method. 100 | * 101 | * @see java.util.ServiceLoader 102 | * 103 | * @throws JsonbException if there is no provider found, or there is a problem 104 | * instantiating the provider instance. 105 | * 106 | * @return {@code JsonbProvider} instance 107 | */ 108 | @SuppressWarnings("UseSpecificCatch") 109 | public static JsonbProvider provider() { 110 | ServiceLoader loader = ServiceLoader.load(JsonbProvider.class); 111 | Iterator it = loader.iterator(); 112 | if (it.hasNext()) { 113 | return it.next(); 114 | } 115 | 116 | try { 117 | Class clazz = Class.forName(DEFAULT_PROVIDER); 118 | return (JsonbProvider) clazz.newInstance(); 119 | } catch (ClassNotFoundException x) { 120 | throw new JsonbException("JSON Binding provider " + DEFAULT_PROVIDER + " not found", x); 121 | } catch (Exception x) { 122 | throw new JsonbException("JSON Binding provider " + DEFAULT_PROVIDER 123 | + " could not be instantiated: " + x, x); 124 | } 125 | } 126 | 127 | /** 128 | * Creates a JSON Binding provider object by using the 129 | * {@link java.util.ServiceLoader#load(Class)} method, matching {@code providerName}. 130 | * The first provider of {@code JsonbProvider} class from list of providers returned by 131 | * {@code ServiceLoader.load} call, matching providerName is returned. 132 | * If no such provider is found, JsonbException is thrown. 133 | * 134 | * @param providerName 135 | * Class name ({@code class.getName()}) to be chosen from the list of providers 136 | * returned by {@code ServiceLoader.load(JsonbProvider.class)} call. 137 | * 138 | * @throws JsonbException if there is no provider found, or there is a problem 139 | * instantiating the provider instance. 140 | * 141 | * @throws NullPointerException if providerName is {@code null}. 142 | * 143 | * @see java.util.ServiceLoader 144 | * 145 | * @return {@code JsonbProvider} instance 146 | */ 147 | @SuppressWarnings("UseSpecificCatch") 148 | public static JsonbProvider provider(final String providerName) { 149 | if (providerName == null) { 150 | throw new IllegalArgumentException(); 151 | } 152 | ServiceLoader loader = ServiceLoader.load(JsonbProvider.class); 153 | Iterator it = loader.iterator(); 154 | while (it.hasNext()) { 155 | JsonbProvider provider = it.next(); 156 | if (providerName.equals(provider.getClass().getName())) { 157 | return provider; 158 | } 159 | } 160 | 161 | throw new JsonbException("JSON Binding provider " + providerName + " not found", 162 | new ClassNotFoundException(providerName)); 163 | } 164 | 165 | /** 166 | * Returns a new instance of {@link javax.json.bind.JsonbBuilder JsonbBuilder} class. 167 | * 168 | * {@link javax.json.bind.JsonbBuilder JsonbBuilder} provides necessary getter 169 | * methods to access required parameters. 170 | * 171 | * @return JsonbBuilder 172 | * A new instance of class implementing {@link javax.json.bind.JsonbBuilder}. 173 | * Always a non-null valid object. 174 | * 175 | * @see javax.json.bind.Jsonb 176 | * @see javax.json.bind.JsonbBuilder 177 | * 178 | * @throws JsonbException 179 | * If an error was encountered while creating the {@link JsonbBuilder} instance. 180 | */ 181 | public abstract JsonbBuilder create(); 182 | 183 | } 184 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/bind/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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 | /** 42 | * Service Provider Interface (SPI) to plug in implementations of JSON 43 | * Binding API {@link javax.json.bind.JsonbBuilder JsonbBuilder} objects. 44 | * 45 | *

{@link javax.json.bind.spi.JsonbProvider JsonbProvider} is an abstract class 46 | * that provides a service for creating JSON Binding builder implementation instances. 47 | * A service provider for {@link javax.json.bind.spi.JsonbProvider JsonbProvider} provides an 48 | * specific implementation by subclassing and implementing the 49 | * {@link javax.json.bind.JsonbBuilder JsonbBuilder} creation 50 | * method(s) in {@link javax.json.bind.spi.JsonbProvider JsonbProvider}. 51 | * 52 | *

The API locates and loads providers using {@link java.util.ServiceLoader ServiceLoader}. 53 | * 54 | * @since JSON Binding 1.0 55 | */ 56 | package javax.json.bind.spi; 57 | -------------------------------------------------------------------------------- /api/src/main/java/module-info.java: -------------------------------------------------------------------------------- 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 | 42 | module java.json.bind { 43 | exports javax.json.bind; 44 | exports javax.json.bind.adapter; 45 | exports javax.json.bind.annotation; 46 | exports javax.json.bind.config; 47 | exports javax.json.bind.serializer; 48 | exports javax.json.bind.spi; 49 | 50 | requires java.json; 51 | requires java.logging; 52 | 53 | uses javax.json.bind.spi.JsonbProvider; 54 | } -------------------------------------------------------------------------------- /api/src/main/javadoc/doc-files/spec-license.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JSR 367 Java API for JSON Binding 1.0 Final Release License 5 | 6 | 7 | 8 |

JSR-000367 JavaTM API for JSON Binding 1.0 Final Release 9 |

10 |

11 | ORACLE AMERICA, INC. IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS LICENSE AGREEMENT ("AGREEMENT"). PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY. BY DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THEM, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THIS PAGE AND THE DOWNLOADING PROCESS WILL NOT CONTINUE. 12 |

13 |

14 | Specification: JSR-367 Java API for JSON Binding 15 | ("Specification")
16 | Version: 1.0
17 | Status: Final Release
18 | Release: June 2017
19 | Copyright 2017 Oracle America, Inc.
20 | 500 Oracle Parkway, Redwood City, California 94065, U.S.A
21 | All rights reserved.

22 |

23 | NOTICE 24 |

25 |

26 | The Specification is protected by copyright and the information described therein may be protected by one or more U.S. patents, foreign patents, or pending applications. Except as provided under the following license, no part of the Specification may be reproduced in any form by any means without the prior written authorization of Oracle America, Inc. ("Oracle") and its licensors, if any. Any use of the Specification and the information described therein will be governed by the terms and conditions of this Agreement. 27 |

28 | Subject to the terms and conditions of this license, including your compliance with Paragraphs 1 and 2 below, Oracle hereby grants you a fully-paid, non-exclusive, non-transferable, limited license (without the right to sublicense) under Oracle's intellectual property rights to:

29 | 1.Review the Specification for the purposes of evaluation. This includes: (i) developing implementations of the Specification for your internal, non-commercial use; (ii) discussing the Specification with any third party; and (iii) excerpting brief portions of the Specification in oral or written communications which discuss the Specification provided that such excerpts do not in the aggregate constitute a significant portion of the Technology.

30 | 31 | 2.Distribute implementations of the Specification to third parties for their testing and evaluation use, provided that any such implementation:
32 | (i) does not modify, subset, superset or otherwise extend the Licensor Name Space, or include any public or protected packages, classes, Java interfaces, fields or methods within the Licensor Name Space other than those required/authorized by the Specification or Specifications being implemented;
33 | (ii) is clearly and prominently marked with the word "UNTESTED" or "EARLY ACCESS" or "INCOMPATIBLE" or "UNSTABLE" or "BETA" in any list of available builds and in proximity to every link initiating its download, where the list or link is under Licensee's control; and
34 | (iii) includes the following notice: "This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."

35 | 36 | The grant set forth above concerning your distribution of implementations of the specification is 37 | contingent upon your agreement to terminate development and distribution of your "early draft" 38 | implementation as soon as feasible following final completion of the specification. If you fail to do so, 39 | the foregoing grant shall be considered null and void.

40 | 41 | No provision of this Agreement shall be understood to restrict your ability to make and distribute to 42 | third parties applications written to the Specification.

43 | 44 | Other than this limited license, you acquire no right, title or interest in or to the Specification or any 45 | other Oracle intellectual property, and the Specification may only be used in accordance with the license 46 | terms set forth herein. This license will expire on the earlier of: (a) two (2) years from the date of 47 | Release listed above; (b) the date on which the final version of the Specification is publicly released; or 48 | (c) the date on which the Java Specification Request (JSR) to which the Specification corresponds is 49 | withdrawn. In addition, this license will terminate immediately without notice from Oracle if you fail to 50 | comply with any provision of this license. Upon termination, you must cease use of or destroy the 51 | Specification.

52 | 53 | "Licensor Name Space" means the public class or interface declarations whose names begin with "java", 54 | "javax", "com.oracle" or their equivalents in any subsequent naming convention adopted by Oracle 55 | through the Java Community Process, or any recognized successors or replacements thereof

56 | 57 | TRADEMARKS
58 | 59 | No right, title, or interest in or to any trademarks, service marks, or trade names of Oracle or Oracle's 60 | licensors is granted hereunder. Oracle, the Oracle logo, and Java are trademarks or registered 61 | trademarks of Oracle America, Inc. in the U.S. and other countries.

62 | 63 | DISCLAIMER OF WARRANTIES
64 | THE SPECIFICATION IS PROVIDED "AS IS" AND IS EXPERIMENTAL AND MAY CONTAIN DEFECTS OR 65 | DEFICIENCIES WHICH CANNOT OR WILL NOT BE CORRECTED BY ORACLE. ORACLE MAKES NO 66 | REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, 67 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT 68 | THAT THE CONTENTS OF THE SPECIFICATION ARE SUITABLE FOR ANY PURPOSE OR THAT ANY PRACTICE 69 | OR IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, 70 | COPYRIGHTS, TRADE SECRETS OR OTHER RIGHTS. This document does not represent any commitment to 71 | release or implement any portion of the Specification in any product.

72 | 73 | THE SPECIFICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES 74 | ARE PERIODICALLY ADDED TO THE INFORMATION THEREIN; THESE CHANGES WILL BE INCORPORATED 75 | INTO NEW VERSIONS OF THE SPECIFICATION, IF ANY. ORACLE MAY MAKE IMPROVEMENTS AND/OR 76 | CHANGES TO THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THE SPECIFICATION AT ANY 77 | TIME. Any use of such changes in the Specification will be governed by the then-current license for the 78 | applicable version of the Specification.

79 | 80 | LIMITATION OF LIABILITY
81 | TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL ORACLE OR ITS LICENSORS BE LIABLE FOR 82 | ANY DAMAGES, INCLUDING WITHOUT LIMITATION, LOST REVENUE, PROFITS OR DATA, OR FOR SPECIAL, 83 | INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS 84 | OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO ANY FURNISHING, PRACTICING, 85 | MODIFYING OR ANY USE OF THE SPECIFICATION, EVEN IF ORACLE AND/OR ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

86 | 87 | You will hold Oracle (and its licensors) harmless from any claims based on your use of the Specification for any purposes other than the limited right of evaluation as described above, and from any claims that later versions or releases of any Specification furnished to you are incompatible with the Specification provided to you under this license.

88 | 89 | RESTRICTED RIGHTS LEGEND
90 | If this Software is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's rights in the Software and accompanying documentation shall be only as set forth in this license; this is in accordance with 48 C.F.R. 227.7201 through 227.7202-4 (for Department of Defense (DoD) acquisitions) and with 48 C.F.R. 2.101 and 12.212 (for non-DoD acquisitions).

91 | REPORT
92 | You may wish to report any ambiguities, inconsistencies or inaccuracies you may find in connection with your evaluation of the Specification ("Feedback"). To the extent that you provide Oracle with any Feedback, you hereby: (i) agree that such Feedback is provided on a non-proprietary and non-confidential basis, and (ii) grant Oracle a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable license, with the right to sublicense through multiple levels of sublicensees, to incorporate, disclose, and use without limitation the Feedback for any purpose related to the Specification and future versions, implementations, and test suites thereof.

93 | 94 | GENERAL TERMS
95 | Any action related to this Agreement will be governed by California law and controlling U.S. federal law. The U.N. Convention for the International Sale of Goods and the choice of law rules of any jurisdiction will not apply. The Specification is subject to U.S. export control laws and may be subject to export or import regulations in other countries. Licensee agrees to comply strictly with all such laws and regulations and acknowledges that it has the responsibility to obtain such licenses to export, re-export or import as may be required after delivery to Licensee.

96 | 97 | This Agreement is the parties' entire agreement relating to its subject matter. It supersedes all prior or contemporaneous oral or written communications, proposals, conditions, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment, or other communication between the parties relating to its subject matter during the term of this Agreement. No modification to this Agreement will be binding, unless in writing and signed by an authorized representative of each party. 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /docs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 43 | 44 | 4.0.0 45 | 46 | 47 | net.java 48 | jvnet-parent 49 | 5 50 | 51 | 52 | javax.json.bind 53 | javax.json.bind-docs 54 | 1.0.0-SNAPSHOT 55 | pom 56 | JSON Binding Docs 57 | 58 | https://javaee.github.io/jsonb-spec 59 | 60 | 61 | Oracle Corporation 62 | http://www.oracle.com 63 | 64 | 65 | 66 | github 67 | https://github.com/javaee/jsonb-spec/issues 68 | 69 | 70 | 71 | 72 | JSON-B Discussion Group 73 | jsonb-spec@javaee.groups.io 74 | 75 | 76 | 77 | 78 | 79 | Dual license consisting of the CDDL v1.1 and GPL v2 80 | https://oss.oracle.com/licenses/CDDL+GPL-1.1 81 | repo 82 | 83 | 84 | 85 | 86 | scm:git:git://github.com/javaee/jsonb-spec.git 87 | scm:git:git@github.com:javaee/jsonb-spec.git 88 | https://github.com/javaee/jsonb-spec 89 | HEAD 90 | 91 | 92 | 93 | 94 | dmitry.kornilov@oracle.com 95 | maiden168 96 | Dmitry Kornilov 97 | Oracle 98 | 99 | Spec Lead 100 | 101 | CET 102 | 103 | 104 | roman.grigoriadi@oracle.com 105 | roman.grigoriadi 106 | Roman Grigoriadi 107 | Oracle 108 | 109 | Developer 110 | 111 | CET 112 | 113 | 114 | 115 | 116 | 1.5.5 117 | 1.5.0-alpha.14 118 | 1.5.5 119 | 9.1.8.0 120 | 2.0.2 121 | 122 | 123 | 124 | 125 | rubygems-proxy-releases2 126 | RubyGems.org Proxy (Releases) 127 | http://rubygems-proxy.torquebox.org/releases 128 | 129 | true 130 | 131 | 132 | false 133 | 134 | 135 | 136 | 137 | 138 | 139 | rubygems 140 | prawn 141 | ${rubygems.prawn.version} 142 | gem 143 | provided 144 | 145 | 146 | 147 | 148 | process-resources 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-enforcer-plugin 153 | 1.4.1 154 | 155 | 156 | enforce-versions 157 | 158 | enforce 159 | 160 | 161 | 162 | 163 | [1.8.0,1.9.0) 164 | You need JDK8 or lower 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | de.saumya.mojo 173 | gem-maven-plugin 174 | 1.0.10 175 | 176 | ${jruby.version} 177 | ${project.build.directory}/gems 178 | ${project.build.directory}/gems 179 | 180 | 181 | 182 | 183 | initialize 184 | 185 | 186 | 187 | 188 | 189 | org.asciidoctor 190 | asciidoctor-maven-plugin 191 | ${asciidoctor.maven.plugin.version} 192 | 193 | 194 | org.asciidoctor 195 | asciidoctorj-pdf 196 | ${asciidoctorj.pdf.version} 197 | 198 | 199 | org.jruby 200 | jruby-complete 201 | ${jruby.version} 202 | 203 | 204 | org.asciidoctor 205 | asciidoctorj 206 | ${asciidoctorj.version} 207 | 208 | 209 | 210 | src/docs 211 | user-guide.adoc 212 | ${project.build.directory}/gems-provided 213 | 214 | ${project.build.sourceDirectory} 215 | 216 | 217 | 218 | 219 | asciidoc-to-html 220 | generate-resources 221 | 222 | process-asciidoc 223 | 224 | 225 | html5 226 | coderay 227 | 228 | ./images 229 | left 230 | 3 231 | font 232 | true 233 | 234 | - 235 | true 236 | 237 | 238 | 239 | 240 | generate-pdf-doc-default-theme 241 | generate-resources 242 | 243 | process-asciidoc 244 | 245 | 246 | pdf 247 | rouge 248 | book 249 | 250 | font 251 | 252 | 253 | 254 | 3 255 | - 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | pdf 267 | 268 | 269 | 270 | org.asciidoctor 271 | asciidoctor-maven-plugin 272 | ${asciidoctor.maven.plugin.version} 273 | 274 | 275 | org.asciidoctor 276 | asciidoctorj-pdf 277 | ${asciidoctorj.pdf.version} 278 | 279 | 280 | 281 | 282 | generate-pdf-doc-default-theme 283 | generate-resources 284 | 285 | process-asciidoc 286 | 287 | 288 | pdf 289 | ${project.build.directory}/generated-docs-default-theme 290 | rouge 291 | book 292 | 293 | font 294 | 295 | 296 | 297 | - 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | -------------------------------------------------------------------------------- /etc/config/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 43 | 44 | 45 | 69 | 70 | 71 | 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 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 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 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | -------------------------------------------------------------------------------- /etc/config/copyright-exclude: -------------------------------------------------------------------------------- 1 | .apt 2 | .args 3 | .bundle 4 | .class 5 | .exe 6 | .gif 7 | .gitignore 8 | .ico 9 | .iml 10 | .ipr 11 | .iws 12 | .jar 13 | .jks 14 | .jpg 15 | .js 16 | .json 17 | .mm 18 | .ods 19 | .png 20 | .project 21 | .sql 22 | .svg 23 | .war 24 | .zip 25 | .dat 26 | /MANIFEST.MF 27 | /META-INF/services/ 28 | /README 29 | spec-license.html 30 | copyright-exclude 31 | api/etc/config/copyright.txt 32 | nb-configuration.xml -------------------------------------------------------------------------------- /etc/config/copyright.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) YYYY 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 | */ -------------------------------------------------------------------------------- /examples/runtime/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | JDK_1.8 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/runtime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 43 | 44 | 4.0.0 45 | 46 | 47 | javax.json.bind 48 | javax.json.bind-examples 49 | 1.0.0-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | jar 54 | javax.json.bind-examples-runtime 55 | javax.json.bind-examples-runtime 56 | 57 | 58 | 59 | javax.json.bind 60 | javax.json.bind-api 61 | 62 | 63 | javax.json 64 | javax.json-api 65 | provided 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/com/example/jsonb/CustomJsonbBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package com.example.jsonb; 42 | 43 | import javax.json.bind.Jsonb; 44 | import javax.json.bind.JsonbBuilder; 45 | import javax.json.bind.JsonbConfig; 46 | 47 | public class CustomJsonbBuilder implements JsonbBuilder { 48 | 49 | @Override 50 | public JsonbBuilder withConfig(JsonbConfig configuration) { 51 | throw new UnsupportedOperationException("Not supported yet."); 52 | } 53 | 54 | @Override 55 | public JsonbBuilder withProvider(javax.json.spi.JsonProvider jsonpProvider) { 56 | throw new UnsupportedOperationException("Not supported yet."); 57 | } 58 | 59 | @Override 60 | public Jsonb build() { 61 | throw new UnsupportedOperationException("Not supported yet."); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/mapping/CustomMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.mapping; 42 | 43 | import javax.json.bind.Jsonb; 44 | import javax.json.bind.JsonbBuilder; 45 | import javax.json.bind.JsonbConfig; 46 | import javax.json.bind.annotation.JsonbNillable; 47 | import javax.json.bind.annotation.JsonbProperty; 48 | import javax.json.bind.annotation.JsonbPropertyOrder; 49 | import javax.json.bind.config.PropertyNamingStrategy; 50 | import javax.json.bind.config.PropertyOrderStrategy; 51 | import java.lang.reflect.Field; 52 | import java.util.*; 53 | 54 | import static examples.mapping.Utils.assertEquals; 55 | 56 | public class CustomMapping { 57 | 58 | public static void main(String[] args) throws Exception { 59 | Jsonb jsonb = JsonbBuilder.create(); 60 | 61 | fromJson_customName(jsonb); 62 | toJson_customName(jsonb); 63 | customNamePolicy(); 64 | 65 | toJson_nillable(jsonb); 66 | 67 | toJson_propertyOrder(jsonb); 68 | } 69 | 70 | public static void fromJson_customName(Jsonb jsonb) { 71 | CustomizedName customizedName = jsonb.fromJson("{\"longDesc\":\"This is long description\"}", CustomizedName.class); 72 | assertEquals("This is long description", customizedName.longDescription); 73 | 74 | CustomizedNameWithSetter customizedNameWithSetter = jsonb.fromJson("{\"long-desc\":\"This is long description\"}", CustomizedNameWithSetter.class); 75 | assertEquals("This is long description", customizedNameWithSetter.longDescription); 76 | } 77 | 78 | public static void toJson_customName(Jsonb jsonb) { 79 | CustomizedName customizedName = new CustomizedName(); 80 | customizedName.longDescription = "This is long description"; 81 | 82 | assertEquals("{\"longDesc\":\"This is long description\"}", jsonb.toJson(customizedName)); 83 | 84 | CustomizedNameWithSetter customizedNameWithSetter = new CustomizedNameWithSetter(); 85 | customizedNameWithSetter.setLongDescription("This is long description"); 86 | 87 | assertEquals("{\"longDesc\":\"This is long description\"}", jsonb.toJson(customizedNameWithSetter)); 88 | } 89 | 90 | public static void customNamePolicy() { 91 | JsonbConfig caseInsensitiveConfig = new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE); 92 | Jsonb caseInsensitiveJsonb = JsonbBuilder.create(caseInsensitiveConfig); 93 | 94 | assertEquals("{\"name\":\"Effective Java\"}", caseInsensitiveJsonb.toJson(new Book())); 95 | 96 | Book book = caseInsensitiveJsonb.fromJson("{\"NAme\":\"Effective Java Second Edition\"}", Book.class); 97 | assertEquals("Effective Java Second Edition", book.name); 98 | } 99 | 100 | public static void toJson_nillable(Jsonb jsonb) { 101 | assertEquals("{\"nillableField\":null}", jsonb.toJson(new NillableClass())); 102 | 103 | assertEquals("{\"nillableField\":null}", jsonb.toJson(new NillableClassWithGetter())); 104 | 105 | assertEquals("{\"nillableField\":null}", jsonb.toJson(new NillableType())); 106 | 107 | assertEquals("{\"nillableField\":null}", jsonb.toJson(new NillableTypeOverride())); 108 | 109 | JsonbConfig nillableConfig = new JsonbConfig().withNullValues(true); 110 | Jsonb nillableJsonb = JsonbBuilder.create(nillableConfig); 111 | 112 | Book book = new Book(); 113 | book.name = null; 114 | assertEquals("{\"name\":null}", nillableJsonb.toJson(new Book())); 115 | } 116 | 117 | public static void toJson_propertyOrder(Jsonb jsonb) { 118 | assertEquals("{\"dField\":\"d\",\"cField\":\"c\",\"bField\":\"b\",\"aField\":\"a\"}", jsonb.toJson(new PropertyOrderSpecificClass())); 119 | } 120 | 121 | @JsonbPropertyOrder({"dField", "cField", "bField", "aField"}) 122 | static class PropertyOrderSpecificClass { 123 | public String aField = "a"; 124 | 125 | public String dField = "d"; 126 | 127 | public String cField = "c"; 128 | 129 | public String bField = "b"; 130 | 131 | public PropertyOrderSpecificClass() { 132 | } 133 | } 134 | 135 | static class PropertyOrderClass { 136 | public String aField = "a"; 137 | 138 | public String dField = "d"; 139 | 140 | public String cField = "c"; 141 | 142 | public String bField = "b"; 143 | 144 | public PropertyOrderClass() { 145 | } 146 | } 147 | 148 | static class NillableClass { 149 | @JsonbProperty(nillable = true) 150 | public String nillableField; 151 | 152 | public NillableClass() { 153 | } 154 | } 155 | 156 | static class NillableClassWithGetter { 157 | public String nillableField; 158 | 159 | public NillableClassWithGetter() { 160 | } 161 | 162 | @JsonbProperty(nillable = true) 163 | public String getNillableField() { 164 | return nillableField; 165 | } 166 | 167 | public void setNillableField(String nillableField) { 168 | this.nillableField = nillableField; 169 | } 170 | } 171 | 172 | @JsonbNillable 173 | static class NillableType { 174 | public String nillableField; 175 | 176 | public NillableType() { 177 | } 178 | } 179 | 180 | @JsonbNillable 181 | static class NillableTypeOverride { 182 | public String nillableField; 183 | 184 | @JsonbProperty(nillable = false) 185 | public String absentField; 186 | 187 | public NillableTypeOverride() { 188 | } 189 | } 190 | 191 | static class Book { 192 | public String name = "Effective Java"; 193 | 194 | public Book() { 195 | } 196 | } 197 | 198 | static class CustomizedName { 199 | @JsonbProperty("longDesc") 200 | public String longDescription; 201 | 202 | public CustomizedName() { 203 | } 204 | } 205 | 206 | static class CustomizedNameWithSetter { 207 | private String longDescription; 208 | 209 | public CustomizedNameWithSetter() { 210 | } 211 | 212 | @JsonbProperty("longDesc") 213 | public String getLongDescription() { 214 | return longDescription; 215 | } 216 | 217 | @JsonbProperty("long-desc") 218 | public void setLongDescription(String longDescription) { 219 | this.longDescription = longDescription; 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/mapping/DefaultMappingDates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.mapping; 42 | 43 | import javax.json.bind.Jsonb; 44 | import javax.json.bind.JsonbBuilder; 45 | import javax.json.bind.JsonbException; 46 | import java.text.SimpleDateFormat; 47 | import java.time.*; 48 | import java.util.*; 49 | 50 | import static examples.mapping.Utils.assertEquals; 51 | 52 | public class DefaultMappingDates { 53 | 54 | public static void main(String[] args) throws Exception { 55 | Jsonb jsonb = JsonbBuilder.create(); 56 | toJson_dates(jsonb); 57 | fromJson_dates(jsonb); 58 | } 59 | 60 | public static void toJson_dates(Jsonb jsonb) throws Exception { 61 | // java.util.Date 62 | SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); 63 | Date parsedDate = sdf.parse("04.03.2015"); 64 | 65 | // Serialize to ISO format 66 | assertEquals("\"2015-03-04T00:00:00\"", jsonb.toJson(parsedDate)); 67 | 68 | // java.util.Calendar 69 | Calendar dateCalendar = Calendar.getInstance(); 70 | dateCalendar.clear(); 71 | dateCalendar.set(2015, 3, 3); 72 | 73 | // Serialize to ISO_DATE 74 | assertEquals("\"2015-04-03\"", jsonb.toJson(dateCalendar)); 75 | 76 | // Serialize to ISO_DATE_TIME 77 | Calendar dateTimeCalendar = new Calendar.Builder().setDate(2015, 3, 3).build(); 78 | assertEquals("\"2015-04-03T00:00:00\"", jsonb.toJson(dateCalendar)); 79 | 80 | // java.util.GregorianCalendar 81 | Calendar dateGregorianCalendar = GregorianCalendar.getInstance(); 82 | dateGregorianCalendar.clear(); 83 | dateGregorianCalendar.set(2015, 3, 3); 84 | 85 | // Serialize to ISO_DATE 86 | assertEquals("\"2015-04-03\"", jsonb.toJson(dateGregorianCalendar)); 87 | 88 | // Serialize to ISO_DATE_TIME 89 | Calendar dateTimeGregorianCalendar = new Calendar.Builder().setDate(2015, 3, 3).build(); 90 | assertEquals("\"2015-04-03T00:00:00\"", jsonb.toJson(dateTimeGregorianCalendar)); 91 | 92 | // java.util.TimeZone 93 | assertEquals("\"Europe/Prague\"", jsonb.toJson(TimeZone.getTimeZone("Europe/Prague"))); 94 | 95 | // java.util.SimpleTimeZone 96 | assertEquals("\"Europe/Prague\"", jsonb.toJson(SimpleTimeZone.getTimeZone("Europe/Prague"))); 97 | 98 | // java.time.Instant 99 | assertEquals("\"2015-03-03T23:00:00Z\"", jsonb.toJson(Instant.parse("2015-03-03T23:00:00Z"))); 100 | 101 | // java.time.Duration 102 | assertEquals("\"PT5H4M\"", jsonb.toJson(Duration.ofHours(5).plusMinutes(4))); 103 | 104 | // java.time.Period 105 | assertEquals("\"P10Y\"", jsonb.toJson(Period.between(LocalDate.of(1960, Month.JANUARY, 1), LocalDate.of(1970, Month.JANUARY, 1)))); 106 | 107 | // java.time.LocalDate ISO_LOCAL_DATE 108 | assertEquals("\"2013-08-10\"", jsonb.toJson(LocalDate.of(2013, Month.AUGUST, 10))); 109 | 110 | // java.time.LocalTime ISO_LOCAL_TIME 111 | assertEquals("\"22:33:00\"", jsonb.toJson(LocalTime.of(22, 33))); 112 | 113 | // java.time.LocalDateTime ISO_LOCAL_DATE_TIME 114 | assertEquals("\"2015-02-16T13:21:00\"", jsonb.toJson(LocalDateTime.of(2015, 2, 16, 13, 21))); 115 | 116 | // java.time.ZonedDateTime ISO_ZONED_DATE_TIME 117 | assertEquals("\"2015-02-16T13:21:00+01:00[Europe/Prague]\"", 118 | jsonb.toJson(ZonedDateTime.of(2015, 2, 16, 13, 21, 0, 0, ZoneId.of("Europe/Prague")))); 119 | 120 | // java.time.ZoneId 121 | assertEquals("\"Europe/Prague\"", jsonb.toJson(ZoneId.of("Europe/Prague"))); 122 | 123 | // java.time.ZoneOffset XXX 124 | assertEquals("\"+02:00\"", jsonb.toJson(ZoneOffset.of("+02:00"))); 125 | 126 | // java.time.OffsetDateTime ISO_OFFSET_DATE_TIME 127 | assertEquals("\"2015-02-16T13:21:00+02:00\"", 128 | jsonb.toJson(OffsetDateTime.of(2015, 2, 16, 13, 21, 0, 0, ZoneOffset.of("+02:00")))); 129 | 130 | // java.time.OffsetTime 131 | assertEquals("\"13:21:15.000000016+02:00\"", jsonb.toJson(OffsetTime.of(13, 21, 15, 16, ZoneOffset.of("+02:00")))); 132 | 133 | } 134 | 135 | public static void fromJson_dates(Jsonb jsonb) { 136 | // java.util.Date 137 | Date date = jsonb.fromJson("\"2015-03-04T00:00:00\"", Date.class); 138 | 139 | // java.util.Calendar 140 | Calendar dateCalendar = jsonb.fromJson("\"2015-04-03\"", Calendar.class); 141 | 142 | Calendar dateTimeCalendar = jsonb.fromJson("\"2015-04-03T00:00:00\"", Calendar.class); 143 | 144 | // java.util.GregorianCalendar 145 | GregorianCalendar gregorianCalendar = jsonb.fromJson("\"2015-04-03T00:00:00\"", GregorianCalendar.class); 146 | 147 | try { 148 | GregorianCalendar badCalendar = jsonb.fromJson("\"03.04.2015T00:00:00\"", GregorianCalendar.class); 149 | assert(false); 150 | } catch (JsonbException e) { 151 | //not supported date format 152 | } 153 | 154 | // java.util.TimeZone 155 | TimeZone timeZone = jsonb.fromJson("\"Europe/Prague\"", TimeZone.class); 156 | 157 | // java.util.SimpleTimeZone 158 | SimpleTimeZone simpleTimeZone = jsonb.fromJson("\"Europe/Prague\"", SimpleTimeZone.class); 159 | 160 | // java.time.Instant 161 | Instant instant = jsonb.fromJson("\"2015-03-03T23:00:00Z\"", Instant.class); 162 | 163 | // java.time.Duration 164 | Duration duration = jsonb.fromJson("\"PT5H4M\"", Duration.class); 165 | 166 | // java.time.Period 167 | Period period = jsonb.fromJson("\"P10Y\"", Period.class); 168 | 169 | // java.time.LocalDate 170 | LocalDate localDate = jsonb.fromJson("\"2013-08-10\"", LocalDate.class); 171 | 172 | // java.time.LocalTime 173 | LocalTime localTime = jsonb.fromJson("\"22:33:00\"", LocalTime.class); 174 | 175 | // java.time.LocalDateTime 176 | LocalDateTime localDateTime = jsonb.fromJson("\"2015-02-16T13:21:00\"", LocalDateTime.class); 177 | 178 | // java.time.ZonedDateTime 179 | ZonedDateTime zonedDateTime = jsonb.fromJson("\"2015-02-16T13:21:00+01:00[Europe/Prague]\"", ZonedDateTime.class); 180 | 181 | // java.time.ZoneId 182 | ZoneId zoneId = jsonb.fromJson("\"Europe/Prague\"", ZoneId.class); 183 | 184 | // java.time.ZoneOffset 185 | ZoneOffset zoneOffset = jsonb.fromJson("\"+02:00\"", ZoneOffset.class); 186 | 187 | // java.time.OffsetDateTime 188 | OffsetDateTime offsetDateTime = jsonb.fromJson("\"2015-02-16T13:21:00+02:00\"", OffsetDateTime.class); 189 | 190 | // java.time.OffsetTime 191 | OffsetTime offsetTime = jsonb.fromJson("\"13:21:15.000000016+02:00\"", OffsetTime.class); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/mapping/DefaultMappingGenerics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.mapping; 42 | 43 | import javax.json.bind.Jsonb; 44 | import javax.json.bind.JsonbBuilder; 45 | import java.util.*; 46 | 47 | import static examples.mapping.Utils.*; 48 | 49 | public class DefaultMappingGenerics { 50 | 51 | public static void main(String[] args) throws Exception { 52 | Jsonb jsonb = JsonbBuilder.create(); 53 | toJson_generics(jsonb); 54 | fromJson_generics(jsonb); 55 | } 56 | 57 | public static void toJson_generics(Jsonb jsonb) throws Exception { 58 | // Standard generic class 59 | MyGenericClass myGenericClassField = new MyGenericClass<>(); 60 | myGenericClassField.field1 = "value1"; 61 | myGenericClassField.field2 = 3; 62 | 63 | assertEquals("{\"field1\":\"value1\",\"field2\":3}", jsonb.toJson(myGenericClassField)); 64 | 65 | // Cyclic generic class is not supported by default mapping, but may be supported by JSON Binding implementations 66 | MyCyclicGenericClass myCyclicGenericClass = new MyCyclicGenericClass<>(); 67 | CyclicSubClass cyclicSubClass = new CyclicSubClass(); 68 | cyclicSubClass.subField = "subFieldValue"; 69 | myCyclicGenericClass.field1 = cyclicSubClass; 70 | 71 | assertEquals("{\"field1\":{\"subField\":\"subFieldValue\"}}", jsonb.toJson(myCyclicGenericClass)); 72 | 73 | // Functional interface 74 | FunctionalInterface myFunction = () -> {return "value1";}; 75 | 76 | assertEquals("{\"value\":\"value1\"}", jsonb.toJson(myFunction)); 77 | 78 | myFunction = new FunctionalInterface() { 79 | 80 | private String value = "initValue"; 81 | 82 | @Override 83 | public String getValue() { 84 | return value; 85 | } 86 | 87 | public void setValue(String value) { 88 | this.value = value; 89 | } 90 | }; 91 | 92 | assertEquals("{\"value\":\"initValue\"}", jsonb.toJson(myFunction)); 93 | 94 | // Nested generic with concrete parameter type 95 | NestedGenericConcreteClass nestedGenericConcreteClass = new NestedGenericConcreteClass(); 96 | nestedGenericConcreteClass.list = new ArrayList<>(); 97 | nestedGenericConcreteClass.list.add("value1"); 98 | 99 | assertEquals("{\"list\":[\"value1\"]}", jsonb.toJson(nestedGenericConcreteClass)); 100 | 101 | // Generic with wildcard 102 | GenericWithWildcardClass genericWithWildcardClass = new GenericWithWildcardClass(); 103 | 104 | List> list = new ArrayList<>(); 105 | 106 | genericWithWildcardClass.wildcardList = list; 107 | 108 | Map stringMap = new HashMap<>(); 109 | stringMap.put("k1", "v1"); 110 | 111 | list.add(stringMap); 112 | 113 | assertEquals("{\"wildcardList\":[{\"k1\":\"v1\"}]}", jsonb.toJson(genericWithWildcardClass)); 114 | 115 | // Multi-level generics 116 | MyGenericClass, Integer> multiLevelGeneric = new MyGenericClass<>(); 117 | 118 | MyGenericClass myGenericClass = new MyGenericClass<>(); 119 | myGenericClass.field1 = "f1"; 120 | myGenericClass.field2 = "f2"; 121 | 122 | multiLevelGeneric.field1 = myGenericClass; 123 | multiLevelGeneric.field2 = 3; 124 | 125 | assertEquals("{\"field1\":{\"field1\":\"f1\",\"field2\":\"f2\"},\"field2\":3}", jsonb.toJson(multiLevelGeneric)); 126 | 127 | // Bounded generics 128 | BoundedGenericClass, Circle> boundedGenericClass = new BoundedGenericClass<>(); 129 | List shapeList = new ArrayList<>(); 130 | DefaultMappingGenerics defaultMappingGenerics = new DefaultMappingGenerics(); 131 | Circle circle = defaultMappingGenerics.new Circle(); 132 | circle.setRadius(2.5); 133 | shapeList.add(circle); 134 | boundedGenericClass.superList = shapeList; 135 | 136 | HashSet intSet = new HashSet<>(); 137 | intSet.add(3); 138 | 139 | boundedGenericClass.boundedSet = intSet; 140 | 141 | assertEquals("{\"boundedSet\":[3],\"superList\":[{\"area\":0.0,\"radius\":2.5}]}", jsonb.toJson(boundedGenericClass)); 142 | 143 | List> expected = Arrays.asList(Optional.empty(), Optional.ofNullable("first"), Optional.of("second")); 144 | 145 | String json = jsonb.toJson(expected, DefaultMappingGenerics.class.getField("listOfOptionalStringField").getGenericType()); 146 | assertEquals("[null,\"first\",\"second\"]",json); 147 | } 148 | 149 | public List> listOfOptionalStringField = new ArrayList<>(); 150 | 151 | public MyGenericClass myGenericClassField = new MyGenericClass<>(); 152 | public MyCyclicGenericClass myCyclicGenericClassField = new MyCyclicGenericClass(); 153 | public MyGenericClass, Integer> multiLevelGenericClassField = new MyGenericClass<>(); 154 | public BoundedGenericClass, Circle> boundedGenericClass = new BoundedGenericClass<>(); 155 | public BoundedGenericClass, Circle> otherBoundedGenericClass = new BoundedGenericClass<>(); 156 | 157 | 158 | public static void fromJson_generics(Jsonb jsonb) throws Exception { 159 | DefaultMapping defaultMapping = new DefaultMapping(); 160 | 161 | MyGenericClass myGenericInstance = jsonb.fromJson("{\"field1\":\"value1\", \"field2\":1}", 162 | DefaultMappingGenerics.class.getField("myGenericClassField").getGenericType()); 163 | 164 | // Cyclic generic class is not supported by default mapping, but may be supported by JSON Binding implementations 165 | MyCyclicGenericClass myCyclicGenericClass = jsonb.fromJson("{\"field1\":{\"subField\":\"subFieldValue\"}}", 166 | DefaultMappingGenerics.class.getField("myCyclicGenericClassField").getGenericType()); 167 | 168 | // Deserialize into (generic) interface is by default unsupported (with the exception of concrete interfaces 169 | // defined elsewhere in default mapping, e.g. java.lang.Number) 170 | 171 | // Nested generic concrete class, I am able to access signature of List from class file 172 | NestedGenericConcreteClass nestedGenericConcreteClass = jsonb.fromJson("{\"list\":[\"value1\"]}", NestedGenericConcreteClass.class); 173 | 174 | // Generic with wildcard 175 | 176 | // WildcardList is treated as List 177 | GenericWithWildcardClass genericWithWildcardClass = jsonb.fromJson("{\"wildcardList\":[{\"k1\":\"v1\"}]}", GenericWithWildcardClass.class); 178 | assert(genericWithWildcardClass.wildcardList.get(0) instanceof Map); 179 | 180 | // Multi-level generics 181 | 182 | // T,U is treated as Object 183 | MyGenericClass multiLevelGeneric = jsonb.fromJson("{\"field1\":{\"field1\":\"f1\",\"field2\":\"f2\"},\"field2\":3}", MyGenericClass.class); 184 | 185 | assert(multiLevelGeneric.field1 instanceof Map); 186 | assert(multiLevelGeneric.field2 instanceof Integer); 187 | 188 | // Deserialize with runtime type 189 | MyGenericClass, Integer> myGenericClass = jsonb.fromJson("{\"field1\":{\"field1\":\"f1\",\"field2\":\"f2\"},\"field2\":3}", 190 | DefaultMappingGenerics.class.getField("multiLevelGenericClassField").getGenericType()); 191 | 192 | // Bounded generics 193 | BoundedGenericClass, Circle> boundedGeneric = jsonb.fromJson("{\"boundedSet\":[3],\"superList\":[{\"radius\":2.5}]}", 194 | DefaultMappingGenerics.class.getField("boundedGenericClass").getGenericType()); 195 | 196 | // Exception incompatible types 197 | try { 198 | BoundedGenericClass, Circle> otherGeneric = jsonb.fromJson("{\"boundedSet\":[3],\"superList\":[{\"radius\":2.5}]}", 199 | DefaultMappingGenerics.class.getField("otherBoundedGenericClass").getGenericType()); 200 | HashSet intSet = otherGeneric.boundedSet; 201 | Integer intValue = intSet.iterator().next(); 202 | System.out.println("intValue="+intValue); 203 | assert(false); 204 | } catch (ClassCastException e) { 205 | // Exception - incompatible types 206 | // Double cannot be converted to Integer 207 | } 208 | } 209 | 210 | static class BoundedGenericClass, U> { 211 | public List superList; 212 | public T boundedSet; 213 | 214 | public BoundedGenericClass() {} 215 | } 216 | 217 | interface FunctionalInterface { 218 | public T getValue(); 219 | } 220 | 221 | static class MyGenericClass { 222 | public T field1; 223 | public U field2; 224 | 225 | public MyGenericClass() {} 226 | } 227 | 228 | static class MyCyclicGenericClass> { 229 | public T field1; 230 | 231 | public MyCyclicGenericClass() {} 232 | } 233 | 234 | static class CyclicSubClass extends MyCyclicGenericClass { 235 | public String subField; 236 | 237 | public CyclicSubClass() {} 238 | } 239 | 240 | static class NestedGenericConcreteClass { 241 | public List list; 242 | 243 | public NestedGenericConcreteClass() {} 244 | } 245 | 246 | static class GenericWithWildcardClass { 247 | public List wildcardList; 248 | 249 | public GenericWithWildcardClass() {} 250 | } 251 | 252 | public class Shape { 253 | private double area; 254 | 255 | public Shape() { 256 | } 257 | 258 | public double getArea() { 259 | return area; 260 | } 261 | 262 | public void setArea(double area) { 263 | this.area = area; 264 | } 265 | } 266 | 267 | public class Circle extends Shape { 268 | private double radius; 269 | 270 | public Circle() { 271 | super(); 272 | } 273 | 274 | public double getRadius() { 275 | return radius; 276 | } 277 | 278 | public void setRadius(double radius) { 279 | this.radius = radius; 280 | } 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/mapping/IJsonCompatibility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.mapping; 42 | 43 | import javax.json.bind.Jsonb; 44 | import javax.json.bind.JsonbBuilder; 45 | import javax.json.bind.JsonbConfig; 46 | 47 | public class IJsonCompatibility { 48 | 49 | public static void main(String[] args) { 50 | JsonbConfig jsonIConfig = new JsonbConfig(). 51 | withStrictIJSON(true); 52 | 53 | Jsonb jsonb = JsonbBuilder.create(jsonIConfig); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/mapping/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.mapping; 42 | 43 | public class Utils { 44 | 45 | public static void assertEquals(Object... objects) { 46 | if (null == objects || objects.length < 2 || null == objects[0]) { 47 | throw new IllegalArgumentException("bad parameters"); 48 | } 49 | for (int i = 0; i < objects.length-1; i++) { 50 | assert(objects[i].equals(objects[i+1])); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/model/Author.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.model; 42 | 43 | public class Author { 44 | public String firstName; 45 | public String lastName; 46 | } 47 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/model/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.model; 42 | 43 | public class Book { 44 | public long id; 45 | public Author author; 46 | public Language lang; 47 | } 48 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/model/Language.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015, 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://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 | 41 | package examples.model; 42 | 43 | public enum Language { 44 | ENGLISH, SPANISH, CZECH, RUSSIAN, SLOVAK 45 | } 46 | -------------------------------------------------------------------------------- /examples/runtime/src/main/java/examples/runtime/Runtime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2015 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://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 | 41 | package examples.runtime; 42 | 43 | import examples.model.Author; 44 | import examples.model.Book; 45 | import examples.model.Language; 46 | 47 | import java.nio.charset.StandardCharsets; 48 | import javax.json.bind.Jsonb; 49 | 50 | import javax.json.bind.JsonbBuilder; 51 | import javax.json.bind.JsonbConfig; 52 | 53 | import com.example.jsonb.CustomJsonbBuilder; 54 | 55 | public class Runtime { 56 | 57 | public static void main(String[] args) { 58 | 59 | Book book = new Book(); 60 | book.id = 101L; 61 | book.lang = Language.CZECH; 62 | 63 | book.author = new Author(); 64 | book.author.firstName = "Jara"; 65 | book.author.lastName = "Cimrman"; 66 | 67 | /** 68 | * Shortcut use 69 | */ 70 | { 71 | Jsonb jsonb = JsonbBuilder.create(); 72 | 73 | /** 74 | * Write an object content tree using default JSON mapping 75 | { 76 | "id" : 101, 77 | "author" : { 78 | "firstName" : "Jara", 79 | "lastName" : "Cimrman" 80 | }, 81 | "lang" : "CZECH" 82 | } 83 | */ 84 | String json = jsonb.toJson(book); 85 | 86 | /** 87 | * Read JSON document (from above) into an object content tree using default mapping 88 | */ 89 | Book b = jsonb.fromJson(json, Book.class); 90 | } 91 | 92 | /** 93 | * Default, reuse 94 | */ 95 | { 96 | Jsonb jsonb = JsonbBuilder.create(); 97 | String json = jsonb.toJson(book); 98 | Book b = jsonb.fromJson(json, Book.class); 99 | } 100 | 101 | /** 102 | * Custom providers 103 | */ 104 | { 105 | // Lookup different provider by provider class name 106 | JsonbBuilder.newBuilder("foo.bar.ProviderImpl").build(); 107 | 108 | // Use an explicit implementation of JsonbProvider 109 | Jsonb jsonb = new CustomJsonbBuilder().build(); 110 | } 111 | 112 | /** 113 | * Configuration 114 | */ 115 | JsonbConfig config = new JsonbConfig() 116 | .withEncoding(StandardCharsets.UTF_16.name()) 117 | .withFormatting(true); 118 | 119 | { 120 | // Default configuration 121 | Jsonb jsonb = JsonbBuilder.create(config); 122 | String json = jsonb.toJson(book); 123 | } 124 | 125 | { 126 | // Default configuration with specific builder 127 | Jsonb jsonb = JsonbBuilder.newBuilder("foo.bar.ProviderImpl") 128 | .withConfig(config) 129 | .build(); 130 | jsonb.toJson(book); 131 | } 132 | 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /spec/spec.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee/jsonb-spec/dc81f781f490e26ca545f98c50a7319551f724e2/spec/spec.docx -------------------------------------------------------------------------------- /spec/spec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee/jsonb-spec/dc81f781f490e26ca545f98c50a7319551f724e2/spec/spec.pdf --------------------------------------------------------------------------------