├── impl └── src │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── javax.json.spi.JsonProvider │ ├── jdk9 │ └── module-info.java │ └── java │ └── org │ └── glassfish │ └── json │ ├── api │ └── BufferPool.java │ ├── JsonLocationImpl.java │ ├── JsonReaderFactoryImpl.java │ ├── JsonWriterFactoryImpl.java │ ├── JsonParserFactoryImpl.java │ ├── BufferPoolImpl.java │ ├── JsonGeneratorFactoryImpl.java │ ├── JsonBuilderFactoryImpl.java │ └── JsonUtil.java ├── gf ├── customprovider │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── javax.json.spi.JsonProvider │ │ │ └── java │ │ │ └── org │ │ │ └── glassfish │ │ │ └── json │ │ │ └── customprovider │ │ │ └── TestServlet.java │ └── pom.xml ├── defaultprovider │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── glassfish │ │ └── json │ │ └── defaultprovider │ │ └── TestServlet.java └── pom.xml ├── copyright-exclude ├── demos ├── jsonpointer │ └── src │ │ └── main │ │ ├── resources │ │ ├── jsonpointer.json │ │ └── wiki.json │ │ └── jdk9 │ │ └── module-info.java ├── facebook │ └── src │ │ └── main │ │ ├── resources │ │ └── facebookconfig.properties │ │ ├── jdk9 │ │ └── module-info.java │ │ └── java │ │ └── org │ │ └── glassfish │ │ └── jsondemos │ │ └── facebook │ │ ├── FacebookStreamSearch.java │ │ └── FacebookObjectSearch.java ├── twitter │ └── src │ │ └── main │ │ ├── resources │ │ └── twitterconfig.properties │ │ └── jdk9 │ │ └── module-info.java ├── customprovider-jdk9 │ └── src │ │ ├── main │ │ └── jdk9 │ │ │ └── module-info.java │ │ └── test │ │ └── java │ │ └── customprovider │ │ └── test │ │ └── TestProviderTest.java ├── jaxrs │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── glassfish │ │ │ └── jsondemos │ │ │ └── jaxrs │ │ │ ├── ArrayResource.java │ │ │ ├── DemoApplication.java │ │ │ ├── StructureResource.java │ │ │ ├── ObjectResource.java │ │ │ └── GeneratorResource.java │ └── pom.xml ├── servlet │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── glassfish │ │ └── jsondemos │ │ └── servlet │ │ └── ArrayServlet.java └── pom.xml ├── .gitignore ├── tests ├── src │ └── test │ │ ├── resources │ │ ├── rfc6901.json │ │ ├── wiki.json │ │ ├── jsonmergepatchdiff.json │ │ └── jsonmergepatch.json │ │ └── java │ │ └── org │ │ └── glassfish │ │ └── json │ │ ├── tests │ │ ├── JsonPointerEscapeTest.java │ │ ├── JsonPatchBugsTest.java │ │ ├── JsonPatchOperationTest.java │ │ ├── JsonParserFactoryTest.java │ │ ├── JsonStringTest.java │ │ ├── JsonSamplesParsingTest.java │ │ ├── ToJsonTest.java │ │ ├── JsonGeneratorFactoryTest.java │ │ └── TwitterSearchTest.java │ │ └── JsonParserImplTest.java └── pom.xml ├── README.md ├── CONTRIBUTING.md ├── copyright.txt ├── bundles ├── ri │ └── src │ │ └── main │ │ ├── resources │ │ └── README.txt │ │ └── assembly │ │ ├── archive-jdk8.xml │ │ └── archive.xml ├── licensee │ └── src │ │ └── main │ │ └── assembly │ │ └── archive.xml └── pom.xml ├── api └── src │ └── main │ ├── jdk9 │ └── module-info.java │ └── java │ └── javax │ └── json │ ├── spi │ └── package-info.java │ ├── JsonStructure.java │ ├── stream │ ├── package-info.java │ ├── JsonGenerationException.java │ ├── JsonLocation.java │ └── JsonParsingException.java │ ├── JsonString.java │ ├── JsonException.java │ ├── package-info.java │ ├── JsonMergePatch.java │ ├── JsonValueImpl.java │ └── EmptyObject.java └── jaxrs └── src └── main └── java └── org └── glassfish └── json └── jaxrs └── JsonValueBodyReader.java /impl/src/main/resources/META-INF/services/javax.json.spi.JsonProvider: -------------------------------------------------------------------------------- 1 | org.glassfish.json.JsonProviderImpl 2 | -------------------------------------------------------------------------------- /gf/customprovider/src/main/resources/META-INF/services/javax.json.spi.JsonProvider: -------------------------------------------------------------------------------- 1 | org.glassfish.json.customprovider.TestProvider 2 | -------------------------------------------------------------------------------- /copyright-exclude: -------------------------------------------------------------------------------- 1 | .json 2 | .md 3 | /copyright-exclude 4 | /copyright.txt 5 | /META-INF/services 6 | speclicense.html 7 | /bundles/ri/src/main/resources/LICENSE.txt 8 | /bundles/ri/src/main/resources/README.txt 9 | /LICENSE.txt -------------------------------------------------------------------------------- /demos/jsonpointer/src/main/resources/jsonpointer.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": ["bar", "baz"], 3 | "": 0, 4 | "a/b": 1, 5 | "c%d": 2, 6 | "e^f": 3, 7 | "g|h": 4, 8 | "i\\j": 5, 9 | "k\"l": 6, 10 | " ": 7, 11 | "m~n": 8 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Maven noise 2 | target/ 3 | 4 | #OSX noise 5 | .DS_Store 6 | 7 | #IntelliJ Idea noise 8 | .idea 9 | *.iws 10 | *.ipr 11 | *.iml 12 | 13 | #Eclipse noise 14 | .settings/ 15 | .classpath 16 | .project 17 | 18 | #NetBeans noise 19 | nbproject/ 20 | 21 | #Java noise 22 | *.class 23 | api/doc 24 | *err_pid*.log 25 | -------------------------------------------------------------------------------- /tests/src/test/resources/rfc6901.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": ["bar", "baz"], 3 | "": 0, 4 | "a/b": 1, 5 | "c%d": 2, 6 | "e^f": 3, 7 | "g|h": 4, 8 | "i\\j": 5, 9 | "k\"l": 6, 10 | " ": 7, 11 | "m~n": 8, 12 | "o" : null, 13 | "p": { 14 | "q":"r" 15 | }, 16 | "s": [ { 17 | "t":"u" 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /tests/src/test/resources/wiki.json: -------------------------------------------------------------------------------- 1 | { 2 | "firstName": "John", 3 | "lastName": "Smith", 4 | "age": 25, 5 | "address": { 6 | "streetAddress": "21 2nd Street", 7 | "city": "New York", 8 | "state": "NY", 9 | "postalCode": "10021" 10 | }, 11 | "phoneNumber": [ 12 | { 13 | "type": "home", 14 | "number": "212 555-1234" 15 | }, 16 | { 17 | "type": "fax", 18 | "number": "646 555-4567" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /demos/jsonpointer/src/main/resources/wiki.json: -------------------------------------------------------------------------------- 1 | { 2 | "firstName": "John", 3 | "lastName": "Smith", 4 | "age": 25, 5 | "address": { 6 | "streetAddress": "21 2nd Street", 7 | "city": "New York", 8 | "state": "NY", 9 | "postalCode": "10021" 10 | }, 11 | "phoneNumber": [ 12 | { 13 | "type": "home", 14 | "number": "212 555-1234" 15 | }, 16 | { 17 | "type": "fax", 18 | "number": "646 555-4567" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSON Processing (JSON-P) 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/jsonp). See [here](https://www.eclipse.org/ee4j/status.php) for the overall EE4J transition status. 4 | 5 | ## Links 6 | 7 | - Eclipse Project for JSON Processing: https://projects.eclipse.org/projects/ee4j.jsonp 8 | - Discussion groups: jsonp-dev@eclipse.org 9 | - JSR-367 page on JCP site: https://jcp.org/en/jsr/detail?id=374 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/src/test/resources/jsonmergepatchdiff.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "original": { 4 | "title": "Goodbye!", 5 | "author": { 6 | "givenName": "John", 7 | "familyName": "Doe" 8 | }, 9 | "tags": [ "example", "sample" ], 10 | "content": "This will be unchanged" 11 | }, 12 | "expected": { 13 | "title": "Hello!", 14 | "phoneNumber": "+01-123-456-7890", 15 | "author": { 16 | "familyName": null 17 | }, 18 | "tags": [ "example" ] 19 | }, 20 | "target": { 21 | "title": "Hello!", 22 | "author": { 23 | "givenName": "John" 24 | }, 25 | "tags": [ "example" ], 26 | "content": "This will be unchanged", 27 | "phoneNumber": "+01-123-456-7890" 28 | } 29 | }, 30 | { 31 | "original": {}, 32 | "expected": {"a": {"b":"c"}}, 33 | "target": {"a":{"b":"c"}} 34 | }, 35 | { 36 | "original": {"a":"foo"}, 37 | "expected": "bar", 38 | "target": "bar" 39 | }, 40 | { 41 | "original": {"a":"foo"}, 42 | "expected": null, 43 | "target": null 44 | }, 45 | { 46 | "original": { "c": "d" }, 47 | "expected": { "a": "b" }, 48 | "target": { "a": "b", "c": "d" } 49 | }, 50 | { 51 | "original": { "a": { "d": 2 } }, 52 | "expected": { "a": { "d": 1 } }, 53 | "target": { "a": { "d": 1 } } 54 | }, 55 | { 56 | "original": { "a": "b", "c": "d" }, 57 | "expected": { "c": null }, 58 | "target": { "a": "b" } 59 | } 60 | ] -------------------------------------------------------------------------------- /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 | */ 40 | -------------------------------------------------------------------------------- /demos/facebook/src/main/resources/facebookconfig.properties: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | # 4 | # Copyright (c) 2012-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 | access_token= 42 | -------------------------------------------------------------------------------- /bundles/ri/src/main/resources/README.txt: -------------------------------------------------------------------------------- 1 | * standalone/javax.json-${project.version}.jar contains both "JSR 374 : Java API for JSON Processing 1.1" API 2 | and its default provider implementation. Keep it in classpath for both compiling and running your application. 3 | Automatic module name is: 'java.json' 4 | 5 | For running on JPMS, following modules are provided: 6 | * mods/javax.json-api-${project.version}.jar - 'java.json' module containing only API classes 7 | * mods/javax.json-${project.version}-module.jar - 'org.glassfish.java.json' module containing implementation 8 | 9 | Integration with JAX-RS: Java API for RESTful Web Services (JAX-RS) is provided through 10 | * jaxrs/jsonp-jaxrs-${project.version}.jar 11 | 12 | 13 | IMPORTANT NOTE: module names are not yet final and may change in the future releases 14 | 15 | 16 | * If you are running with maven, you can use the following maven coordinates: 17 | 18 | for standalone reference implementation which includes APIs and implementation classes: 19 | 20 | org.glassfish 21 | javax.json 22 | ${project.version} 23 | 24 | 25 | for APIs: 26 | 27 | javax.json 28 | javax.json-api 29 | ${project.version} 30 | 31 | 32 | for implementation only: 33 | 34 | org.glassfish 35 | javax.json 36 | module 37 | ${project.version} 38 | 39 | 40 | for JAX-RS integration module: 41 | 42 | org.glassfish 43 | jsonp-jaxrs 44 | ${project.version} 45 | 46 | 47 | 48 | * GlassFish 5.x already bundles latest JSON Processing implementation and JAX-RS integration module. 49 | If you deploy an application with GlassFish 5.x, your application (war/ear) doesn't have to bundle APIs nor the ri jar. 50 | 51 | * Samples can be run from https://github.com/javaee/glassfish-samples 52 | -------------------------------------------------------------------------------- /demos/twitter/src/main/resources/twitterconfig.properties: -------------------------------------------------------------------------------- 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 | consumer-key= 42 | consumer-secret= 43 | access-token= 44 | access-token-secret= 45 | 46 | -------------------------------------------------------------------------------- /demos/facebook/src/main/jdk9/module-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 | module org.glassfish.java.json.demos.facebook { 42 | requires org.glassfish.java.json; 43 | } 44 | -------------------------------------------------------------------------------- /demos/jsonpointer/src/main/jdk9/module-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 | module org.glassfish.java.json.demos.jsonpointer { 42 | requires org.glassfish.java.json; 43 | } 44 | -------------------------------------------------------------------------------- /demos/twitter/src/main/jdk9/module-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 | module org.glassfish.java.json.demos.twitter { 42 | requires java.xml.bind; 43 | requires org.glassfish.java.json; 44 | } 45 | -------------------------------------------------------------------------------- /api/src/main/jdk9/module-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 | module java.json { 42 | exports javax.json; 43 | exports javax.json.spi; 44 | exports javax.json.stream; 45 | uses javax.json.spi.JsonProvider; 46 | } 47 | -------------------------------------------------------------------------------- /impl/src/main/jdk9/module-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 | module org.glassfish.java.json { 42 | requires transitive java.json; 43 | exports org.glassfish.json.api; 44 | provides javax.json.spi.JsonProvider with org.glassfish.json.JsonProviderImpl; 45 | } -------------------------------------------------------------------------------- /demos/customprovider-jdk9/src/main/jdk9/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 | module org.glassfish.java.json.demos.customprovider { 42 | requires transitive java.json; 43 | exports org.glassfish.json.customprovider; 44 | provides javax.json.spi.JsonProvider with org.glassfish.json.customprovider.TestProvider; 45 | } 46 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/api/BufferPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.api; 42 | 43 | /** 44 | * char[] pool that pool instances of char[] which are expensive to create. 45 | * 46 | * @author Jitendra Kotamraju 47 | */ 48 | public interface BufferPool { 49 | 50 | /** 51 | * Gets a new char[] object from the pool. 52 | * 53 | *

54 | * If no object is available in the pool, this method creates a new one. 55 | * 56 | * @return 57 | * always non-null. 58 | */ 59 | char[] take(); 60 | 61 | /** 62 | * Returns an object back to the pool. 63 | * 64 | * @param buf object to return back to the pool 65 | */ 66 | void recycle(char[] buf); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonPointerEscapeTest.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 | package org.glassfish.json.tests; 41 | 42 | import org.junit.Test; 43 | 44 | import javax.json.Json; 45 | 46 | import static org.junit.Assert.assertEquals; 47 | 48 | /** 49 | * JSON pointer escape/unescape tests. 50 | * 51 | * @author Dmitry Kornilov 52 | */ 53 | public class JsonPointerEscapeTest { 54 | 55 | @Test 56 | public void escapeTest() { 57 | assertEquals("a~1b", Json.encodePointer("a/b")); 58 | assertEquals("a~0b~1c", Json.encodePointer("a~b/c")); 59 | } 60 | 61 | @Test 62 | public void unescapeTest() { 63 | assertEquals("/a/b", Json.decodePointer("/a~1b")); 64 | assertEquals("/~1", Json.decodePointer("/~01")); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /demos/customprovider-jdk9/src/test/java/customprovider/test/TestProviderTest.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 | package customprovider.test; 42 | 43 | import javax.json.Json; 44 | import javax.json.stream.JsonGenerator; 45 | import org.glassfish.json.customprovider.TestGenerator; 46 | import org.junit.Assert; 47 | import org.junit.Test; 48 | 49 | /** 50 | * 51 | * @author lukas 52 | */ 53 | public class TestProviderTest { 54 | 55 | @Test 56 | public void hello() { 57 | try (JsonGenerator generator = Json.createGenerator(System.out)) { 58 | Assert.assertTrue("TestGenerator is not picked up", generator instanceof TestGenerator); 59 | generator.writeStartArray().writeEnd(); 60 | } 61 | System.out.println(); 62 | System.out.println("Hurray!!!"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-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 for 43 | * JSON processing objects. 44 | * 45 | *

{@link javax.json.spi.JsonProvider JsonProvider} is an abstract class 46 | * that provides a service for creating JSON processing instances. 47 | * A service provider for {@code JsonProvider} provides an 48 | * specific implementation by subclassing and implementing the methods in 49 | * {@code JsonProvider}. This enables using custom, efficient JSON processing 50 | * implementations (for e.g. parser and generator) other than the default ones. 51 | * 52 | *

The API locates and loads providers using {@link java.util.ServiceLoader}. 53 | * 54 | * @since JSON Processing 1.0 55 | */ 56 | package javax.json.spi; 57 | -------------------------------------------------------------------------------- /gf/customprovider/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish.jsonp 48 | providers 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | war 54 | http://maven.apache.org 55 | customprovider 56 | 57 | customprovider 58 | 59 | 60 | customprovider 61 | 62 | 63 | -------------------------------------------------------------------------------- /gf/defaultprovider/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish.jsonp 48 | providers 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | war 54 | http://maven.apache.org 55 | defaultprovider 56 | 57 | defaultprovider 58 | 59 | 60 | defaultprovider 61 | 62 | 63 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/JsonStructure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-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; 42 | 43 | /** 44 | * Super type for the two structured types in JSON ({@link JsonObject object}s 45 | * and {@link JsonArray array}s). 46 | */ 47 | public interface JsonStructure extends JsonValue { 48 | 49 | /** 50 | * Get the value referenced by the provided JSON Pointer in the JsonStructure. 51 | * 52 | * @param jsonPointer the JSON Pointer 53 | * @return the {@code JsonValue} at the referenced location 54 | * @throws JsonException if the JSON Pointer is malformed, or if it references 55 | * a non-existing member or value. 56 | * 57 | * @since 1.1 58 | */ 59 | default public JsonValue getValue(String jsonPointer) { 60 | return Json.createPointer(jsonPointer).getValue(this); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /bundles/licensee/src/main/assembly/archive.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | dist 44 | 45 | zip 46 | 47 | 48 | 49 | ../.. 50 | 51 | api/** 52 | impl/** 53 | 54 | 55 | api/target/** 56 | impl/target/** 57 | **/*.iml 58 | 59 | 60 | 61 | 62 | target/assembly 63 | 64 | *.txt 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonPatchBugsTest.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 | package org.glassfish.json.tests; 42 | 43 | import javax.json.Json; 44 | import javax.json.JsonArray; 45 | import javax.json.JsonException; 46 | import javax.json.JsonPatch; 47 | import org.junit.Test; 48 | 49 | /** 50 | * 51 | * @author lukas 52 | */ 53 | public class JsonPatchBugsTest { 54 | 55 | // https://github.com/javaee/jsonp/issues/58 56 | @Test(expected = JsonException.class) 57 | public void applyThrowsJsonException() { 58 | JsonArray array = Json.createArrayBuilder() 59 | .add(Json.createObjectBuilder() 60 | .add("name", "Bob") 61 | .build()) 62 | .build(); 63 | JsonPatch patch = Json.createPatchBuilder() 64 | .replace("/0/name", "Bobek") 65 | .replace("/1/name", "Vila Amalka") 66 | .build(); 67 | JsonArray result = patch.apply(array); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /gf/defaultprovider/src/main/java/org/glassfish/json/defaultprovider/TestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.defaultprovider; 42 | 43 | import javax.servlet.annotation.*; 44 | import javax.servlet.http.*; 45 | import javax.servlet.*; 46 | import java.io.IOException; 47 | import javax.json.*; 48 | import javax.json.stream.*; 49 | import java.io.*; 50 | 51 | /** 52 | * @author Jitendra Kotamraju 53 | */ 54 | @WebServlet("/json") 55 | public class TestServlet extends HttpServlet { 56 | 57 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { 58 | try { 59 | res.setStatus(200); 60 | res.setContentType("application/json"); 61 | OutputStream os = res.getOutputStream(); 62 | JsonGenerator generator = Json.createGenerator(os); 63 | generator.writeStartArray().writeEnd(); 64 | generator.close(); 65 | } catch(IOException ioe) { 66 | throw new ServletException(ioe); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonPatchOperationTest.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 org.glassfish.json.tests; 42 | 43 | import javax.json.JsonException; 44 | import javax.json.JsonPatch.Operation; 45 | import org.junit.Assert; 46 | import org.junit.Test; 47 | 48 | /** 49 | * 50 | * @author lukas 51 | */ 52 | public class JsonPatchOperationTest { 53 | 54 | private static final String[] opNames = {"add", "remove", "replace", "move", "copy", "test"}; 55 | 56 | @Test 57 | public void fromOperationName() { 58 | for (String op: opNames) { 59 | Assert.assertEquals(Operation.valueOf(op.toUpperCase()), Operation.fromOperationName(op)); 60 | } 61 | for (String op: opNames) { 62 | Assert.assertEquals(Operation.valueOf(op.toUpperCase()), Operation.fromOperationName(op.toUpperCase())); 63 | } 64 | } 65 | 66 | @Test(expected = JsonException.class) 67 | public void fromInvalidOperationName() { 68 | Operation.fromOperationName("undef"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonLocationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import javax.json.stream.JsonLocation; 44 | 45 | /** 46 | * @author Jitendra Kotamraju 47 | */ 48 | class JsonLocationImpl implements JsonLocation { 49 | static final JsonLocation UNKNOWN = new JsonLocationImpl(-1, -1, -1); 50 | 51 | private final long columnNo; 52 | private final long lineNo; 53 | private final long offset; 54 | 55 | JsonLocationImpl(long lineNo, long columnNo, long streamOffset) { 56 | this.lineNo = lineNo; 57 | this.columnNo = columnNo; 58 | this.offset = streamOffset; 59 | } 60 | 61 | @Override 62 | public long getLineNumber() { 63 | return lineNo; 64 | } 65 | 66 | @Override 67 | public long getColumnNumber() { 68 | return columnNo; 69 | } 70 | 71 | @Override 72 | public long getStreamOffset() { 73 | return offset; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "(line no="+lineNo+", column no="+columnNo+", offset="+ offset +")"; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /demos/jaxrs/src/main/java/org/glassfish/jsondemos/jaxrs/ArrayResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.jaxrs; 42 | 43 | import javax.json.*; 44 | import javax.ws.rs.*; 45 | import javax.ws.rs.core.MediaType; 46 | 47 | /** 48 | * JsonArray as parameter and return type for a JAX-RS resource 49 | * 50 | * @author Jitendra Kotamraju 51 | */ 52 | @Path("/array") 53 | public class ArrayResource { 54 | private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); 55 | 56 | @GET 57 | @Produces(MediaType.APPLICATION_JSON) 58 | public JsonArray doGet() { 59 | return bf.createArrayBuilder() 60 | .add(bf.createObjectBuilder() 61 | .add("type", "home") 62 | .add("number", "212 555-1234")) 63 | .add(bf.createObjectBuilder() 64 | .add("type", "fax") 65 | .add("number", "646 555-4567")) 66 | .build(); 67 | } 68 | 69 | @POST 70 | @Consumes(MediaType.APPLICATION_JSON) 71 | public void doPost(JsonArray structure) { 72 | System.out.println(structure); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /demos/jaxrs/src/main/java/org/glassfish/jsondemos/jaxrs/DemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.jaxrs; 42 | 43 | import javax.json.stream.JsonGenerator; 44 | import javax.ws.rs.ApplicationPath; 45 | import javax.ws.rs.core.Application; 46 | import java.util.HashMap; 47 | import java.util.HashSet; 48 | import java.util.Map; 49 | import java.util.Set; 50 | 51 | /** 52 | * A JAX-RS Demo Application using JSON API 53 | * 54 | * @author Jitendra Kotamraju 55 | */ 56 | @ApplicationPath("/") 57 | public class DemoApplication extends Application { 58 | 59 | @Override 60 | public Set> getClasses() { 61 | Set> set = new HashSet<>(); 62 | set.add(ParserResource.class); 63 | set.add(GeneratorResource.class); 64 | set.add(ObjectResource.class); 65 | set.add(ArrayResource.class); 66 | set.add(StructureResource.class); 67 | 68 | return set; 69 | } 70 | 71 | @Override 72 | public Map getProperties() { 73 | return new HashMap() {{ 74 | put(JsonGenerator.PRETTY_PRINTING, true); 75 | }}; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /bundles/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 43 | 44 | 45 | 4.0.0 46 | 47 | 48 | org.glassfish 49 | json 50 | 1.2-SNAPSHOT 51 | ../pom.xml 52 | 53 | 54 | org.glassfish 55 | json-bundles 56 | pom 57 | JSR 374 (JSON Processing) bundles 58 | JSON Processing bundles 59 | https://javaee.github.io/jsonp 60 | 61 | 62 | ri 63 | 64 | 65 | 66 | licensee 67 | 68 | licensee 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /gf/customprovider/src/main/java/org/glassfish/json/customprovider/TestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.customprovider; 42 | 43 | import javax.servlet.annotation.*; 44 | import javax.servlet.http.*; 45 | import javax.servlet.*; 46 | import java.io.IOException; 47 | import javax.json.*; 48 | import javax.json.stream.*; 49 | import java.io.*; 50 | 51 | /** 52 | * @author Jitendra Kotamraju 53 | */ 54 | @WebServlet("/json") 55 | public class TestServlet extends HttpServlet { 56 | 57 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { 58 | try { 59 | res.setStatus(200); 60 | res.setContentType("application/json"); 61 | OutputStream os = res.getOutputStream(); 62 | JsonGenerator generator = Json.createGenerator(new OutputStreamWriter(os)); 63 | if (!(generator instanceof TestGenerator)) { 64 | throw new RuntimeException("MyGenerator is not picked up"); 65 | } 66 | generator.writeStartArray().writeEnd(); 67 | generator.close(); 68 | os.close(); 69 | } catch(IOException ioe) { 70 | throw new ServletException(ioe); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 43 | 44 | 45 | 4.0.0 46 | 47 | 48 | org.glassfish 49 | json 50 | 1.2-SNAPSHOT 51 | ../pom.xml 52 | 53 | 54 | jsonp-tests 55 | jar 56 | JSR 374 (JSON Processing) Tests 57 | 58 | 59 | 60 | javax.json 61 | javax.json-api 62 | 63 | 64 | org.glassfish 65 | javax.json 66 | test 67 | 68 | 69 | junit 70 | junit 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonReaderFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import org.glassfish.json.api.BufferPool; 44 | 45 | import javax.json.JsonReader; 46 | import javax.json.JsonReaderFactory; 47 | import java.io.InputStream; 48 | import java.io.Reader; 49 | import java.nio.charset.Charset; 50 | import java.util.Collections; 51 | import java.util.Map; 52 | 53 | /** 54 | * @author Jitendra Kotamraju 55 | */ 56 | class JsonReaderFactoryImpl implements JsonReaderFactory { 57 | private final Map config = Collections.emptyMap(); 58 | private final BufferPool bufferPool; 59 | 60 | JsonReaderFactoryImpl(BufferPool bufferPool) { 61 | this.bufferPool = bufferPool; 62 | } 63 | 64 | @Override 65 | public JsonReader createReader(Reader reader) { 66 | return new JsonReaderImpl(reader, bufferPool); 67 | } 68 | 69 | @Override 70 | public JsonReader createReader(InputStream in) { 71 | return new JsonReaderImpl(in, bufferPool); 72 | } 73 | 74 | @Override 75 | public JsonReader createReader(InputStream in, Charset charset) { 76 | return new JsonReaderImpl(in, charset, bufferPool); 77 | } 78 | 79 | @Override 80 | public Map getConfigInUse() { 81 | return config; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tests/src/test/resources/jsonmergepatch.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "target": {}, 4 | "patch": {"a": {"b":"c"}}, 5 | "expected": {"a":{"b":"c"}} 6 | }, 7 | { 8 | "target": {}, 9 | "patch": {"a":{"bb":{"ccc":null}}}, 10 | "expected": {"a":{"bb":{}}} 11 | }, 12 | { 13 | "target": {"a":"foo"}, 14 | "patch": "bar", 15 | "expected": "bar" 16 | }, 17 | { 18 | "target": {"a":"foo"}, 19 | "patch": null, 20 | "expected": null 21 | }, 22 | { 23 | "target": {"a": {"b":"c"}}, 24 | "patch": {"a": {"b":"d", "c":null}}, 25 | "expected": {"a": {"b":"d"}} 26 | }, 27 | { 28 | "target": { "c": "d" }, 29 | "patch": { "a": "b" }, 30 | "expected": { "a": "b", "c": "d" } 31 | }, 32 | { 33 | "target": { "a": { "d": 2 } }, 34 | "patch": { "a": { "d": 1 } }, 35 | "expected": { "a": { "d": 1 } } 36 | }, 37 | { 38 | "target": { "a": "b", "c": "d" }, 39 | "patch": { "c": null }, 40 | "expected": { "a": "b" } 41 | }, 42 | { 43 | "target": { "a": { "b": "c", "d": null} }, 44 | "patch": { "a": { "d": null} }, 45 | "expected": { "a": { "b": "c" } } 46 | }, 47 | { 48 | "target": { 49 | "a": { "b": "c" }, 50 | "d": "e" 51 | }, 52 | "patch": { 53 | "a": 1000010002020389.8787987983 54 | }, 55 | "expected": { 56 | "a": 1000010002020389.8787987983, 57 | "d": "e" 58 | } 59 | }, 60 | { 61 | "target": { "a": "b" }, 62 | "patch": { "c": [ null ] }, 63 | "expected": { "a": "b", "c": [ null ] } 64 | }, 65 | { 66 | "target": { "a": { "b": null, "d": 3}, "e": -1 }, 67 | "patch": { "a": { "b": "c", "d": null } }, 68 | "expected": { "a": { "b": "c" }, "e": -1 } 69 | }, 70 | { 71 | "target": [1,2], 72 | "patch": { "a": "b", "c": null }, 73 | "expected": { "a": "b"} 74 | }, 75 | { 76 | "target": { 77 | "title": "Goodbye!", 78 | "author": { 79 | "givenName": "John", 80 | "familyName": "Doe" 81 | }, 82 | "tags": [ "example", "sample" ], 83 | "content": "This will be unchanged" 84 | }, 85 | "patch": { 86 | "title": "Hello!", 87 | "phoneNumber": "+01-123-456-7890", 88 | "author": { 89 | "familyName": null 90 | }, 91 | "tags": [ "example" ] 92 | }, 93 | "expected": { 94 | "title": "Hello!", 95 | "author": { 96 | "givenName": "John" 97 | }, 98 | "tags": [ "example" ], 99 | "content": "This will be unchanged", 100 | "phoneNumber": "+01-123-456-7890" 101 | } 102 | } 103 | ] -------------------------------------------------------------------------------- /api/src/main/java/javax/json/stream/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-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 a streaming API to parse and generate 43 | * JSON. 44 | * 45 | *

46 | * The streaming API consists of the interfaces 47 | * {@link javax.json.stream.JsonParser} and 48 | * {@link javax.json.stream.JsonGenerator}. The interface {@code JsonParser} 49 | * contains methods to parse JSON in a streaming way. The interface 50 | * {@code JsonGenerator} contains methods to write JSON to an output source 51 | * in a streaming way. 52 | * 53 | *

54 | * {@code JsonParser} provides forward, read-only access to JSON data using the 55 | * pull parsing programming model. In this model the application code controls 56 | * the thread and calls methods in the parser interface to move the parser 57 | * forward or to obtain JSON data from the current state of the parser. 58 | * 59 | *

60 | * {@code JsonGenerator} provides methods to write JSON to an output source. 61 | * The generator writes name/value pairs in JSON objects and values in JSON 62 | * arrays. 63 | * 64 | *

65 | * The streaming API is a low-level API designed to process large amounts of 66 | * JSON data efficiently. Other JSON frameworks (such as JSON binding) can be 67 | * implemented using this API. 68 | * 69 | * @since JSON Processing 1.0 70 | */ 71 | package javax.json.stream; 72 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonParserFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.tests; 42 | 43 | import junit.framework.TestCase; 44 | 45 | import javax.json.Json; 46 | import javax.json.stream.JsonParser; 47 | import javax.json.stream.JsonParserFactory; 48 | import java.io.StringReader; 49 | import java.util.HashMap; 50 | import java.util.Map; 51 | 52 | /** 53 | * Tests JsonParserFactory 54 | * 55 | * @author Jitendra Kotamraju 56 | */ 57 | public class JsonParserFactoryTest extends TestCase { 58 | 59 | public JsonParserFactoryTest(String testName) { 60 | super(testName); 61 | } 62 | 63 | public void testParserFactory() { 64 | JsonParserFactory parserFactory = Json.createParserFactory(null); 65 | JsonParser parser1 = parserFactory.createParser(new StringReader("[]")); 66 | parser1.close(); 67 | JsonParser parser2 = parserFactory.createParser(new StringReader("[]")); 68 | parser2.close(); 69 | } 70 | 71 | public void testParserFactoryWithConfig() { 72 | Map config = new HashMap<>(); 73 | JsonParserFactory parserFactory = Json.createParserFactory(config); 74 | JsonParser parser1 = parserFactory.createParser(new StringReader("[]")); 75 | parser1.close(); 76 | JsonParser parser2 = parserFactory.createParser(new StringReader("[]")); 77 | parser2.close(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonStringTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.tests; 42 | 43 | import junit.framework.TestCase; 44 | 45 | import javax.json.*; 46 | import java.io.StringReader; 47 | 48 | /** 49 | * @author Jitendra Kotamraju 50 | */ 51 | public class JsonStringTest extends TestCase { 52 | public JsonStringTest(String testName) { 53 | super(testName); 54 | } 55 | 56 | // tests JsonString#toString() 57 | public void testToString() throws Exception { 58 | escapedString(""); 59 | escapedString("abc"); 60 | escapedString("abc\f"); 61 | escapedString("abc\na"); 62 | escapedString("abc\tabc"); 63 | escapedString("abc\n\tabc"); 64 | escapedString("abc\n\tabc\r"); 65 | escapedString("\n\tabc\r"); 66 | escapedString("\bab\tb\rc\\\"\ftesting1234"); 67 | escapedString("\f\babcdef\tb\rc\\\"\ftesting1234"); 68 | escapedString("\u0000\u00ff"); 69 | escapedString("abc\"\\/abc"); 70 | } 71 | 72 | void escapedString(String str) throws Exception { 73 | JsonArray exp = Json.createArrayBuilder().add(str).build(); 74 | String parseStr = "["+exp.get(0).toString()+"]"; 75 | JsonReader jr = Json.createReader(new StringReader(parseStr)); 76 | JsonArray got = jr.readArray(); 77 | assertEquals(exp, got); 78 | jr.close(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/JsonString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2011-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; 42 | 43 | /** 44 | * An immutable JSON string value. 45 | */ 46 | public interface JsonString extends JsonValue { 47 | 48 | /** 49 | * Returns the JSON string value. 50 | * 51 | * @return a JSON string value 52 | */ 53 | String getString(); 54 | 55 | 56 | /** 57 | * Returns the char sequence for the JSON String value 58 | * 59 | * @return a char sequence for the JSON String value 60 | */ 61 | CharSequence getChars(); 62 | 63 | /** 64 | * Compares the specified object with this {@code JsonString} for equality. 65 | * Returns {@code true} if and only if the specified object is also a 66 | * {@code JsonString}, and their {@link #getString()} objects are 67 | * equal. 68 | * 69 | * @param obj the object to be compared for equality with this 70 | * {@code JsonString} 71 | * @return {@code true} if the specified object is equal to this 72 | * {@code JsonString} 73 | */ 74 | @Override 75 | boolean equals(Object obj); 76 | 77 | /** 78 | * Returns the hash code value for this {@code JsonString} object. 79 | * The hash code of a {@code JsonString} object is defined to be its 80 | * {@link #getString()} object's hash code. 81 | * 82 | * @return the hash code value for this {@code JsonString} object 83 | */ 84 | @Override 85 | int hashCode(); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonWriterFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import org.glassfish.json.api.BufferPool; 44 | 45 | import javax.json.JsonWriter; 46 | import javax.json.JsonWriterFactory; 47 | import java.io.OutputStream; 48 | import java.io.Writer; 49 | import java.nio.charset.Charset; 50 | import java.util.Map; 51 | 52 | /** 53 | * @author Jitendra Kotamraju 54 | */ 55 | class JsonWriterFactoryImpl implements JsonWriterFactory { 56 | private final Map config; // unmodifiable map 57 | private final boolean prettyPrinting; 58 | private final BufferPool bufferPool; 59 | 60 | JsonWriterFactoryImpl(Map config, boolean prettyPrinting, 61 | BufferPool bufferPool) { 62 | this.config = config; 63 | this.prettyPrinting = prettyPrinting; 64 | this.bufferPool = bufferPool; 65 | } 66 | 67 | @Override 68 | public JsonWriter createWriter(Writer writer) { 69 | return new JsonWriterImpl(writer, prettyPrinting, bufferPool); 70 | } 71 | 72 | @Override 73 | public JsonWriter createWriter(OutputStream out) { 74 | return new JsonWriterImpl(out, prettyPrinting, bufferPool); 75 | } 76 | 77 | @Override 78 | public JsonWriter createWriter(OutputStream out, Charset charset) { 79 | return new JsonWriterImpl(out, charset, prettyPrinting, bufferPool); 80 | } 81 | 82 | @Override 83 | public Map getConfigInUse() { 84 | return config; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/JsonException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2011-2018 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; 42 | 43 | /** 44 | * JsonException indicates that some exception happened during 45 | * JSON processing. 46 | */ 47 | public class JsonException extends RuntimeException { 48 | 49 | /** 50 | * Constructs a new runtime exception with the specified detail message. 51 | * The cause is not initialized, and may subsequently be initialized by a 52 | * call to {@link #initCause}. 53 | * 54 | * @param message the detail message. The detail message is saved for 55 | * later retrieval by the {@link #getMessage()} method. 56 | */ 57 | public JsonException(String message) { 58 | super(message); 59 | } 60 | 61 | /** 62 | * Constructs a new runtime exception with the specified detail message and 63 | * cause.

Note that the detail message associated with 64 | * {@code cause} is not automatically incorporated in 65 | * this runtime exception's detail message. 66 | * 67 | * @param message the detail message (which is saved for later retrieval 68 | * by the {@link #getMessage()} method). 69 | * @param cause the cause (which is saved for later retrieval by the 70 | * {@link #getCause()} method). (A null value is 71 | * permitted, and indicates that the cause is nonexistent or 72 | * unknown.) 73 | */ 74 | public JsonException(String message, Throwable cause) { 75 | super(message, cause); 76 | } 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /gf/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish 48 | json 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | pom 54 | http://maven.apache.org 55 | org.glassfish.jsonp 56 | providers 57 | 58 | 59 | 60 | javax 61 | javaee-web-api 62 | provided 63 | 64 | 65 | javax.json 66 | javax.json-api 67 | provided 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-war-plugin 75 | 76 | 77 | customprovider 78 | 79 | 80 | customprovider 81 | defaultprovider 82 | 83 | 84 | -------------------------------------------------------------------------------- /demos/jaxrs/src/main/java/org/glassfish/jsondemos/jaxrs/StructureResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.jaxrs; 42 | 43 | import javax.json.*; 44 | import javax.ws.rs.*; 45 | import javax.ws.rs.core.MediaType; 46 | 47 | /** 48 | * JsonStructure as parameter and return type for a JAX-RS resource 49 | * 50 | * @author Jitendra Kotamraju 51 | */ 52 | @Path("/structure") 53 | public class StructureResource { 54 | private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); 55 | 56 | @GET 57 | @Produces(MediaType.APPLICATION_JSON) 58 | public JsonStructure doGet() { 59 | return bf.createObjectBuilder() 60 | .add("firstName", "John") 61 | .add("lastName", "Smith") 62 | .add("age", 25) 63 | .add("address", bf.createObjectBuilder() 64 | .add("streetAddress", "21 2nd Street") 65 | .add("city", "New York") 66 | .add("state", "NY") 67 | .add("postalCode", "10021")) 68 | .add("phoneNumber", bf.createArrayBuilder() 69 | .add(bf.createObjectBuilder() 70 | .add("type", "home") 71 | .add("number", "212 555-1234")) 72 | .add(bf.createObjectBuilder() 73 | .add("type", "fax") 74 | .add("number", "646 555-4567"))) 75 | .build(); 76 | } 77 | 78 | @POST 79 | @Consumes(MediaType.APPLICATION_JSON) 80 | public void doPost(JsonStructure structure) { 81 | System.out.println(structure); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonSamplesParsingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.tests; 42 | 43 | import junit.framework.TestCase; 44 | 45 | import javax.json.Json; 46 | import javax.json.JsonException; 47 | import javax.json.stream.JsonParser; 48 | import java.io.InputStreamReader; 49 | import java.io.Reader; 50 | import java.nio.charset.StandardCharsets; 51 | 52 | /** 53 | * JsonParser tests for sample files 54 | * 55 | * @author Jitendra Kotamraju 56 | */ 57 | public class JsonSamplesParsingTest extends TestCase { 58 | 59 | public void testSampleFiles() { 60 | String[] fileNames = { 61 | "facebook.json", "facebook1.json", "facebook2.json", 62 | "twitter.json" 63 | }; 64 | for(String fileName: fileNames) { 65 | try { 66 | testSampleFile(fileName); 67 | } catch(Exception e) { 68 | throw new JsonException("Exception while parsing "+fileName, e); 69 | } 70 | } 71 | } 72 | 73 | private void testSampleFile(String fileName) { 74 | Reader reader = new InputStreamReader( 75 | JsonSamplesParsingTest.class.getResourceAsStream("/"+fileName), StandardCharsets.UTF_8); 76 | JsonParser parser = null; 77 | try { 78 | parser = Json.createParser(reader); 79 | while(parser.hasNext()) { 80 | parser.next(); 81 | } 82 | } finally { 83 | if (parser != null) { 84 | parser.close(); 85 | } 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /demos/jaxrs/src/main/java/org/glassfish/jsondemos/jaxrs/ObjectResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.jaxrs; 42 | 43 | import javax.json.*; 44 | import javax.ws.rs.*; 45 | import javax.ws.rs.core.MediaType; 46 | 47 | /** 48 | * JsonObject as parameter and return type for a JAX-RS resource 49 | * Writes a person's representation as JSON using JsonObject 50 | * 51 | * @author Jitendra Kotamraju 52 | */ 53 | @Path("/object") 54 | public class ObjectResource { 55 | private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); 56 | 57 | @GET 58 | @Produces(MediaType.APPLICATION_JSON) 59 | public JsonObject doGet() { 60 | return bf.createObjectBuilder() 61 | .add("firstName", "John") 62 | .add("lastName", "Smith") 63 | .add("age", 25) 64 | .add("address", bf.createObjectBuilder() 65 | .add("streetAddress", "21 2nd Street") 66 | .add("city", "New York") 67 | .add("state", "NY") 68 | .add("postalCode", "10021")) 69 | .add("phoneNumber", bf.createArrayBuilder() 70 | .add(bf.createObjectBuilder() 71 | .add("type", "home") 72 | .add("number", "212 555-1234")) 73 | .add(bf.createObjectBuilder() 74 | .add("type", "fax") 75 | .add("number", "646 555-4567"))) 76 | .build(); 77 | } 78 | 79 | @POST 80 | @Consumes(MediaType.APPLICATION_JSON) 81 | public void doPost(JsonObject structure) { 82 | System.out.println(structure); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /demos/servlet/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish.jsonp 48 | demos 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | war 54 | http://maven.apache.org 55 | jsondemos-servlet 56 | 57 | jsondemos-servlet 58 | 59 | 60 | 61 | javax 62 | javaee-web-api 63 | provided 64 | 65 | 66 | javax.json 67 | javax.json-api 68 | provided 69 | 70 | 71 | 72 | 73 | 74 | org.apache.maven.plugins 75 | maven-compiler-plugin 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-war-plugin 80 | 81 | 82 | jsondemos-servlet 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/JsonParserImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import static org.junit.Assert.assertEquals; 44 | 45 | import javax.json.JsonException; 46 | 47 | import org.junit.After; 48 | import org.junit.Before; 49 | import org.junit.Test; 50 | 51 | public class JsonParserImplTest { 52 | 53 | private String previousValue; 54 | 55 | @Before 56 | public void before() { 57 | previousValue = System.getProperty(JsonParserImpl.MAX_DEPTH); 58 | System.getProperties().remove(JsonParserImpl.MAX_DEPTH); 59 | } 60 | 61 | @After 62 | public void after() { 63 | if (previousValue != null) { 64 | System.setProperty(JsonParserImpl.MAX_DEPTH, previousValue); 65 | } else { 66 | System.getProperties().remove(JsonParserImpl.MAX_DEPTH); 67 | } 68 | } 69 | 70 | @Test 71 | public void undefined() { 72 | System.getProperties().remove(JsonParserImpl.MAX_DEPTH); 73 | int result = JsonParserImpl.propertyStringToInt(JsonParserImpl.MAX_DEPTH, -1); 74 | assertEquals(-1, result); 75 | } 76 | 77 | @Test 78 | public void notInteger() { 79 | System.setProperty(JsonParserImpl.MAX_DEPTH, "String"); 80 | int result = JsonParserImpl.propertyStringToInt(JsonParserImpl.MAX_DEPTH, -10); 81 | assertEquals(-10, result); 82 | } 83 | 84 | @Test 85 | public void integer() { 86 | System.setProperty(JsonParserImpl.MAX_DEPTH, "10"); 87 | int result = JsonParserImpl.propertyStringToInt(JsonParserImpl.MAX_DEPTH, -1); 88 | assertEquals(10, result); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /bundles/ri/src/main/assembly/archive-jdk8.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | dist 45 | 46 | zip 47 | 48 | 49 | 50 | src/main/resources/README.txt 51 | 52 | true 53 | 54 | 55 | src/main/resources/LICENSE.txt 56 | 57 | 58 | 59 | 60 | 61 | false 62 | api 63 | 64 | javax.json:javax.json-api:* 65 | 66 | 67 | 68 | false 69 | standalone 70 | 71 | org.glassfish:javax.json 72 | 73 | 74 | org.glassfish:javax.json:jar:module:* 75 | 76 | 77 | 78 | false 79 | jaxrs 80 | 81 | org.glassfish:jsonp-jaxrs* 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/stream/JsonGenerationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2018 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.stream; 42 | 43 | import javax.json.JsonException; 44 | 45 | /** 46 | * {@code JsonGenerationException} indicates an incorrect JSON is 47 | * being generated. 48 | */ 49 | public class JsonGenerationException extends JsonException { 50 | 51 | /** 52 | * Constructs a new runtime exception with the specified detail message. 53 | * The cause is not initialized, and may subsequently be initialized by a 54 | * call to {@link #initCause}. 55 | * 56 | * @param message the detail message. The detail message is saved for 57 | * later retrieval by the {@link #getMessage()} method. 58 | */ 59 | public JsonGenerationException(String message) { 60 | super(message); 61 | } 62 | 63 | /** 64 | * Constructs a new runtime exception with the specified detail message and 65 | * cause.

Note that the detail message associated with 66 | * {@code cause} is not automatically incorporated in 67 | * this runtime exception's detail message. 68 | * 69 | * @param message the detail message (which is saved for later retrieval 70 | * by the {@link #getMessage()} method). 71 | * @param cause the cause (which is saved for later retrieval by the 72 | * {@link #getCause()} method). (A null value is 73 | * permitted, and indicates that the cause is nonexistent or 74 | * unknown.) 75 | */ 76 | public JsonGenerationException(String message, Throwable cause) { 77 | super(message, cause); 78 | } 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonParserFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import org.glassfish.json.api.BufferPool; 44 | 45 | import javax.json.JsonArray; 46 | import javax.json.JsonObject; 47 | import javax.json.stream.JsonParserFactory; 48 | import javax.json.stream.JsonParser; 49 | import java.io.InputStream; 50 | import java.io.Reader; 51 | import java.nio.charset.Charset; 52 | import java.util.Collections; 53 | import java.util.Map; 54 | 55 | /** 56 | * @author Jitendra Kotamraju 57 | */ 58 | class JsonParserFactoryImpl implements JsonParserFactory { 59 | private final Map config = Collections.emptyMap(); 60 | private final BufferPool bufferPool; 61 | 62 | JsonParserFactoryImpl(BufferPool bufferPool) { 63 | this.bufferPool = bufferPool; 64 | } 65 | 66 | @Override 67 | public JsonParser createParser(Reader reader) { 68 | return new JsonParserImpl(reader, bufferPool); 69 | } 70 | 71 | @Override 72 | public JsonParser createParser(InputStream in) { 73 | return new JsonParserImpl(in, bufferPool); 74 | } 75 | 76 | @Override 77 | public JsonParser createParser(InputStream in, Charset charset) { 78 | return new JsonParserImpl(in, charset, bufferPool); 79 | } 80 | 81 | @Override 82 | public JsonParser createParser(JsonArray array) { 83 | return new JsonStructureParser(array); 84 | } 85 | 86 | @Override 87 | public Map getConfigInUse() { 88 | return config; 89 | } 90 | 91 | @Override 92 | public JsonParser createParser(JsonObject object) { 93 | return new JsonStructureParser(object); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/BufferPoolImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import org.glassfish.json.api.BufferPool; 44 | 45 | import java.lang.ref.WeakReference; 46 | import java.util.concurrent.ConcurrentLinkedQueue; 47 | 48 | /** 49 | * char[] pool that pool instances of char[] which are expensive to create. 50 | * 51 | * @author Jitendra Kotamraju 52 | */ 53 | class BufferPoolImpl implements BufferPool { 54 | 55 | // volatile since multiple threads may access queue reference 56 | private volatile WeakReference> queue; 57 | 58 | /** 59 | * Gets a new object from the pool. 60 | * 61 | *

62 | * If no object is available in the pool, this method creates a new one. 63 | * 64 | * @return 65 | * always non-null. 66 | */ 67 | @Override 68 | public final char[] take() { 69 | char[] t = getQueue().poll(); 70 | if (t==null) 71 | return new char[4096]; 72 | return t; 73 | } 74 | 75 | private ConcurrentLinkedQueue getQueue() { 76 | WeakReference> q = queue; 77 | if (q != null) { 78 | ConcurrentLinkedQueue d = q.get(); 79 | if (d != null) 80 | return d; 81 | } 82 | 83 | // overwrite the queue 84 | ConcurrentLinkedQueue d = new ConcurrentLinkedQueue<>(); 85 | queue = new WeakReference<>(d); 86 | 87 | return d; 88 | } 89 | 90 | /** 91 | * Returns an object back to the pool. 92 | */ 93 | @Override 94 | public final void recycle(char[] t) { 95 | getQueue().offer(t); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /bundles/ri/src/main/assembly/archive.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | dist 45 | 46 | zip 47 | 48 | 49 | 50 | src/main/resources/README.txt 51 | 52 | true 53 | 54 | 55 | src/main/resources/LICENSE.txt 56 | 57 | 58 | 59 | 60 | 61 | false 62 | mods 63 | 64 | javax.json:javax.json-api:* 65 | org.glassfish:javax.json:jar:module:* 66 | 67 | 68 | 69 | false 70 | standalone 71 | 72 | org.glassfish:javax.json 73 | 74 | 75 | org.glassfish:javax.json:jar:module:* 76 | 77 | 78 | 79 | false 80 | jaxrs 81 | 82 | org.glassfish:jsonp-jaxrs* 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/ToJsonTest.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 org.glassfish.json.tests; 42 | 43 | import org.junit.Test; 44 | 45 | import javax.json.Json; 46 | import javax.json.JsonArray; 47 | import javax.json.JsonArrayBuilder; 48 | import javax.json.JsonValue; 49 | 50 | import org.glassfish.json.JsonUtil; 51 | 52 | import static org.junit.Assert.assertEquals; 53 | /** 54 | * @author Kin-man Chung 55 | */ 56 | public class ToJsonTest { 57 | 58 | @Test 59 | public void testToJson() { 60 | assertEquals(Json.createValue("someString"), JsonUtil.toJson("'someString'")); 61 | assertEquals(Json.createValue("some'thing"), JsonUtil.toJson("'some\\'thing'")); 62 | assertEquals(Json.createValue("some\"thing"), JsonUtil.toJson("'some\\\"thing'")); 63 | JsonArrayBuilder builder = Json.createArrayBuilder(); 64 | JsonArray array = builder 65 | .add(Json.createObjectBuilder() 66 | .add("name", "John") 67 | .add("age", 35) 68 | .add("educations", Json.createArrayBuilder() 69 | .add("Gunn High") 70 | .add("UC Berkeley"))) 71 | .add(Json.createObjectBuilder() 72 | .add("name", "Jane") 73 | .add("educations", Json.createArrayBuilder() 74 | .add("Oxford"))) 75 | .build(); 76 | JsonValue expected = JsonUtil.toJson( 77 | "[ { 'name': 'John', " + 78 | "'age': 35, " + 79 | "'educations': ['Gunn High', 'UC Berkeley'] }, " + 80 | " { 'name': 'Jane', " + 81 | "'educations': ['Oxford']}]"); 82 | assertEquals(expected, array); 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2011-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 an object model API to process JSON. 43 | * 44 | *

The object model API is a high-level API that provides immutable object 45 | * models for JSON object and array structures. These JSON structures are 46 | * represented as object models using the Java types {@link javax.json.JsonObject} 47 | * and {@link javax.json.JsonArray}. The interface {@code javax.json.JsonObject} provides 48 | * a {@link java.util.Map} view to access the unordered collection of zero or 49 | * more name/value pairs from the model. Similarly, the interface 50 | * {@code JsonArray} provides a {@link java.util.List} view to access the 51 | * ordered sequence of zero or more values from the model. 52 | * 53 | *

The object model API uses builder patterns to create and modify 54 | * these object models. The classes {@link javax.json.JsonObjectBuilder} and 55 | * {@link javax.json.JsonArrayBuilder} provide methods to create and modify models 56 | * of type {@code JsonObject} and {@code JsonArray} respectively. 57 | * 58 | *

These object models can also be created from an input source using 59 | * the class {@link javax.json.JsonReader}. Similarly, these object models 60 | * can be written to an output source using the class {@link javax.json.JsonWriter}. 61 | *

62 | * This package includes several classes that implement other JSON related 63 | * standards: JSON Pointer, 64 | * JSON Patch, and 65 | * JSON Merge Patch. 66 | * They can be used to retrieve, transform or manipulate values in an 67 | * object model. 68 | */ 69 | package javax.json; 70 | -------------------------------------------------------------------------------- /demos/jaxrs/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish.jsonp 48 | demos 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | war 54 | http://maven.apache.org 55 | jsondemos-jaxrs 56 | 57 | jsondemos-jaxrs 58 | 59 | 60 | 61 | javax.ws.rs 62 | javax.ws.rs-api 63 | provided 64 | 65 | 66 | javax 67 | javaee-web-api 68 | provided 69 | 70 | 71 | javax.json 72 | javax.json-api 73 | provided 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven.plugins 80 | maven-compiler-plugin 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-war-plugin 85 | 86 | 87 | jsondemos-jaxrs 88 | 89 | 90 | -------------------------------------------------------------------------------- /demos/facebook/src/main/java/org/glassfish/jsondemos/facebook/FacebookStreamSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.facebook; 42 | 43 | import javax.json.*; 44 | import javax.json.stream.JsonParser; 45 | import javax.json.stream.JsonParser.Event; 46 | import java.io.*; 47 | 48 | /** 49 | * Parses JSON from facebook graph API using streaming API. 50 | * JSON would like : 51 | * 52 | * { 53 | * data: [ 54 | * { "from" : { "name" : "xxx", ... }, "message: "yyy", ... }, 55 | * { "from" : { "name" : "ppp", ... }, "message: "qqq", ... }, 56 | * ... 57 | * ], 58 | * ... 59 | * } 60 | * 61 | * This codes writes the facebook posts to output as follows: 62 | * xxx: yyy 63 | * -------- 64 | * ppp: qqq 65 | * -------- 66 | * 67 | * @author Jitendra Kotamraju 68 | */ 69 | public class FacebookStreamSearch { 70 | 71 | public static void main(String... args) throws Exception { 72 | try (InputStream is = FacebookObjectSearch.getSearchStream(); 73 | JsonParser parser = Json.createParser(is)) { 74 | while (parser.hasNext()) { 75 | Event e = parser.next(); 76 | if (e == Event.KEY_NAME) { 77 | switch (parser.getString()) { 78 | case "name": 79 | parser.next(); 80 | System.out.print(parser.getString()); 81 | System.out.print(": "); 82 | break; 83 | case "message": 84 | parser.next(); 85 | System.out.println(parser.getString()); 86 | System.out.println("---------"); 87 | break; 88 | } 89 | } 90 | } 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonGeneratorFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import org.glassfish.json.api.BufferPool; 44 | 45 | import javax.json.stream.JsonGenerator; 46 | import javax.json.stream.JsonGeneratorFactory; 47 | import java.io.OutputStream; 48 | import java.io.Writer; 49 | import java.nio.charset.Charset; 50 | import java.util.Map; 51 | 52 | /** 53 | * @author Jitendra Kotamraju 54 | */ 55 | class JsonGeneratorFactoryImpl implements JsonGeneratorFactory { 56 | 57 | private final boolean prettyPrinting; 58 | private final Map config; // unmodifiable map 59 | private final BufferPool bufferPool; 60 | 61 | JsonGeneratorFactoryImpl(Map config, boolean prettyPrinting, 62 | BufferPool bufferPool) { 63 | this.config = config; 64 | this.prettyPrinting = prettyPrinting; 65 | this.bufferPool = bufferPool; 66 | } 67 | 68 | @Override 69 | public JsonGenerator createGenerator(Writer writer) { 70 | return prettyPrinting 71 | ? new JsonPrettyGeneratorImpl(writer, bufferPool) 72 | : new JsonGeneratorImpl(writer, bufferPool); 73 | } 74 | 75 | @Override 76 | public JsonGenerator createGenerator(OutputStream out) { 77 | return prettyPrinting 78 | ? new JsonPrettyGeneratorImpl(out, bufferPool) 79 | : new JsonGeneratorImpl(out, bufferPool); 80 | } 81 | 82 | @Override 83 | public JsonGenerator createGenerator(OutputStream out, Charset charset) { 84 | return prettyPrinting 85 | ? new JsonPrettyGeneratorImpl(out, charset, bufferPool) 86 | : new JsonGeneratorImpl(out, charset, bufferPool); 87 | } 88 | 89 | @Override 90 | public Map getConfigInUse() { 91 | return config; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /demos/servlet/src/main/java/org/glassfish/jsondemos/servlet/ArrayServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.servlet; 42 | 43 | import javax.json.*; 44 | import javax.servlet.*; 45 | import javax.servlet.annotation.WebServlet; 46 | import javax.servlet.http.*; 47 | import java.io.IOException; 48 | 49 | /** 50 | * Writes a JsonArray using HttpServletResponse#getWriter 51 | * http://localhost:8080/jsondemos-servlet/array 52 | * 53 | * Writes a JsonArray using HttpServletResponse#getOutputStream 54 | * http://localhost:8080/jsondemos-servlet/array?stream 55 | * 56 | * 57 | * @author Jitendra Kotamraju 58 | */ 59 | @WebServlet("/array") 60 | public class ArrayServlet extends HttpServlet { 61 | private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); 62 | private static final JsonWriterFactory wf = Json.createWriterFactory(null); 63 | 64 | @Override 65 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { 66 | JsonArray array = bf.createArrayBuilder() 67 | .add(bf.createObjectBuilder() 68 | .add("type", "home") 69 | .add("number", "212 555-1234")) 70 | .add(bf.createObjectBuilder() 71 | .add("type", "fax") 72 | .add("number", "646 555-4567")) 73 | .build(); 74 | res.setStatus(HttpServletResponse.SC_OK); 75 | res.setContentType("application/json"); 76 | res.setCharacterEncoding("UTF-8"); 77 | 78 | String q = req.getQueryString(); 79 | boolean isStream = q != null && q.equals("stream"); 80 | JsonWriter writer = isStream 81 | ? wf.createWriter(res.getOutputStream()) 82 | : wf.createWriter(res.getWriter()); 83 | writer.write(array); 84 | // not closing writer intentionally 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/stream/JsonLocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-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.stream; 42 | 43 | /** 44 | * Provides the location information of a JSON event in an input source. The 45 | * {@code JsonLocation} information can be used to identify incorrect JSON 46 | * or can be used by higher frameworks to know about the processing location. 47 | * 48 | *

All the information provided by a {@code JsonLocation} is optional. For 49 | * example, a provider may only report line numbers. Also, there may not be any 50 | * location information for an input source. For example, if a 51 | * {@code JsonParser} is created using 52 | * {@link javax.json.JsonArray JsonArray} input source, all the methods in 53 | * this class return -1. 54 | * @see JsonParser 55 | * @see JsonParsingException 56 | */ 57 | public interface JsonLocation { 58 | 59 | /** 60 | * Return the line number (starts with 1 for the first line) for the current JSON event in the input source. 61 | * 62 | * @return the line number (starts with 1 for the first line) or -1 if none is available 63 | */ 64 | long getLineNumber(); 65 | 66 | /** 67 | * Return the column number (starts with 1 for the first column) for the current JSON event in the input source. 68 | * 69 | * @return the column number (starts with 1 for the first column) or -1 if none is available 70 | */ 71 | long getColumnNumber(); 72 | 73 | /** 74 | * Return the stream offset into the input source this location 75 | * is pointing to. If the input source is a file or a byte stream then 76 | * this is the byte offset into that stream, but if the input source is 77 | * a character media then the offset is the character offset. 78 | * Returns -1 if there is no offset available. 79 | * 80 | * @return the offset of input source stream, or -1 if there is 81 | * no offset available 82 | */ 83 | long getStreamOffset(); 84 | 85 | } 86 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonBuilderFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json; 42 | 43 | import java.util.Collection; 44 | import org.glassfish.json.api.BufferPool; 45 | 46 | import javax.json.JsonObject; 47 | import javax.json.JsonArray; 48 | import javax.json.JsonArrayBuilder; 49 | import javax.json.JsonBuilderFactory; 50 | import javax.json.JsonObjectBuilder; 51 | import java.util.Collections; 52 | import java.util.Map; 53 | 54 | /** 55 | * @author Jitendra Kotamraju 56 | */ 57 | class JsonBuilderFactoryImpl implements JsonBuilderFactory { 58 | private final Map config; 59 | private final BufferPool bufferPool; 60 | 61 | JsonBuilderFactoryImpl(BufferPool bufferPool) { 62 | this.config = Collections.emptyMap(); 63 | this.bufferPool = bufferPool; 64 | } 65 | 66 | @Override 67 | public JsonObjectBuilder createObjectBuilder() { 68 | return new JsonObjectBuilderImpl(bufferPool); 69 | } 70 | 71 | @Override 72 | public JsonObjectBuilder createObjectBuilder(JsonObject object) { 73 | return new JsonObjectBuilderImpl(object, bufferPool); 74 | } 75 | 76 | @Override 77 | public JsonObjectBuilder createObjectBuilder(Map object) { 78 | return new JsonObjectBuilderImpl(object, bufferPool); 79 | } 80 | 81 | @Override 82 | public JsonArrayBuilder createArrayBuilder() { 83 | return new JsonArrayBuilderImpl(bufferPool); 84 | } 85 | 86 | @Override 87 | public JsonArrayBuilder createArrayBuilder(JsonArray array) { 88 | return new JsonArrayBuilderImpl(array, bufferPool); 89 | } 90 | 91 | @Override 92 | public JsonArrayBuilder createArrayBuilder(Collection collection) { 93 | return new JsonArrayBuilderImpl(collection, bufferPool); 94 | } 95 | 96 | @Override 97 | public Map getConfigInUse() { 98 | return config; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/JsonMergePatch.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; 42 | 43 | /** 44 | *

This interface represents an implementation of a JSON Merge Patch 45 | * as defined by RFC 7396. 46 | *

47 | *

A {@code JsonMergePatch} can be instantiated with {@link Json#createMergePatch(JsonValue)} 48 | * by specifying the patch operations in a JSON Merge Patch or using {@link Json#createMergeDiff(JsonValue, JsonValue)} 49 | * to create a JSON Merge Patch based on the difference between two {@code JsonValue}s. 50 | *

51 | * The following illustrates both approaches. 52 | *

1. Construct a JsonMergePatch with an existing JSON Merge Patch. 53 | *

{@code
54 |  *   JsonValue contacts = ... ; // The target to be patched
55 |  *   JsonValue patch = ...  ; // JSON Merge Patch
56 |  *   JsonMergePatch mergePatch = Json.createMergePatch(patch);
57 |  *   JsonValue result = mergePatch.apply(contacts);
58 |  * } 
59 | * 2. Construct a JsonMergePatch from a difference between two {@code JsonValue}s. 60 | *
{@code
61 |  *   JsonValue source = ... ; // The source object
62 |  *   JsonValue target = ... ; // The modified object
63 |  *   JsonMergePatch mergePatch = Json.createMergeDiff(source, target); // The diff between source and target in a Json Merge Patch format
64 |  * } 
65 | * 66 | * @see RFC 7396 67 | * 68 | * @since 1.1 69 | */ 70 | public interface JsonMergePatch { 71 | 72 | /** 73 | * Applies the JSON Merge Patch to the specified {@code target}. 74 | * The target is not modified by the patch. 75 | * 76 | * @param target the target to apply the merge patch 77 | * @return the transformed target after the patch 78 | */ 79 | JsonValue apply(JsonValue target); 80 | 81 | /** 82 | * Returns the {@code JsonMergePatch} as {@code JsonValue}. 83 | * 84 | * @return this {@code JsonMergePatch} as {@code JsonValue} 85 | */ 86 | JsonValue toJsonValue(); 87 | } 88 | -------------------------------------------------------------------------------- /demos/jaxrs/src/main/java/org/glassfish/jsondemos/jaxrs/GeneratorResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.jaxrs; 42 | 43 | import javax.json.Json; 44 | import javax.json.stream.JsonGenerator; 45 | import javax.ws.rs.GET; 46 | import javax.ws.rs.Path; 47 | import javax.ws.rs.Produces; 48 | import javax.ws.rs.core.MediaType; 49 | import javax.ws.rs.core.StreamingOutput; 50 | import java.io.OutputStream; 51 | 52 | /** 53 | * Writes wiki's JSON example in a streaming fashion using JsonGenerator 54 | * 55 | * @author Jitendra Kotamraju 56 | */ 57 | @Path("/generator") 58 | public class GeneratorResource { 59 | 60 | @GET 61 | @Produces(MediaType.APPLICATION_JSON) 62 | public StreamingOutput doGet() { 63 | return new StreamingOutput() { 64 | public void write(OutputStream os) { 65 | writeWikiExample(os); 66 | } 67 | }; 68 | } 69 | 70 | // Writes wiki example JSON in a streaming fashion 71 | private void writeWikiExample(OutputStream os) { 72 | try(JsonGenerator gene = Json.createGenerator(os)) { 73 | gene.writeStartObject() 74 | .write("firstName", "John") 75 | .write("lastName", "Smith") 76 | .write("age", 25) 77 | .writeStartObject("address") 78 | .write("streetAddress", "21 2nd Street") 79 | .write("city", "New York") 80 | .write("state", "NY") 81 | .write("postalCode", "10021") 82 | .writeEnd() 83 | .writeStartArray("phoneNumber") 84 | .writeStartObject() 85 | .write("type", "home") 86 | .write("number", "212 555-1234") 87 | .writeEnd() 88 | .writeStartObject() 89 | .write("type", "fax") 90 | .write("number", "646 555-4567") 91 | .writeEnd() 92 | .writeEnd() 93 | .writeEnd(); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/JsonGeneratorFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.tests; 42 | 43 | import junit.framework.TestCase; 44 | 45 | import javax.json.*; 46 | import javax.json.stream.JsonGenerator; 47 | import javax.json.stream.JsonGeneratorFactory; 48 | import java.io.StringWriter; 49 | import java.util.HashMap; 50 | import java.util.Map; 51 | 52 | /** 53 | * Tests JsonGeneratorFactory 54 | * 55 | * @author Jitendra Kotamraju 56 | */ 57 | public class JsonGeneratorFactoryTest extends TestCase { 58 | 59 | public JsonGeneratorFactoryTest(String testName) { 60 | super(testName); 61 | } 62 | 63 | public void testGeneratorFactory() { 64 | JsonGeneratorFactory generatorFactory = Json.createGeneratorFactory(null); 65 | 66 | JsonGenerator generator1 = generatorFactory.createGenerator(new StringWriter()); 67 | generator1.writeStartArray().writeEnd(); 68 | generator1.close(); 69 | 70 | JsonGenerator generator2 = generatorFactory.createGenerator(new StringWriter()); 71 | generator2.writeStartArray().writeEnd(); 72 | generator2.close(); 73 | } 74 | 75 | public void testGeneratorFactoryWithConfig() { 76 | Map config = new HashMap<>(); 77 | config.put(JsonGenerator.PRETTY_PRINTING, true); 78 | JsonGeneratorFactory generatorFactory = Json.createGeneratorFactory(config); 79 | Map config1 = generatorFactory.getConfigInUse(); 80 | if (config1.size() != 1) { 81 | throw new JsonException("Expecting no of properties=1, got="+config1.size()); 82 | } 83 | assertTrue(config1.containsKey(JsonGenerator.PRETTY_PRINTING)); 84 | 85 | JsonGenerator generator1 = generatorFactory.createGenerator(new StringWriter()); 86 | generator1.writeStartArray().writeEnd(); 87 | generator1.close(); 88 | 89 | JsonGenerator generator2 = generatorFactory.createGenerator(new StringWriter()); 90 | generator2.writeStartArray().writeEnd(); 91 | generator2.close(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/stream/JsonParsingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2018 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.stream; 42 | 43 | import javax.json.JsonException; 44 | 45 | /** 46 | * {@code JsonParsingException} is used when an incorrect JSON is 47 | * being parsed. 48 | */ 49 | public class JsonParsingException extends JsonException { 50 | 51 | private final JsonLocation location; 52 | 53 | /** 54 | * Constructs a new runtime exception with the specified detail message. 55 | * The cause is not initialized, and may subsequently be initialized by a 56 | * call to {@link #initCause}. 57 | * 58 | * @param message the detail message. The detail message is saved for 59 | * later retrieval by the {@link #getMessage()} method. 60 | * @param location the location of the incorrect JSON 61 | */ 62 | public JsonParsingException(String message, JsonLocation location) { 63 | super(message); 64 | this.location = location; 65 | } 66 | 67 | /** 68 | * Constructs a new runtime exception with the specified detail message and 69 | * cause.

Note that the detail message associated with 70 | * {@code cause} is not automatically incorporated in 71 | * this runtime exception's detail message. 72 | * 73 | * @param message the detail message (which is saved for later retrieval 74 | * by the {@link #getMessage()} method). 75 | * @param cause the cause (which is saved for later retrieval by the 76 | * {@link #getCause()} method). (A null value is 77 | * permitted, and indicates that the cause is nonexistent or 78 | * unknown.) 79 | * @param location the location of the incorrect JSON 80 | */ 81 | public JsonParsingException(String message, Throwable cause, JsonLocation location) { 82 | super(message, cause); 83 | this.location = location; 84 | } 85 | 86 | /** 87 | * Return the location of the incorrect JSON. 88 | * 89 | * @return the non-null location of the incorrect JSON 90 | */ 91 | public JsonLocation getLocation() { 92 | return location; 93 | } 94 | 95 | } 96 | 97 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/JsonValueImpl.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; 42 | 43 | import java.io.Serializable; 44 | 45 | /** 46 | * Private implementation of {@link JsonValue} for simple {@link ValueType}s 47 | * allowing their usage in constants which are better to implement {@link Serializable}. 48 | * 49 | * @author Lukas Jungmann 50 | */ 51 | final class JsonValueImpl implements JsonValue, Serializable { 52 | 53 | private final ValueType valueType; 54 | 55 | JsonValueImpl(ValueType valueType) { 56 | this.valueType = valueType; 57 | } 58 | 59 | /** 60 | * Returns the value type of this JSON value. 61 | * 62 | * @return JSON value type 63 | */ 64 | @Override 65 | public ValueType getValueType() { 66 | return valueType; 67 | } 68 | 69 | /** 70 | * Compares the specified object with this {@link JsonValue} 71 | * object for equality. Returns {@code true} if and only if the 72 | * specified object is also a JsonValue, and their 73 | * {@link #getValueType()} objects are equal. 74 | * 75 | * @param obj the object to be compared for equality with this JsonValue 76 | * @return {@code true} if the specified object is equal to this 77 | * JsonValue 78 | */ 79 | @Override 80 | public boolean equals(Object obj) { 81 | if (this == obj) { 82 | return true; 83 | } 84 | if (obj instanceof JsonValue) { 85 | return getValueType().equals(((JsonValue) obj).getValueType()); 86 | } 87 | return false; 88 | } 89 | 90 | /** 91 | * Returns the hash code value for this {@link JsonValue} object. 92 | * The hash code of the {@link JsonValue} object is defined to be 93 | * its {@link #getValueType()} object's hash code. 94 | * 95 | * @return the hash code value for this {@link JsonValue} object 96 | */ 97 | @Override 98 | public int hashCode() { 99 | return valueType.hashCode(); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return valueType.name().toLowerCase(); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /impl/src/main/java/org/glassfish/json/JsonUtil.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 org.glassfish.json; 42 | 43 | import java.io.StringReader; 44 | import javax.json.Json; 45 | import javax.json.JsonReader; 46 | import javax.json.JsonValue; 47 | import javax.json.stream.JsonParsingException; 48 | 49 | /** 50 | * A utility class 51 | * 52 | * @since 1.1 53 | */ 54 | public final class JsonUtil { 55 | 56 | private JsonUtil() { 57 | } 58 | 59 | /** 60 | * Reads the input JSON text and returns a JsonValue. 61 | *

For convenience, single quotes as well as double quotes 62 | * are allowed to delimit JSON strings. If single quotes are 63 | * used, any quotes, single or double, in the JSON string must be 64 | * escaped (prepend with a '\'). 65 | * 66 | * @param jsonString the input JSON data 67 | * @return the object model for {@code jsonString} 68 | * @throws JsonParsingException if the input is not legal JSON text 69 | */ 70 | public static JsonValue toJson(String jsonString) { 71 | StringBuilder builder = new StringBuilder(); 72 | boolean single_context = false; 73 | for (int i = 0; i < jsonString.length(); i++) { 74 | char ch = jsonString.charAt(i); 75 | if (ch == '\\') { 76 | i = i + 1; 77 | if (i < jsonString.length()) { 78 | ch = jsonString.charAt(i); 79 | if (!(single_context && ch == '\'')) { 80 | // unescape ' inside single quotes 81 | builder.append('\\'); 82 | } 83 | } 84 | } else if (ch == '\'') { 85 | // Turn ' into ", for proper JSON string 86 | ch = '"'; 87 | single_context = ! single_context; 88 | } 89 | builder.append(ch); 90 | } 91 | 92 | JsonReader reader = Json.createReader( 93 | new StringReader(builder.toString())); 94 | JsonValue value = reader.readValue(); 95 | reader.close(); 96 | return value; 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /jaxrs/src/main/java/org/glassfish/json/jaxrs/JsonValueBodyReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.jaxrs; 42 | 43 | import java.io.IOException; 44 | import java.io.InputStream; 45 | import java.lang.annotation.Annotation; 46 | import java.lang.reflect.Type; 47 | import javax.json.Json; 48 | import javax.json.JsonReader; 49 | import javax.json.JsonReaderFactory; 50 | import javax.json.JsonValue; 51 | import javax.ws.rs.Consumes; 52 | import javax.ws.rs.WebApplicationException; 53 | import javax.ws.rs.core.MediaType; 54 | import javax.ws.rs.core.MultivaluedMap; 55 | import javax.ws.rs.ext.MessageBodyReader; 56 | import javax.ws.rs.ext.Provider; 57 | 58 | /** 59 | * JAX-RS MessageBodyReader for JsonValue. This allows JsonValue 60 | * to be a parameter of a resource method. 61 | * 62 | * @author Jitendra Kotamraju 63 | * @author Blaise Doughan 64 | * @author Michal Gajdos 65 | */ 66 | @Provider 67 | @Consumes({"application/json", "text/json", "*/*"}) 68 | public class JsonValueBodyReader implements MessageBodyReader { 69 | private final JsonReaderFactory rf = Json.createReaderFactory(null); 70 | 71 | private static final String JSON = "json"; 72 | private static final String PLUS_JSON = "+json"; 73 | 74 | @Override 75 | public boolean isReadable(Class aClass, Type type, 76 | Annotation[] annotations, MediaType mediaType) { 77 | return JsonValue.class.isAssignableFrom(aClass) && supportsMediaType(mediaType); 78 | } 79 | 80 | /** 81 | * @return true for all media types of the pattern */json and 82 | * */*+json. 83 | */ 84 | private static boolean supportsMediaType(final MediaType mediaType) { 85 | return mediaType.getSubtype().equals(JSON) || mediaType.getSubtype().endsWith(PLUS_JSON); 86 | } 87 | 88 | @Override 89 | public JsonValue readFrom(Class jsonValueClass, 90 | Type type, Annotation[] annotations, MediaType mediaType, 91 | MultivaluedMap stringStringMultivaluedMap, 92 | InputStream inputStream) throws IOException, WebApplicationException { 93 | try (JsonReader reader = rf.createReader(inputStream)) { 94 | return reader.readValue(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /tests/src/test/java/org/glassfish/json/tests/TwitterSearchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.json.tests; 42 | 43 | import junit.framework.TestCase; 44 | 45 | import javax.json.*; 46 | import javax.json.stream.JsonParser; 47 | import javax.json.stream.JsonParser.Event; 48 | import java.io.*; 49 | import java.net.URL; 50 | 51 | /** 52 | * JsonParser Tests using twitter search API 53 | * 54 | * @author Jitendra Kotamraju 55 | */ 56 | public class TwitterSearchTest extends TestCase { 57 | 58 | public void test() { 59 | // dummy test so that junit doesn't complain 60 | } 61 | 62 | public void xtestStreamTwitter() throws Exception { 63 | URL url = new URL("http://search.twitter.com/search.json?q=%23java&rpp=100"); 64 | InputStream is = url.openStream(); 65 | JsonParser parser = Json.createParser(is); 66 | 67 | while(parser.hasNext()) { 68 | Event e = parser.next(); 69 | if (e == Event.KEY_NAME) { 70 | if (parser.getString().equals("from_user")) { 71 | parser.next(); 72 | System.out.print(parser.getString()); 73 | System.out.print(": "); 74 | } else if (parser.getString().equals("text")) { 75 | parser.next(); 76 | System.out.println(parser.getString()); 77 | System.out.println("---------"); 78 | } 79 | } 80 | } 81 | parser.close(); 82 | } 83 | 84 | public void xtestObjectTwitter() throws Exception { 85 | URL url = new URL("http://search.twitter.com/search.json?q=%23java&rpp=100"); 86 | InputStream is = url.openStream(); 87 | JsonReader rdr = Json.createReader(is); 88 | JsonObject obj = rdr.readObject(); 89 | JsonArray results = obj.getJsonArray("results"); 90 | for(JsonObject result : results.getValuesAs(JsonObject.class)) { 91 | System.out.print(result.get("from_user")); 92 | System.out.print(": "); 93 | System.out.println(result.get("text")); 94 | System.out.println("-----------"); 95 | } 96 | rdr.close(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /demos/pom.xml: -------------------------------------------------------------------------------- 1 | 42 | 43 | 44 | 4.0.0 45 | 46 | 47 | org.glassfish 48 | json 49 | 1.2-SNAPSHOT 50 | ../pom.xml 51 | 52 | 53 | pom 54 | http://maven.apache.org 55 | org.glassfish.jsonp 56 | demos 57 | 58 | 59 | 60 | all 61 | 62 | true 63 | 64 | 65 | 66 | javax 67 | javaee-web-api 68 | provided 69 | 70 | 71 | javax.json 72 | javax.json-api 73 | provided 74 | 75 | 76 | 77 | jaxrs 78 | twitter 79 | facebook 80 | jsonpointer 81 | servlet 82 | 83 | 84 | 85 | jdk9-all 86 | 87 | [9,) 88 | 89 | 90 | jaxrs 91 | twitter 92 | facebook 93 | jsonpointer 94 | servlet 95 | customprovider-jdk9 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /demos/facebook/src/main/java/org/glassfish/jsondemos/facebook/FacebookObjectSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * The contents of this file are subject to the terms of either the GNU 7 | * General Public License Version 2 only ("GPL") or the Common Development 8 | * and Distribution License("CDDL") (collectively, the "License"). You 9 | * may not use this file except in compliance with the License. You can 10 | * obtain a copy of the License at 11 | * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 | * or LICENSE.txt. See the License for the specific 13 | * language governing permissions and limitations under the License. 14 | * 15 | * When distributing the software, include this License Header Notice in each 16 | * file and include the License file at LICENSE.txt. 17 | * 18 | * GPL Classpath Exception: 19 | * Oracle designates this particular file as subject to the "Classpath" 20 | * exception as provided by Oracle in the GPL Version 2 section of the License 21 | * file that accompanied this code. 22 | * 23 | * Modifications: 24 | * If applicable, add the following below the License Header, with the fields 25 | * enclosed by brackets [] replaced by your own identifying information: 26 | * "Portions Copyright [year] [name of copyright owner]" 27 | * 28 | * Contributor(s): 29 | * If you wish your version of this file to be governed by only the CDDL or 30 | * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | * elects to include this software in this distribution under the [CDDL or GPL 32 | * Version 2] license." If you don't indicate a single choice of license, a 33 | * recipient has the option to distribute your version of this file under 34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | * its licensees as provided above. However, if you add GPL Version 2 code 36 | * and therefore, elected the GPL Version 2 license, then the option applies 37 | * only if the new code is made subject to such option by the copyright 38 | * holder. 39 | */ 40 | 41 | package org.glassfish.jsondemos.facebook; 42 | 43 | import javax.json.*; 44 | import java.io.*; 45 | import java.net.HttpURLConnection; 46 | import java.net.URL; 47 | import java.util.Properties; 48 | 49 | /** 50 | * Parses JSON from facebook graph API using object model API. 51 | * JSON would like : 52 | * 53 | * { 54 | * data: [ 55 | * { "from" : { "name" : "xxx", ... }, "message: "yyy", ... }, 56 | * { "from" : { "name" : "ppp", ... }, "message: "qqq", ... }, 57 | * ... 58 | * ], 59 | * ... 60 | * } 61 | * 62 | * This codes writes the facebook posts to output as follows: 63 | * xxx: yyy 64 | * -------- 65 | * ppp: qqq 66 | * -------- 67 | * 68 | * @author Jitendra Kotamraju 69 | */ 70 | public class FacebookObjectSearch { 71 | 72 | public static void main(String... args) throws Exception { 73 | try (InputStream is = getSearchStream(); 74 | JsonReader rdr = Json.createReader(is)) { 75 | 76 | JsonObject obj = rdr.readObject(); 77 | JsonArray results = obj.getJsonArray("data"); 78 | for (JsonObject result : results.getValuesAs(JsonObject.class)) { 79 | JsonValue value = result.get("from"); 80 | if (value != null && value instanceof JsonObject) { 81 | System.out.print(((JsonObject)value).getString("name", "anon")); 82 | } 83 | System.out.print(": "); 84 | System.out.println(result.getString("message", "")); 85 | System.out.println("-----------"); 86 | } 87 | } 88 | } 89 | 90 | static InputStream getSearchStream() throws Exception { 91 | Properties config = new Properties(); 92 | config.load(FacebookObjectSearch.class.getResourceAsStream( 93 | "/facebookconfig.properties")); 94 | final String accessToken = (String)config.get("access_token"); 95 | 96 | // Gets the search stream 97 | String searchUrl = "https://graph.facebook.com/search?q=tamil&type=post&access_token="; 98 | URL url = new URL(searchUrl+accessToken); 99 | HttpURLConnection con = (HttpURLConnection)url.openConnection(); 100 | return con.getInputStream(); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /api/src/main/java/javax/json/EmptyObject.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 | package javax.json; 42 | 43 | import java.io.Serializable; 44 | import java.util.AbstractMap; 45 | import java.util.Collections; 46 | import java.util.Set; 47 | 48 | /** 49 | * Private implementation of immutable {@link JsonObject}. 50 | * 51 | * @author Lukas Jungmann 52 | */ 53 | final class EmptyObject extends AbstractMap implements JsonObject, Serializable { 54 | 55 | private static final long serialVersionUID = -1461653546889072583L; 56 | 57 | @Override 58 | public Set> entrySet() { 59 | return Collections.>emptySet(); 60 | } 61 | 62 | @Override 63 | public JsonArray getJsonArray(String name) { 64 | return (JsonArray) get(name); 65 | } 66 | 67 | @Override 68 | public JsonObject getJsonObject(String name) { 69 | return (JsonObject) get(name); 70 | } 71 | 72 | @Override 73 | public JsonNumber getJsonNumber(String name) { 74 | return (JsonNumber) get(name); 75 | } 76 | 77 | @Override 78 | public JsonString getJsonString(String name) { 79 | return (JsonString) get(name); 80 | } 81 | 82 | @Override 83 | public String getString(String name) { 84 | return getJsonString(name).getString(); 85 | } 86 | 87 | @Override 88 | public String getString(String name, String defaultValue) { 89 | return defaultValue; 90 | } 91 | 92 | @Override 93 | public int getInt(String name) { 94 | return getJsonNumber(name).intValue(); 95 | } 96 | 97 | @Override 98 | public int getInt(String name, int defaultValue) { 99 | return defaultValue; 100 | } 101 | 102 | @Override 103 | public boolean getBoolean(String name) { 104 | throw new NullPointerException(); 105 | } 106 | 107 | @Override 108 | public boolean getBoolean(String name, boolean defaultValue) { 109 | return defaultValue; 110 | } 111 | 112 | @Override 113 | public boolean isNull(String name) { 114 | throw new NullPointerException(); 115 | } 116 | 117 | @Override 118 | public ValueType getValueType() { 119 | return ValueType.OBJECT; 120 | } 121 | 122 | // Preserves singleton property 123 | private Object readResolve() { 124 | return JsonValue.EMPTY_JSON_OBJECT; 125 | } 126 | } 127 | --------------------------------------------------------------------------------