From 6aa9daec84c07bb860814354f50055f893b29b51 Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Mon, 7 Jun 2021 22:41:44 +0200 Subject: [PATCH] move implementation to parsson repo, see https://gitlab.eclipse.org/eclipsefdn/emo-team/emo/-/issues/34 Signed-off-by: Lukas Jungmann --- .travis.yml | 9 +- README.md | 6 +- bundles/jakarta.json/pom.xml | 224 ----- .../src/main/java/module-info.java | 25 - .../main/javadoc/doc-files/speclicense.html | 72 -- .../src/main/javadoc/overview.html | 108 --- bundles/pom.xml | 41 - bundles/ri/pom.xml | 98 -- bundles/ri/src/main/assembly/archive.xml | 59 -- bundles/ri/src/main/resources/LICENSE.md | 637 ------------ bundles/ri/src/main/resources/README.txt | 51 - demos/LICENSE.md | 29 - demos/NOTICE.md | 49 - demos/customprovider-jdk9/pom.xml | 88 -- .../src/main/java/module-info.java | 15 - .../demos/customprovider/TestGenerator.java | 175 ---- .../demos/customprovider/TestProvider.java | 113 --- .../customprovider/test/TestProviderTest.java | 34 - demos/facebook/pom.xml | 101 -- demos/facebook/src/main/java/module-info.java | 13 - .../demos/facebook/FacebookObjectSearch.java | 73 -- .../demos/facebook/FacebookStreamSearch.java | 64 -- .../main/resources/facebookconfig.properties | 12 - demos/jaxrs/pom.xml | 54 -- .../jsonp/demos/jaxrs/ArrayResource.java | 45 - .../jsonp/demos/jaxrs/DemoApplication.java | 47 - .../jsonp/demos/jaxrs/GeneratorResource.java | 67 -- .../jsonp/demos/jaxrs/ObjectResource.java | 56 -- .../jsonp/demos/jaxrs/ParserResource.java | 92 -- .../jsonp/demos/jaxrs/StructureResource.java | 55 -- demos/jsonpointer/pom.xml | 112 --- .../src/main/java/module-info.java | 13 - .../demos/jsonpointer/JsonpointerDemo.java | 139 --- .../src/main/resources/jsonpointer.json | 12 - .../jsonpointer/src/main/resources/wiki.json | 21 - demos/pom.xml | 41 - demos/servlet/pom.xml | 54 -- .../jsonp/demos/servlet/ArrayServlet.java | 64 -- demos/twitter/pom.xml | 119 --- demos/twitter/src/main/java/module-info.java | 14 - .../demos/twitter/TwitterObjectSearch.java | 150 --- .../demos/twitter/TwitterStreamSearch.java | 80 -- .../main/resources/twitterconfig.properties | 16 - etc/config/copyright-exclude | 8 - etc/config/copyright.txt | 15 - etc/config/exclude.xml | 14 - impl/pom.xml | 100 -- impl/src/main/java/module-info.java | 21 - .../org/eclipse/jsonp/BufferPoolImpl.java | 74 -- .../eclipse/jsonp/JsonArrayBuilderImpl.java | 488 ---------- .../eclipse/jsonp/JsonBuilderFactoryImpl.java | 78 -- .../jsonp/JsonGeneratorFactoryImpl.java | 70 -- .../org/eclipse/jsonp/JsonGeneratorImpl.java | 733 -------------- .../org/eclipse/jsonp/JsonLocationImpl.java | 57 -- .../org/eclipse/jsonp/JsonMergePatchImpl.java | 117 --- .../java/org/eclipse/jsonp/JsonMessages.java | 294 ------ .../org/eclipse/jsonp/JsonNumberImpl.java | 269 ------ .../eclipse/jsonp/JsonObjectBuilderImpl.java | 366 ------- .../eclipse/jsonp/JsonParserFactoryImpl.java | 71 -- .../org/eclipse/jsonp/JsonParserImpl.java | 592 ------------ .../eclipse/jsonp/JsonPatchBuilderImpl.java | 337 ------- .../java/org/eclipse/jsonp/JsonPatchImpl.java | 320 ------ .../org/eclipse/jsonp/JsonPointerImpl.java | 300 ------ .../jsonp/JsonPrettyGeneratorImpl.java | 106 -- .../org/eclipse/jsonp/JsonProviderImpl.java | 290 ------ .../eclipse/jsonp/JsonReaderFactoryImpl.java | 61 -- .../org/eclipse/jsonp/JsonReaderImpl.java | 147 --- .../org/eclipse/jsonp/JsonStringImpl.java | 108 --- .../eclipse/jsonp/JsonStructureParser.java | 311 ------ .../java/org/eclipse/jsonp/JsonTokenizer.java | 593 ------------ .../main/java/org/eclipse/jsonp/JsonUtil.java | 85 -- .../eclipse/jsonp/JsonWriterFactoryImpl.java | 62 -- .../org/eclipse/jsonp/JsonWriterImpl.java | 167 ---- .../main/java/org/eclipse/jsonp/MapUtil.java | 78 -- .../java/org/eclipse/jsonp/NodeReference.java | 282 ------ .../jsonp/UnicodeDetectingInputStream.java | 164 ---- .../org/eclipse/jsonp/api/BufferPool.java | 44 - .../org/eclipse/jsonp/api/JsonConfig.java | 25 - .../services/jakarta.json.spi.JsonProvider | 1 - .../org/eclipse/jsonp/messages.properties | 92 -- .../eclipse/jsonp/tests/JsonArrayTest.java | 159 --- .../jsonp/tests/JsonBuilderFactoryTest.java | 77 -- .../eclipse/jsonp/tests/JsonBuilderTest.java | 161 ---- .../jsonp/tests/JsonCollectorTest.java | 165 ---- .../jsonp/tests/JsonDuplicateKeyTest.java | 101 -- .../eclipse/jsonp/tests/JsonFieldTest.java | 198 ---- .../jsonp/tests/JsonGeneratorFactoryTest.java | 70 -- .../jsonp/tests/JsonGeneratorTest.java | 545 ----------- .../jsonp/tests/JsonMergePatchDiffTest.java | 111 --- .../jsonp/tests/JsonMergePatchTest.java | 113 --- .../eclipse/jsonp/tests/JsonNumberTest.java | 219 ----- .../eclipse/jsonp/tests/JsonObjectTest.java | 232 ----- .../jsonp/tests/JsonParserFactoryTest.java | 56 -- .../jsonp/tests/JsonParserSkipTest.java | 116 --- .../eclipse/jsonp/tests/JsonParserTest.java | 827 ---------------- .../jsonp/tests/JsonParsingExceptionTest.java | 155 --- .../jsonp/tests/JsonPatchBugsTest.java | 79 -- .../jsonp/tests/JsonPatchBuilderTest.java | 83 -- .../jsonp/tests/JsonPatchDiffTest.java | 118 --- .../jsonp/tests/JsonPatchOperationTest.java | 46 - .../eclipse/jsonp/tests/JsonPatchTest.java | 118 --- .../tests/JsonPointerAddOperationTest.java | 203 ---- .../jsonp/tests/JsonPointerEscapeTest.java | 43 - .../tests/JsonPointerRemoveOperationTest.java | 157 --- .../JsonPointerReplaceOperationTest.java | 201 ---- .../eclipse/jsonp/tests/JsonPointerTest.java | 108 --- .../jsonp/tests/JsonPointerToStringTest.java | 57 -- .../eclipse/jsonp/tests/JsonReaderTest.java | 207 ---- .../jsonp/tests/JsonSamplesParsingTest.java | 65 -- .../eclipse/jsonp/tests/JsonStringTest.java | 69 -- .../eclipse/jsonp/tests/JsonValueTest.java | 171 ---- .../eclipse/jsonp/tests/JsonWriterTest.java | 229 ----- .../org/eclipse/jsonp/tests/RFC7159Test.java | 102 -- .../org/eclipse/jsonp/tests/ToJsonTest.java | 61 -- .../jsonp/tests/TwitterSearchTest.java | 75 -- impl/src/test/resources/facebook.json | 668 ------------- impl/src/test/resources/facebook1.json | 911 ------------------ impl/src/test/resources/facebook2.json | 555 ----------- impl/src/test/resources/jsonmergepatch.json | 103 -- .../test/resources/jsonmergepatchdiff.json | 60 -- impl/src/test/resources/jsonpatch.json | 219 ----- impl/src/test/resources/jsonpatchdiff.json | 169 ---- impl/src/test/resources/rfc6901.json | 20 - impl/src/test/resources/twitter.json | 2 - impl/src/test/resources/wiki.json | 21 - jaxrs/pom.xml | 87 -- jaxrs/src/main/java/module-info.java | 25 - .../jsonp/jaxrs/JsonValueBodyReader.java | 73 -- .../jsonp/jaxrs/JsonValueBodyWriter.java | 98 -- pom.xml | 502 ---------- providers/customprovider/pom.xml | 38 - .../jsonp/customprovider/TestGenerator.java | 181 ---- .../jsonp/customprovider/TestProvider.java | 112 --- .../jsonp/customprovider/TestServlet.java | 56 -- .../services/jakarta.json.spi.JsonProvider | 1 - providers/defaultprovider/pom.xml | 38 - .../jsonp/defaultprovider/TestServlet.java | 47 - providers/pom.xml | 59 -- 138 files changed, 2 insertions(+), 19827 deletions(-) delete mode 100644 bundles/jakarta.json/pom.xml delete mode 100644 bundles/jakarta.json/src/main/java/module-info.java delete mode 100644 bundles/jakarta.json/src/main/javadoc/doc-files/speclicense.html delete mode 100644 bundles/jakarta.json/src/main/javadoc/overview.html delete mode 100644 bundles/pom.xml delete mode 100755 bundles/ri/pom.xml delete mode 100755 bundles/ri/src/main/assembly/archive.xml delete mode 100644 bundles/ri/src/main/resources/LICENSE.md delete mode 100644 bundles/ri/src/main/resources/README.txt delete mode 100644 demos/LICENSE.md delete mode 100644 demos/NOTICE.md delete mode 100644 demos/customprovider-jdk9/pom.xml delete mode 100644 demos/customprovider-jdk9/src/main/java/module-info.java delete mode 100644 demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestGenerator.java delete mode 100644 demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestProvider.java delete mode 100644 demos/customprovider-jdk9/src/test/java/customprovider/test/TestProviderTest.java delete mode 100644 demos/facebook/pom.xml delete mode 100644 demos/facebook/src/main/java/module-info.java delete mode 100644 demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookObjectSearch.java delete mode 100644 demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookStreamSearch.java delete mode 100644 demos/facebook/src/main/resources/facebookconfig.properties delete mode 100644 demos/jaxrs/pom.xml delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ArrayResource.java delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/DemoApplication.java delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/GeneratorResource.java delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ObjectResource.java delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ParserResource.java delete mode 100644 demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/StructureResource.java delete mode 100644 demos/jsonpointer/pom.xml delete mode 100644 demos/jsonpointer/src/main/java/module-info.java delete mode 100644 demos/jsonpointer/src/main/java/org/eclipse/jsonp/demos/jsonpointer/JsonpointerDemo.java delete mode 100644 demos/jsonpointer/src/main/resources/jsonpointer.json delete mode 100644 demos/jsonpointer/src/main/resources/wiki.json delete mode 100644 demos/pom.xml delete mode 100644 demos/servlet/pom.xml delete mode 100644 demos/servlet/src/main/java/org/eclipse/jsonp/demos/servlet/ArrayServlet.java delete mode 100644 demos/twitter/pom.xml delete mode 100644 demos/twitter/src/main/java/module-info.java delete mode 100644 demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterObjectSearch.java delete mode 100644 demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterStreamSearch.java delete mode 100644 demos/twitter/src/main/resources/twitterconfig.properties delete mode 100644 etc/config/copyright-exclude delete mode 100644 etc/config/copyright.txt delete mode 100644 etc/config/exclude.xml delete mode 100644 impl/pom.xml delete mode 100644 impl/src/main/java/module-info.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/BufferPoolImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonArrayBuilderImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonBuilderFactoryImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonGeneratorFactoryImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonGeneratorImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonLocationImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonMergePatchImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonMessages.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonNumberImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonObjectBuilderImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonParserFactoryImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonParserImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonPatchBuilderImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonPatchImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonPointerImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonPrettyGeneratorImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonProviderImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonReaderFactoryImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonReaderImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonStringImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonStructureParser.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonTokenizer.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonUtil.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonWriterFactoryImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/JsonWriterImpl.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/MapUtil.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/NodeReference.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/UnicodeDetectingInputStream.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/api/BufferPool.java delete mode 100644 impl/src/main/java/org/eclipse/jsonp/api/JsonConfig.java delete mode 100644 impl/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider delete mode 100644 impl/src/main/resources/org/eclipse/jsonp/messages.properties delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonArrayTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderFactoryTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonCollectorTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonDuplicateKeyTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonFieldTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorFactoryTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchDiffTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonNumberTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonObjectTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonParserFactoryTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonParserSkipTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonParserTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonParsingExceptionTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBugsTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBuilderTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchDiffTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchOperationTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerAddOperationTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerEscapeTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerRemoveOperationTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerReplaceOperationTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerToStringTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonReaderTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonSamplesParsingTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonStringTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonValueTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/JsonWriterTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/RFC7159Test.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/ToJsonTest.java delete mode 100644 impl/src/test/java/org/eclipse/jsonp/tests/TwitterSearchTest.java delete mode 100644 impl/src/test/resources/facebook.json delete mode 100644 impl/src/test/resources/facebook1.json delete mode 100644 impl/src/test/resources/facebook2.json delete mode 100644 impl/src/test/resources/jsonmergepatch.json delete mode 100644 impl/src/test/resources/jsonmergepatchdiff.json delete mode 100644 impl/src/test/resources/jsonpatch.json delete mode 100644 impl/src/test/resources/jsonpatchdiff.json delete mode 100644 impl/src/test/resources/rfc6901.json delete mode 100644 impl/src/test/resources/twitter.json delete mode 100644 impl/src/test/resources/wiki.json delete mode 100644 jaxrs/pom.xml delete mode 100644 jaxrs/src/main/java/module-info.java delete mode 100644 jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyReader.java delete mode 100644 jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyWriter.java delete mode 100644 pom.xml delete mode 100644 providers/customprovider/pom.xml delete mode 100644 providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestGenerator.java delete mode 100644 providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestProvider.java delete mode 100644 providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestServlet.java delete mode 100644 providers/customprovider/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider delete mode 100644 providers/defaultprovider/pom.xml delete mode 100644 providers/defaultprovider/src/main/java/org/eclipse/jsonp/defaultprovider/TestServlet.java delete mode 100644 providers/pom.xml diff --git a/.travis.yml b/.travis.yml index a8576a27..501f7b79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,4 @@ install: true script: - cd api - - mvn -U -C -Pstaging,oss-release -Dnon.final=true -Dgpg.skip=true clean install - - cd .. - - mvn -U -C -Pstaging,oss-release,all -Dnon.final=true -Dgpg.skip=true clean install - - cd tck - - mvn -U clean install - - cd ../impl-tck - - mvn -U clean test - + - mvn -U -C -Pstaging,oss-release -Dgpg.skip=true clean install diff --git a/README.md b/README.md index 52567e18..0731a6c6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ # Jakarta JSON Processing Jakarta JSON Processing provides portable APIs to parse, generate, transform, and query JSON documents. -This project contains Jakarta JSON Processing specification, API and a compatible implementation. +This project contains Jakarta JSON Processing specification, API and TCK. ## Build @@ -32,8 +32,6 @@ mvn -U -C clean install under the [Eclipse Public License (EPL) v2.0](https://projects.eclipse.org/license/epl-2.0) and [GNU General Public License (GPL) v2 with Classpath Exception](https://www.gnu.org/software/classpath/license.html); see the license information at the top of each source file. -* The source code for the demo programs is licensed -under the [Eclipse Distribution License (EDL) v1.0.](https://www.eclipse.org/org/documents/edl-v10.php). * The binary jar files published to the Maven repository are licensed under the same licenses as the corresponding source code; see the file `META-INF/LICENSE.txt` in each jar file. @@ -47,9 +45,7 @@ the license text included in every source file. ## Links -- [Jakarta JSON Processing official web site](https://eclipse-ee4j.github.io/jsonp) - [Jakarta JSON Processing @ Eclipse](https://projects.eclipse.org/projects/ee4j.jsonp) -- [README.txt](https://github.com/eclipse-ee4j/jsonp/blob/master/bundles/ri/src/main/resources/README.txt) ## Contributing diff --git a/bundles/jakarta.json/pom.xml b/bundles/jakarta.json/pom.xml deleted file mode 100644 index 009f2163..00000000 --- a/bundles/jakarta.json/pom.xml +++ /dev/null @@ -1,224 +0,0 @@ - - - - - 4.0.0 - - - org.eclipse.jsonp - json-bundles - 2.0.2-SNAPSHOT - ../pom.xml - - - org.eclipse.jsonp - jakarta.json - 2.0.2-SNAPSHOT - JSON-P Default Provider - Default provider for Jakarta JSON Processing - https://github.com/eclipse-ee4j/jsonp - - - - jakarta.json - jakarta.json-api - provided - - - org.eclipse.jsonp - jsonp - provided - - - - - ${project.build.directory}/generated-sources/dependencies - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack-sources - generate-sources - - unpack-dependencies - - - provided - sources - true - module-info.*,META-INF/services/**, META-INF/MANIFEST.MF - ${dep.sources} - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-resource - generate-resources - - add-resource - - - - - ${dep.sources} - - **/*.java - - - - - - - add-source - generate-sources - - add-source - - - - ${dep.sources} - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - fix-default-provider - generate-sources - - run - - - - - - - - - - - - - - - - org.glassfish.build - spec-version-maven-plugin - - - ${non.final} - impl - ${spec_version} - ${new_spec_version} - ${new_spec_impl_version} - ${impl_version} - ${new_impl_version} - ${api_package} - ${impl_namespace} - - - - - - set-spec-properties - - - - - - - - org.apache.felix - maven-bundle-plugin - - - osgi-manifest - - manifest - - - - ${spec.bundle.version} - ${spec.bundle.symbolic-name} - ${spec.extension.name} - ${spec.implementation.version} - Eclipse Foundation - ${spec.specification.version} - !org.eclipse.jsonp,* - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - false - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - false - - - 11 - true - true - JSON Processing API documentation - JSON Processing API documentation - JSON Processing API documentation -
JSON Processing API v${project.version}]]>
- jsonp-dev@eclipse.org.
-Copyright © 2019, 2021 Eclipse Foundation. All rights reserved.
-Use is subject to license terms.]]> -
-
-
-
-
- -
diff --git a/bundles/jakarta.json/src/main/java/module-info.java b/bundles/jakarta.json/src/main/java/module-info.java deleted file mode 100644 index 2928317e..00000000 --- a/bundles/jakarta.json/src/main/java/module-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -module jakarta.json { - - exports jakarta.json; - exports jakarta.json.spi; - exports jakarta.json.stream; - exports org.eclipse.jsonp.api; - - uses jakarta.json.spi.JsonProvider; -} diff --git a/bundles/jakarta.json/src/main/javadoc/doc-files/speclicense.html b/bundles/jakarta.json/src/main/javadoc/doc-files/speclicense.html deleted file mode 100644 index ba29e5ed..00000000 --- a/bundles/jakarta.json/src/main/javadoc/doc-files/speclicense.html +++ /dev/null @@ -1,72 +0,0 @@ - - -Eclipse Foundation Specification License - v1.0 - - -

Eclipse Foundation Specification License - v1.0

-

By using and/or copying this document, or the Eclipse Foundation - document from which this statement is linked, you (the licensee) agree - that you have read, understood, and will comply with the following - terms and conditions:

- -

Permission to copy, and distribute the contents of this document, or - the Eclipse Foundation document from which this statement is linked, in - any medium for any purpose and without fee or royalty is hereby - granted, provided that you include the following on ALL copies of the - document, or portions thereof, that you use:

- - - -

Inclusion of the full text of this NOTICE must be provided. We - request that authorship attribution be provided in any software, - documents, or other items or products that you create pursuant to the - implementation of the contents of this document, or any portion - thereof.

- -

No right to create modifications or derivatives of Eclipse Foundation - documents is granted pursuant to this license, except anyone may - prepare and distribute derivative works and portions of this document - in software that implements the specification, in supporting materials - accompanying such software, and in documentation of such software, - PROVIDED that all such works include the notice below. HOWEVER, the - publication of derivative works of this document for use as a technical - specification is expressly prohibited.

- -

The notice is:

- -

"Copyright © 2018 Eclipse Foundation. This software or - document includes material copied from or derived from [title and URI - of the Eclipse Foundation specification document]."

- -

Disclaimers

- -

THIS DOCUMENT IS PROVIDED "AS IS," AND THE COPYRIGHT - HOLDERS AND THE ECLIPSE FOUNDATION MAKE NO REPRESENTATIONS OR - WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, - WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, - NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE DOCUMENT ARE - SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS - WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR - OTHER RIGHTS.

- -

THE COPYRIGHT HOLDERS AND THE ECLIPSE FOUNDATION WILL NOT BE LIABLE - FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT - OF ANY USE OF THE DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE - CONTENTS THEREOF.

- -

The name and trademarks of the copyright holders or the Eclipse - Foundation may NOT be used in advertising or publicity pertaining to - this document or its contents without specific, written prior - permission. Title to copyright in this document will at all times - remain with copyright holders.

- - - diff --git a/bundles/jakarta.json/src/main/javadoc/overview.html b/bundles/jakarta.json/src/main/javadoc/overview.html deleted file mode 100644 index 2b822089..00000000 --- a/bundles/jakarta.json/src/main/javadoc/overview.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - -Jakarta JSON Processing provides portable APIs to parse, -generate, transform, and query JSON using the -streaming API or the object model API. - -

The Streaming API provides a way to parsing and generation of JSON in a -streaming fashion. It hands over parsing and generation control to the -programmer. The streaming API provides an event-based parser and allows an -application developer to ask for the next event rather than handling the event -in a callback. This gives a developer more procedural control over -the processing of the JSON. Application code can process or discard -the parser event, and ask for the next event(pull the event). The -streaming model is adequate for local processing where random access of other -parts of the data is not required. Similarly, the streaming API provides -a way to generate well-formed JSON to a stream by writing one event at a time. - -

The object model API creates a random access tree-like structure that -represents the JSON data in memory. The tree can then be navigated and -queried. This programming model is the most flexible and enables processing -that requires random access to the complete contents of the tree. However, -it is often not as efficient as the streaming model and requires more memory. -The object model generates JSON output by navigating the entire tree at once. - -

The Streaming API

-

The streaming API is similar to the StAX API for XML and consists of the -interfaces {@link jakarta.json.stream.JsonParser} and -{@link jakarta.json.stream.JsonGenerator}. {@code JsonParser} -contains methods to parse JSON data using the streaming model. -{@code JsonGenerator} contains methods to write JSON data to an ouptut source. - -

{@code JsonParser} provides forward, read-only access to -JSON data using the pull parsing programming model. In this model the -application code controls the thread and calls methods in the parser interface -to move the parser forward or to obtain JSON data from the current state of -the parser. Refer to -this example -for more details. - -

{@code JsonGenerator} provides methods to write JSON to a stream. The -generator writes name/value pairs in JSON objects and values in JSON arrays. -Refer to -this -example for more details. - -

The streaming API is a low-level API designed to process large amounts of -JSON data efficiently. Other JSON frameworks (such as JSON binding) can be -implemented using this API.

- -

The Object Model API

-

The object model API is similar to the DOM API for XML. It is a high-level -API that provides immutable object models for JSON object and array structures. -These JSON structures are represented as object models using the Java types -{@link jakarta.json.JsonObject} and {@link jakarta.json.JsonArray}. -{@code JsonObject} provides a {@link java.util.Map} view to access the unordered -collection of zero or more name/value pairs from the model. Similarly, -{@code JsonArray} provides a {@link java.util.List} view to access the ordered -sequence of zero or more values from the model. - -

The object model API uses builder patterns to create these object models. -Application code can use the interface {@link jakarta.json.JsonObjectBuilder} -to create models that represent JSON objects. The resulting model is of type -{@code JsonObject}. Refer to -this example -for more details. Application code can use the interface -{@link jakarta.json.JsonArrayBuilder} to create models that represent JSON arrays. -The resulting model is of type {@code JsonArray}. Refer to -this example -for more details. - -

These object models can also be created from an input source (such as -{@link java.io.InputStream} or {@link java.io.Reader}) using the interface -{@link jakarta.json.JsonReader}. -This example shows -how to read and create an empty {@code JsonArray} model using the interface -{@code JsonReader}. Similarly, these object models can be written to an output -source (such as {@link java.io.OutputStream} or {@link java.io.Writer}) using -the class {@link jakarta.json.JsonWriter}. -This example shows -how to write an empty {@code JsonObject} model using the interface -{@code JsonWriter}. - -

JSON Pointer, JSON Patch, and JSON Merge Patch

-Jakarta JSON Processing supports the latest standard on -JSON Pointer, -JSON Patch, and -JSON Merge Patch. - - - diff --git a/bundles/pom.xml b/bundles/pom.xml deleted file mode 100644 index 3b41f668..00000000 --- a/bundles/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - 4.0.0 - - - org.eclipse.jsonp - json - 2.0.2-SNAPSHOT - ../pom.xml - - - org.eclipse.jsonp - json-bundles - pom - Jakarta JSON Processing bundles - Jakarta JSON Processing bundles - https://github.com/eclipse-ee4j/jsonp - - - jakarta.json - ri - - diff --git a/bundles/ri/pom.xml b/bundles/ri/pom.xml deleted file mode 100755 index d6e98a43..00000000 --- a/bundles/ri/pom.xml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - 4.0.0 - - org.eclipse.jsonp - json-bundles - 2.0.2-SNAPSHOT - - - jakarta.json-ri - RI Distribution zip bundle - pom - - - - jakarta.json - jakarta.json-api - - - org.eclipse.jsonp - jsonp - - - org.eclipse.jsonp - jakarta.json - - - org.eclipse.jsonp - jsonp-jaxrs - - - - - - - maven-assembly-plugin - - - make-assembly - package - - single - - - - src/main/assembly/archive.xml - - false - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - stage - package - - unpack - - - **/module-info.java - - - ${project.groupId} - ${project.artifactId} - ${project.version} - zip - ${project.build.directory}/stage - - - - - - - - - diff --git a/bundles/ri/src/main/assembly/archive.xml b/bundles/ri/src/main/assembly/archive.xml deleted file mode 100755 index d73b28ed..00000000 --- a/bundles/ri/src/main/assembly/archive.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - dist - - zip - - - - src/main/resources/README.txt - - true - - - src/main/resources/LICENSE.md - - - - - - false - mods - - jakarta.json:jakarta.json-api:* - org.eclipse.jsonp:jsonp:* - - - - false - standalone - - org.eclipse.jsonp:jakarta.json:* - - - - false - jaxrs - - org.eclipse.jsonp:jsonp-jaxrs* - - - - diff --git a/bundles/ri/src/main/resources/LICENSE.md b/bundles/ri/src/main/resources/LICENSE.md deleted file mode 100644 index 5de3d1b4..00000000 --- a/bundles/ri/src/main/resources/LICENSE.md +++ /dev/null @@ -1,637 +0,0 @@ -# Eclipse Public License - v 2.0 - - THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE - PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION - OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - - 1. DEFINITIONS - - "Contribution" means: - - a) in the case of the initial Contributor, the initial content - Distributed under this Agreement, and - - b) in the case of each subsequent Contributor: - i) changes to the Program, and - ii) additions to the Program; - where such changes and/or additions to the Program originate from - and are Distributed by that particular Contributor. A Contribution - "originates" from a Contributor if it was added to the Program by - such Contributor itself or anyone acting on such Contributor's behalf. - Contributions do not include changes or additions to the Program that - are not Modified Works. - - "Contributor" means any person or entity that Distributes the Program. - - "Licensed Patents" mean patent claims licensable by a Contributor which - are necessarily infringed by the use or sale of its Contribution alone - or when combined with the Program. - - "Program" means the Contributions Distributed in accordance with this - Agreement. - - "Recipient" means anyone who receives the Program under this Agreement - or any Secondary License (as applicable), including Contributors. - - "Derivative Works" shall mean any work, whether in Source Code or other - form, that is based on (or derived from) the Program and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. - - "Modified Works" shall mean any work in Source Code or other form that - results from an addition to, deletion from, or modification of the - contents of the Program, including, for purposes of clarity any new file - in Source Code form that contains any contents of the Program. Modified - Works shall not include works that contain only declarations, - interfaces, types, classes, structures, or files of the Program solely - in each case in order to link to, bind by name, or subclass the Program - or Modified Works thereof. - - "Distribute" means the acts of a) distributing or b) making available - in any manner that enables the transfer of a copy. - - "Source Code" means the form of a Program preferred for making - modifications, including but not limited to software source code, - documentation source, and configuration files. - - "Secondary License" means either the GNU General Public License, - Version 2.0, or any later versions of that license, including any - exceptions or additional permissions as identified by the initial - Contributor. - - 2. GRANT OF RIGHTS - - a) Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free copyright - license to reproduce, prepare Derivative Works of, publicly display, - publicly perform, Distribute and sublicense the Contribution of such - Contributor, if any, and such Derivative Works. - - b) Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free patent - license under Licensed Patents to make, use, sell, offer to sell, - import and otherwise transfer the Contribution of such Contributor, - if any, in Source Code or other form. This patent license shall - apply to the combination of the Contribution and the Program if, at - the time the Contribution is added by the Contributor, such addition - of the Contribution causes such combination to be covered by the - Licensed Patents. The patent license shall not apply to any other - combinations which include the Contribution. No hardware per se is - licensed hereunder. - - c) Recipient understands that although each Contributor grants the - licenses to its Contributions set forth herein, no assurances are - provided by any Contributor that the Program does not infringe the - patent or other intellectual property rights of any other entity. - Each Contributor disclaims any liability to Recipient for claims - brought by any other entity based on infringement of intellectual - property rights or otherwise. As a condition to exercising the - rights and licenses granted hereunder, each Recipient hereby - assumes sole responsibility to secure any other intellectual - property rights needed, if any. For example, if a third party - patent license is required to allow Recipient to Distribute the - Program, it is Recipient's responsibility to acquire that license - before distributing the Program. - - d) Each Contributor represents that to its knowledge it has - sufficient copyright rights in its Contribution, if any, to grant - the copyright license set forth in this Agreement. - - e) Notwithstanding the terms of any Secondary License, no - Contributor makes additional grants to any Recipient (other than - those set forth in this Agreement) as a result of such Recipient's - receipt of the Program under the terms of a Secondary License - (if permitted under the terms of Section 3). - - 3. REQUIREMENTS - - 3.1 If a Contributor Distributes the Program in any form, then: - - a) the Program must also be made available as Source Code, in - accordance with section 3.2, and the Contributor must accompany - the Program with a statement that the Source Code for the Program - is available under this Agreement, and informs Recipients how to - obtain it in a reasonable manner on or through a medium customarily - used for software exchange; and - - b) the Contributor may Distribute the Program under a license - different than this Agreement, provided that such license: - i) effectively disclaims on behalf of all other Contributors all - warranties and conditions, express and implied, including - warranties or conditions of title and non-infringement, and - implied warranties or conditions of merchantability and fitness - for a particular purpose; - - ii) effectively excludes on behalf of all other Contributors all - liability for damages, including direct, indirect, special, - incidental and consequential damages, such as lost profits; - - iii) does not attempt to limit or alter the recipients' rights - in the Source Code under section 3.2; and - - iv) requires any subsequent distribution of the Program by any - party to be under a license that satisfies the requirements - of this section 3. - - 3.2 When the Program is Distributed as Source Code: - - a) it must be made available under this Agreement, or if the - Program (i) is combined with other material in a separate file or - files made available under a Secondary License, and (ii) the initial - Contributor attached to the Source Code the notice described in - Exhibit A of this Agreement, then the Program may be made available - under the terms of such Secondary Licenses, and - - b) a copy of this Agreement must be included with each copy of - the Program. - - 3.3 Contributors may not remove or alter any copyright, patent, - trademark, attribution notices, disclaimers of warranty, or limitations - of liability ("notices") contained within the Program from any copy of - the Program which they Distribute, provided that Contributors may add - their own appropriate notices. - - 4. COMMERCIAL DISTRIBUTION - - Commercial distributors of software may accept certain responsibilities - with respect to end users, business partners and the like. While this - license is intended to facilitate the commercial use of the Program, - the Contributor who includes the Program in a commercial product - offering should do so in a manner which does not create potential - liability for other Contributors. Therefore, if a Contributor includes - the Program in a commercial product offering, such Contributor - ("Commercial Contributor") hereby agrees to defend and indemnify every - other Contributor ("Indemnified Contributor") against any losses, - damages and costs (collectively "Losses") arising from claims, lawsuits - and other legal actions brought by a third party against the Indemnified - Contributor to the extent caused by the acts or omissions of such - Commercial Contributor in connection with its distribution of the Program - in a commercial product offering. The obligations in this section do not - apply to any claims or Losses relating to any actual or alleged - intellectual property infringement. In order to qualify, an Indemnified - Contributor must: a) promptly notify the Commercial Contributor in - writing of such claim, and b) allow the Commercial Contributor to control, - and cooperate with the Commercial Contributor in, the defense and any - related settlement negotiations. The Indemnified Contributor may - participate in any such claim at its own expense. - - For example, a Contributor might include the Program in a commercial - product offering, Product X. That Contributor is then a Commercial - Contributor. If that Commercial Contributor then makes performance - claims, or offers warranties related to Product X, those performance - claims and warranties are such Commercial Contributor's responsibility - alone. Under this section, the Commercial Contributor would have to - defend claims against the other Contributors related to those performance - claims and warranties, and if a court requires any other Contributor to - pay any damages as a result, the Commercial Contributor must pay - those damages. - - 5. NO WARRANTY - - EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT - PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR - IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF - TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR - PURPOSE. Each Recipient is solely responsible for determining the - appropriateness of using and distributing the Program and assumes all - risks associated with its exercise of rights under this Agreement, - including but not limited to the risks and costs of program errors, - compliance with applicable laws, damage to or loss of data, programs - or equipment, and unavailability or interruption of operations. - - 6. DISCLAIMER OF LIABILITY - - EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT - PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS - SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST - PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE - EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGES. - - 7. GENERAL - - If any provision of this Agreement is invalid or unenforceable under - applicable law, it shall not affect the validity or enforceability of - the remainder of the terms of this Agreement, and without further - action by the parties hereto, such provision shall be reformed to the - minimum extent necessary to make such provision valid and enforceable. - - If Recipient institutes patent litigation against any entity - (including a cross-claim or counterclaim in a lawsuit) alleging that the - Program itself (excluding combinations of the Program with other software - or hardware) infringes such Recipient's patent(s), then such Recipient's - rights granted under Section 2(b) shall terminate as of the date such - litigation is filed. - - All Recipient's rights under this Agreement shall terminate if it - fails to comply with any of the material terms or conditions of this - Agreement and does not cure such failure in a reasonable period of - time after becoming aware of such noncompliance. If all Recipient's - rights under this Agreement terminate, Recipient agrees to cease use - and distribution of the Program as soon as reasonably practicable. - However, Recipient's obligations under this Agreement and any licenses - granted by Recipient relating to the Program shall continue and survive. - - Everyone is permitted to copy and distribute copies of this Agreement, - but in order to avoid inconsistency the Agreement is copyrighted and - may only be modified in the following manner. The Agreement Steward - reserves the right to publish new versions (including revisions) of - this Agreement from time to time. No one other than the Agreement - Steward has the right to modify this Agreement. The Eclipse Foundation - is the initial Agreement Steward. The Eclipse Foundation may assign the - responsibility to serve as the Agreement Steward to a suitable separate - entity. Each new version of the Agreement will be given a distinguishing - version number. The Program (including Contributions) may always be - Distributed subject to the version of the Agreement under which it was - received. In addition, after a new version of the Agreement is published, - Contributor may elect to Distribute the Program (including its - Contributions) under the new version. - - Except as expressly stated in Sections 2(a) and 2(b) above, Recipient - receives no rights or licenses to the intellectual property of any - Contributor under this Agreement, whether expressly, by implication, - estoppel or otherwise. All rights in the Program not expressly granted - under this Agreement are reserved. Nothing in this Agreement is intended - to be enforceable by any entity that is not a Contributor or Recipient. - No third-party beneficiary rights are created under this Agreement. - - Exhibit A - Form of Secondary Licenses Notice - - "This Source Code may also be made available under the following - Secondary Licenses when the conditions for such availability set forth - in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), - version(s), and exceptions or additional permissions here}." - - Simply including a copy of this Agreement, including this Exhibit A - is not sufficient to license the Source Code under Secondary Licenses. - - If it is not possible or desirable to put the notice in a particular - file, then You may include the notice in a location (such as a LICENSE - file in a relevant directory) where a recipient would be likely to - look for such a notice. - - You may add additional accurate notices of copyright ownership. - ---- - -## The GNU General Public License (GPL) Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1335 - USA - - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your freedom to - share and change it. By contrast, the GNU General Public License is - intended to guarantee your freedom to share and change free software--to - make sure the software is free for all its users. This General Public - License applies to most of the Free Software Foundation's software and - to any other program whose authors commit to using it. (Some other Free - Software Foundation software is covered by the GNU Library General - Public License instead.) You can apply it to your programs, too. - - When we speak of free software, we are referring to freedom, not price. - Our General Public Licenses are designed to make sure that you have the - freedom to distribute copies of free software (and charge for this - service if you wish), that you receive source code or can get it if you - want it, that you can change the software or use pieces of it in new - free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid anyone - to deny you these rights or to ask you to surrender the rights. These - restrictions translate to certain responsibilities for you if you - distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether gratis - or for a fee, you must give the recipients all the rights that you have. - You must make sure that they, too, receive or can get the source code. - And you must show them these terms so they know their rights. - - We protect your rights with two steps: (1) copyright the software, and - (2) offer you this license which gives you legal permission to copy, - distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain - that everyone understands that there is no warranty for this free - software. If the software is modified by someone else and passed on, we - want its recipients to know that what they have is not the original, so - that any problems introduced by others will not reflect on the original - authors' reputations. - - Finally, any free program is threatened constantly by software patents. - We wish to avoid the danger that redistributors of a free program will - individually obtain patent licenses, in effect making the program - proprietary. To prevent this, we have made it clear that any patent must - be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and - modification follow. - - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains a - notice placed by the copyright holder saying it may be distributed under - the terms of this General Public License. The "Program", below, refers - to any such program or work, and a "work based on the Program" means - either the Program or any derivative work under copyright law: that is - to say, a work containing the Program or a portion of it, either - verbatim or with modifications and/or translated into another language. - (Hereinafter, translation is included without limitation in the term - "modification".) Each licensee is addressed as "you". - - Activities other than copying, distribution and modification are not - covered by this License; they are outside its scope. The act of running - the Program is not restricted, and the output from the Program is - covered only if its contents constitute a work based on the Program - (independent of having been made by running the Program). Whether that - is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's source - code as you receive it, in any medium, provided that you conspicuously - and appropriately publish on each copy an appropriate copyright notice - and disclaimer of warranty; keep intact all the notices that refer to - this License and to the absence of any warranty; and give any other - recipients of the Program a copy of this License along with the Program. - - You may charge a fee for the physical act of transferring a copy, and - you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion of - it, thus forming a work based on the Program, and copy and distribute - such modifications or work under the terms of Section 1 above, provided - that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any part - thereof, to be licensed as a whole at no charge to all third parties - under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a notice - that there is no warranty (or else, saying that you provide a - warranty) and that users may redistribute the program under these - conditions, and telling the user how to view a copy of this License. - (Exception: if the Program itself is interactive but does not - normally print such an announcement, your work based on the Program - is not required to print an announcement.) - - These requirements apply to the modified work as a whole. If - identifiable sections of that work are not derived from the Program, and - can be reasonably considered independent and separate works in - themselves, then this License, and its terms, do not apply to those - sections when you distribute them as separate works. But when you - distribute the same sections as part of a whole which is a work based on - the Program, the distribution of the whole must be on the terms of this - License, whose permissions for other licensees extend to the entire - whole, and thus to each and every part regardless of who wrote it. - - Thus, it is not the intent of this section to claim rights or contest - your rights to work written entirely by you; rather, the intent is to - exercise the right to control the distribution of derivative or - collective works based on the Program. - - In addition, mere aggregation of another work not based on the Program - with the Program (or with a work based on the Program) on a volume of a - storage or distribution medium does not bring the other work under the - scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, - under Section 2) in object code or executable form under the terms of - Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections 1 - and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your cost - of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to - distribute corresponding source code. (This alternative is allowed - only for noncommercial distribution and only if you received the - program in object code or executable form with such an offer, in - accord with Subsection b above.) - - The source code for a work means the preferred form of the work for - making modifications to it. For an executable work, complete source code - means all the source code for all modules it contains, plus any - associated interface definition files, plus the scripts used to control - compilation and installation of the executable. However, as a special - exception, the source code distributed need not include anything that is - normally distributed (in either source or binary form) with the major - components (compiler, kernel, and so on) of the operating system on - which the executable runs, unless that component itself accompanies the - executable. - - If distribution of executable or object code is made by offering access - to copy from a designated place, then offering equivalent access to copy - the source code from the same place counts as distribution of the source - code, even though third parties are not compelled to copy the source - along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program - except as expressly provided under this License. Any attempt otherwise - to copy, modify, sublicense or distribute the Program is void, and will - automatically terminate your rights under this License. However, parties - who have received copies, or rights, from you under this License will - not have their licenses terminated so long as such parties remain in - full compliance. - - 5. You are not required to accept this License, since you have not - signed it. However, nothing else grants you permission to modify or - distribute the Program or its derivative works. These actions are - prohibited by law if you do not accept this License. Therefore, by - modifying or distributing the Program (or any work based on the - Program), you indicate your acceptance of this License to do so, and all - its terms and conditions for copying, distributing or modifying the - Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the - Program), the recipient automatically receives a license from the - original licensor to copy, distribute or modify the Program subject to - these terms and conditions. You may not impose any further restrictions - on the recipients' exercise of the rights granted herein. You are not - responsible for enforcing compliance by third parties to this License. - - 7. If, as a consequence of a court judgment or allegation of patent - infringement or for any other reason (not limited to patent issues), - conditions are imposed on you (whether by court order, agreement or - otherwise) that contradict the conditions of this License, they do not - excuse you from the conditions of this License. If you cannot distribute - so as to satisfy simultaneously your obligations under this License and - any other pertinent obligations, then as a consequence you may not - distribute the Program at all. For example, if a patent license would - not permit royalty-free redistribution of the Program by all those who - receive copies directly or indirectly through you, then the only way you - could satisfy both it and this License would be to refrain entirely from - distribution of the Program. - - If any portion of this section is held invalid or unenforceable under - any particular circumstance, the balance of the section is intended to - apply and the section as a whole is intended to apply in other - circumstances. - - It is not the purpose of this section to induce you to infringe any - patents or other property right claims or to contest validity of any - such claims; this section has the sole purpose of protecting the - integrity of the free software distribution system, which is implemented - by public license practices. Many people have made generous - contributions to the wide range of software distributed through that - system in reliance on consistent application of that system; it is up to - the author/donor to decide if he or she is willing to distribute - software through any other system and a licensee cannot impose that choice. - - This section is intended to make thoroughly clear what is believed to be - a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in - certain countries either by patents or by copyrighted interfaces, the - original copyright holder who places the Program under this License may - add an explicit geographical distribution limitation excluding those - countries, so that distribution is permitted only in or among countries - not thus excluded. In such case, this License incorporates the - limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new - versions of the General Public License from time to time. Such new - versions will be similar in spirit to the present version, but may - differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the Program - specifies a version number of this License which applies to it and "any - later version", you have the option of following the terms and - conditions either of that version or of any later version published by - the Free Software Foundation. If the Program does not specify a version - number of this License, you may choose any version ever published by the - Free Software Foundation. - - 10. If you wish to incorporate parts of the Program into other free - programs whose distribution conditions are different, write to the - author to ask for permission. For software which is copyrighted by the - Free Software Foundation, write to the Free Software Foundation; we - sometimes make exceptions for this. Our decision will be guided by the - two goals of preserving the free status of all derivatives of our free - software and of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO - WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. - EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR - OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, - EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE - ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH - YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL - NECESSARY SERVICING, REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN - WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY - AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR - DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL - DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM - (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED - INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF - THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR - OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest - possible use to the public, the best way to achieve this is to make it - free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest to - attach them to the start of each source file to most effectively convey - the exclusion of warranty; and each file should have at least the - "copyright" line and a pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - - Also add information on how to contact you by electronic and paper mail. - - If the program is interactive, make it output a short notice like this - when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type - `show w'. This is free software, and you are welcome to redistribute - it under certain conditions; type `show c' for details. - - The hypothetical commands `show w' and `show c' should show the - appropriate parts of the General Public License. Of course, the commands - you use may be called something other than `show w' and `show c'; they - could even be mouse-clicks or menu items--whatever suits your program. - - You should also get your employer (if you work as a programmer) or your - school, if any, to sign a "copyright disclaimer" for the program, if - necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - program `Gnomovision' (which makes passes at compilers) written by - James Hacker. - - signature of Ty Coon, 1 April 1989 - Ty Coon, President of Vice - - This General Public License does not permit incorporating your program - into proprietary programs. If your program is a subroutine library, you - may consider it more useful to permit linking proprietary applications - with the library. If this is what you want to do, use the GNU Library - General Public License instead of this License. - ---- - -## CLASSPATH EXCEPTION - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License version 2 cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from or - based on this library. If you modify this library, you may extend this - exception to your version of the library, but you are not obligated to - do so. If you do not wish to do so, delete this exception statement - from your version. diff --git a/bundles/ri/src/main/resources/README.txt b/bundles/ri/src/main/resources/README.txt deleted file mode 100644 index 8843418a..00000000 --- a/bundles/ri/src/main/resources/README.txt +++ /dev/null @@ -1,51 +0,0 @@ -For running on JPMS, following modules are provided: -* mods/jakarta.json-api-${project.version}.jar - 'jakarta.json' module containing only API classes -* mods/jsonp-${project.version}.jar - 'org.eclipse.jsonp' module containing implementation - -Integration with Jakarta RESTful Web Services: -* jaxrs/jsonp-jaxrs-${project.version}.jar - -* standalone/jakarta.json-${project.version}.jar - 'jakarta.json' module containing API classes and implementation, which serves as a fallback for environments -willing to support different implementations of Jakarta JSON Processing API while also providing some default implementation, such as application servers. -When this library is used, then Eclipse JSONP is the default implementation being provided. - -NOTE: jakarta.json-api.jar and jakarta.json.jar CAN NOT co-exist together when running on JPMS. One can be used as a drop-in -replacement of the other wrt Jakarta JSON Processing API. - -IMPORTANT NOTE: module names are not yet final and may change in the future releases - - -* If you are running with maven, you can use the following maven coordinates: - -for the implementation: - - org.eclipse.jsonp - jsonp - ${project.version} - - -for APIs: - - jakarta.json - jakarta.json-api - ${api.version} - - -for Jakarta RESTful Web Services integration module: - - org.eclipse.jsonp - jsonp-jaxrs - ${project.version} - - -for Jakarta JSON Processing API which uses Eclipse JSONP as a default provider: - - org.eclipse.jsonp - jakarta.json - ${project.version} - - -* GlassFish 6.x already bundles latest Jakarta JSON Processing implementation and Jakarta RESTful Web Services integration module. -If you deploy an application with GlassFish 6.x, your application (war/ear) doesn't have to bundle APIs nor the implementation. - -* Samples can be run from https://github.com/eclipse-ee4j/glassfish-samples diff --git a/demos/LICENSE.md b/demos/LICENSE.md deleted file mode 100644 index c739f78b..00000000 --- a/demos/LICENSE.md +++ /dev/null @@ -1,29 +0,0 @@ - - Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - - Neither the name of the Eclipse Foundation, Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/demos/NOTICE.md b/demos/NOTICE.md deleted file mode 100644 index b4cb5bae..00000000 --- a/demos/NOTICE.md +++ /dev/null @@ -1,49 +0,0 @@ -# Notices for Eclipse Project for JSON Processing - -This content is produced and maintained by the Eclipse Project for JSON -Processing project. - -* Project home: https://projects.eclipse.org/projects/ee4j.jsonp - -## Trademarks - -Eclipse Project for JSON Processing is a trademark of the Eclipse Foundation. - -## Copyright - -All content is the property of the respective authors or their employers. For -more information regarding authorship of content, please consult the listed -source code repository logs. - -## Declared Project Licenses - -This program and the accompanying materials are made available under the terms -of the Eclipse Public License v. 2.0 which is available at -http://www.eclipse.org/legal/epl-2.0. This Source Code may also be made -available under the following Secondary Licenses when the conditions for such -availability set forth in the Eclipse Public License v. 2.0 are satisfied: GNU -General Public License, version 2 with the GNU Classpath Exception which is -available at https://www.gnu.org/software/classpath/license.html. - -SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - -## Source Code - -The project maintains the following source code repositories: - -* https://github.com/eclipse-ee4j/jsonp - -## Third-party Content - -JUnit (4.12) - -* License: Eclipse Public License - -## Cryptography - -Content may contain encryption software. The country in which you are currently -may have restrictions on the import, possession, and use, and/or re-export to -another country, of encryption software. BEFORE using any encryption software, -please check the country's laws, regulations and policies concerning the import, -possession, or use, and re-export of encryption software, to see if this is -permitted. diff --git a/demos/customprovider-jdk9/pom.xml b/demos/customprovider-jdk9/pom.xml deleted file mode 100644 index 1354a456..00000000 --- a/demos/customprovider-jdk9/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - http://maven.apache.org - customprovider-jdk9 - - customprovider-jdk9 - - - ${project.build.directory}/mods - - - customprovider-jdk9 - - - org.apache.maven.plugins - maven-dependency-plugin - - - prepare-endorsed - validate - - copy-dependencies - - - ${mod.dir} - false - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - test - - test - - - - - --module-path ${project.build.directory}/classes:${mod.dir}:${project.build.directory}/test-classes - --add-modules org.eclipse.jsonp.demos.customprovider - - - - - - - - jakarta.json - jakarta.json-api - - - junit - junit - test - - - org.hamcrest - hamcrest-core - test - - - diff --git a/demos/customprovider-jdk9/src/main/java/module-info.java b/demos/customprovider-jdk9/src/main/java/module-info.java deleted file mode 100644 index 10cbe8c8..00000000 --- a/demos/customprovider-jdk9/src/main/java/module-info.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -module org.eclipse.jsonp.demos.customprovider { - requires transitive jakarta.json; - exports org.eclipse.jsonp.demos.customprovider; - provides jakarta.json.spi.JsonProvider with org.eclipse.jsonp.demos.customprovider.TestProvider; -} diff --git a/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestGenerator.java b/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestGenerator.java deleted file mode 100644 index 661a848c..00000000 --- a/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestGenerator.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.customprovider; - -import jakarta.json.JsonException; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonGenerator; -import java.io.IOException; -import java.io.Writer; -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * @author Jitendra Kotamraju - */ -public class TestGenerator implements JsonGenerator { - private final Writer writer; - - public TestGenerator(Writer writer) { - this.writer = writer; - } - - @Override - public void flush() { - } - - @Override - public JsonGenerator writeStartObject() { - return null; - } - - @Override - public JsonGenerator writeStartObject(String name) { - return null; - } - - @Override - public JsonGenerator write(String name, String fieldValue) { - return null; - } - - @Override - public JsonGenerator write(String name, int value) { - return null; - } - - @Override - public JsonGenerator write(String name, long value) { - return null; - } - - @Override - public JsonGenerator write(String name, double value) { - return null; - } - - @Override - public JsonGenerator write(String name, BigInteger value) { - return null; - } - - @Override - public JsonGenerator write(String name, BigDecimal value) { - return null; - } - - @Override - public JsonGenerator write(String name, boolean value) { - return null; - } - - @Override - public JsonGenerator writeNull(String name) { - return null; - } - - @Override - public JsonGenerator write(JsonValue value) { - return null; - } - - @Override - public JsonGenerator writeStartArray() { - try { - writer.write("["); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - return this; - } - - @Override - public JsonGenerator writeStartArray(String name) { - return null; - } - - @Override - public JsonGenerator write(String name, JsonValue value) { - return null; - } - - @Override - public JsonGenerator write(String value) { - return null; - } - - - @Override - public JsonGenerator write(int value) { - return null; - } - - @Override - public JsonGenerator write(long value) { - return null; - } - - @Override - public JsonGenerator write(double value) { - return null; - } - - @Override - public JsonGenerator write(BigInteger value) { - return null; - } - - @Override - public JsonGenerator write(BigDecimal value) { - return null; - } - - @Override - public JsonGenerator write(boolean value) { - return null; - } - - @Override - public JsonGenerator writeNull() { - return null; - } - - @Override - public JsonGenerator writeEnd() { - try { - writer.write("]"); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - return this; - } - - @Override - public void close() { - try { - writer.close(); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - } - - @Override - public JsonGenerator writeKey(String string) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestProvider.java b/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestProvider.java deleted file mode 100644 index 31058ba8..00000000 --- a/demos/customprovider-jdk9/src/main/java/org/eclipse/jsonp/demos/customprovider/TestProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.customprovider; - -import jakarta.json.spi.JsonProvider; -import jakarta.json.stream.JsonGenerator; -import jakarta.json.stream.JsonGeneratorFactory; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParserFactory; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Map; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonReader; -import jakarta.json.JsonReaderFactory; -import jakarta.json.JsonWriter; -import jakarta.json.JsonWriterFactory; - -/** - * @author Jitendra Kotamraju - */ -public class TestProvider extends JsonProvider { - - @Override - public JsonGenerator createGenerator(Writer writer) { - return new TestGenerator(writer); - } - - @Override - public JsonGenerator createGenerator(OutputStream out) { - return new TestGenerator(new OutputStreamWriter(out)); - } - - @Override - public JsonGeneratorFactory createGeneratorFactory(Map config) { - return null; - } - - @Override - public JsonReader createReader(Reader reader) { - return null; - } - - @Override - public JsonReader createReader(InputStream in) { - return null; - } - - @Override - public JsonWriter createWriter(Writer writer) { - return null; - } - - @Override - public JsonWriter createWriter(OutputStream out) { - return null; - } - - @Override - public JsonWriterFactory createWriterFactory(Map config) { - return null; - } - - @Override - public JsonReaderFactory createReaderFactory(Map config) { - return null; - } - - @Override - public JsonObjectBuilder createObjectBuilder() { - return null; - } - - @Override - public JsonArrayBuilder createArrayBuilder() { - return null; - } - - @Override - public JsonBuilderFactory createBuilderFactory(Map config) { - return null; - } - - @Override - public JsonParser createParser(Reader reader) { - return null; - } - - @Override - public JsonParser createParser(InputStream in) { - return null; - } - - @Override - public JsonParserFactory createParserFactory(Map config) { - return null; - } - - -} diff --git a/demos/customprovider-jdk9/src/test/java/customprovider/test/TestProviderTest.java b/demos/customprovider-jdk9/src/test/java/customprovider/test/TestProviderTest.java deleted file mode 100644 index a820596e..00000000 --- a/demos/customprovider-jdk9/src/test/java/customprovider/test/TestProviderTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package customprovider.test; - -import jakarta.json.Json; -import jakarta.json.stream.JsonGenerator; -import org.eclipse.jsonp.demos.customprovider.TestGenerator; -import org.junit.Assert; -import org.junit.Test; - -/** - * - * @author lukas - */ -public class TestProviderTest { - - @Test - public void hello() { - try (JsonGenerator generator = Json.createGenerator(System.out)) { - Assert.assertTrue("TestGenerator is not picked up", generator instanceof TestGenerator); - generator.writeStartArray().writeEnd(); - } - System.out.println(); - System.out.println("Hurray!!!"); - } -} diff --git a/demos/facebook/pom.xml b/demos/facebook/pom.xml deleted file mode 100644 index 7229e0fc..00000000 --- a/demos/facebook/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - jar - http://maven.apache.org - jsondemos-facebook - - - org.eclipse.jsonp.demos.facebook.FacebookObjectSearch - - ${project.build.directory}/modules - - - - - org.eclipse.jsonp - jakarta.json - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - true - ${modules.directory} - - - - get-dependencies - package - - copy-dependencies - - - - get-project-artifact - package - - copy - - - - - ${project.groupId} - ${project.artifactId} - ${project.version} - - - - - - - - org.codehaus.mojo - exec-maven-plugin - - java - - --module-path - ${modules.directory} - -m - org.eclipse.jsonp.demos.facebook/${main.class} - - - - - example-facebook - - exec - - - - - - - - diff --git a/demos/facebook/src/main/java/module-info.java b/demos/facebook/src/main/java/module-info.java deleted file mode 100644 index 15464c70..00000000 --- a/demos/facebook/src/main/java/module-info.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -module org.eclipse.jsonp.demos.facebook { - requires jakarta.json; -} diff --git a/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookObjectSearch.java b/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookObjectSearch.java deleted file mode 100644 index 30efc2a2..00000000 --- a/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookObjectSearch.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.facebook; - -import jakarta.json.*; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Properties; - -/** - * Parses JSON from facebook graph API using object model API. - * JSON would like : - * - * { - * data: [ - * { "from" : { "name" : "xxx", ... }, "message: "yyy", ... }, - * { "from" : { "name" : "ppp", ... }, "message: "qqq", ... }, - * ... - * ], - * ... - * } - * - * This codes writes the facebook posts to output as follows: - * xxx: yyy - * -------- - * ppp: qqq - * -------- - * - * @author Jitendra Kotamraju - */ -public class FacebookObjectSearch { - - public static void main(String... args) throws Exception { - try (InputStream is = getSearchStream(); - JsonReader rdr = Json.createReader(is)) { - - JsonObject obj = rdr.readObject(); - JsonArray results = obj.getJsonArray("data"); - for (JsonObject result : results.getValuesAs(JsonObject.class)) { - JsonValue value = result.get("from"); - if (value != null && value instanceof JsonObject) { - System.out.print(((JsonObject)value).getString("name", "anon")); - } - System.out.print(": "); - System.out.println(result.getString("message", "")); - System.out.println("-----------"); - } - } - } - - static InputStream getSearchStream() throws Exception { - Properties config = new Properties(); - config.load(FacebookObjectSearch.class.getResourceAsStream( - "/facebookconfig.properties")); - final String accessToken = (String)config.get("access_token"); - - // Gets the search stream - String searchUrl = "https://graph.facebook.com/search?q=tamil&type=post&access_token="; - URL url = new URL(searchUrl+accessToken); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); - return con.getInputStream(); - } - -} diff --git a/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookStreamSearch.java b/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookStreamSearch.java deleted file mode 100644 index 768ab030..00000000 --- a/demos/facebook/src/main/java/org/eclipse/jsonp/demos/facebook/FacebookStreamSearch.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.facebook; - -import jakarta.json.*; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParser.Event; -import java.io.*; - -/** - * Parses JSON from facebook graph API using streaming API. - * JSON would like : - * - * { - * data: [ - * { "from" : { "name" : "xxx", ... }, "message: "yyy", ... }, - * { "from" : { "name" : "ppp", ... }, "message: "qqq", ... }, - * ... - * ], - * ... - * } - * - * This codes writes the facebook posts to output as follows: - * xxx: yyy - * -------- - * ppp: qqq - * -------- - * - * @author Jitendra Kotamraju - */ -public class FacebookStreamSearch { - - public static void main(String... args) throws Exception { - try (InputStream is = FacebookObjectSearch.getSearchStream(); - JsonParser parser = Json.createParser(is)) { - while (parser.hasNext()) { - Event e = parser.next(); - if (e == Event.KEY_NAME) { - switch (parser.getString()) { - case "name": - parser.next(); - System.out.print(parser.getString()); - System.out.print(": "); - break; - case "message": - parser.next(); - System.out.println(parser.getString()); - System.out.println("---------"); - break; - } - } - } - } - } - -} diff --git a/demos/facebook/src/main/resources/facebookconfig.properties b/demos/facebook/src/main/resources/facebookconfig.properties deleted file mode 100644 index f801f7d5..00000000 --- a/demos/facebook/src/main/resources/facebookconfig.properties +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Distribution License v. 1.0, which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: BSD-3-Clause -# - - -access_token= diff --git a/demos/jaxrs/pom.xml b/demos/jaxrs/pom.xml deleted file mode 100644 index a9b64189..00000000 --- a/demos/jaxrs/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - war - http://maven.apache.org - jsondemos-jaxrs - - jsondemos-jaxrs - - - - jakarta.ws.rs - jakarta.ws.rs-api - provided - - - jakarta.json - jakarta.json-api - provided - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-war-plugin - - - jsondemos-jaxrs - - diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ArrayResource.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ArrayResource.java deleted file mode 100644 index 28c90093..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ArrayResource.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.*; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; - -/** - * JsonArray as parameter and return type for a Jakarta RESTful Web Services resource - * - * @author Jitendra Kotamraju - */ -@Path("/array") -public class ArrayResource { - private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); - - @GET - @Produces(MediaType.APPLICATION_JSON) - public JsonArray doGet() { - return bf.createArrayBuilder() - .add(bf.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(bf.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567")) - .build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void doPost(JsonArray structure) { - System.out.println(structure); - } - -} diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/DemoApplication.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/DemoApplication.java deleted file mode 100644 index 7bf3cfa4..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/DemoApplication.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.stream.JsonGenerator; -import jakarta.ws.rs.ApplicationPath; -import jakarta.ws.rs.core.Application; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * A Jakarta RESTful Web Services Demo Application - * - * @author Jitendra Kotamraju - */ -@ApplicationPath("/") -public class DemoApplication extends Application { - - @Override - public Set> getClasses() { - Set> set = new HashSet<>(); - set.add(ParserResource.class); - set.add(GeneratorResource.class); - set.add(ObjectResource.class); - set.add(ArrayResource.class); - set.add(StructureResource.class); - - return set; - } - - @Override - public Map getProperties() { - return new HashMap() {{ - put(JsonGenerator.PRETTY_PRINTING, true); - }}; - } -} diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/GeneratorResource.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/GeneratorResource.java deleted file mode 100644 index 291607a0..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/GeneratorResource.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.Json; -import jakarta.json.stream.JsonGenerator; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.StreamingOutput; -import java.io.OutputStream; - -/** - * Writes wiki's JSON example in a streaming fashion using JsonGenerator - * - * @author Jitendra Kotamraju - */ -@Path("/generator") -public class GeneratorResource { - - @GET - @Produces(MediaType.APPLICATION_JSON) - public StreamingOutput doGet() { - return new StreamingOutput() { - public void write(OutputStream os) { - writeWikiExample(os); - } - }; - } - - // Writes wiki example JSON in a streaming fashion - private void writeWikiExample(OutputStream os) { - try(JsonGenerator gene = Json.createGenerator(os)) { - gene.writeStartObject() - .write("firstName", "John") - .write("lastName", "Smith") - .write("age", 25) - .writeStartObject("address") - .write("streetAddress", "21 2nd Street") - .write("city", "New York") - .write("state", "NY") - .write("postalCode", "10021") - .writeEnd() - .writeStartArray("phoneNumber") - .writeStartObject() - .write("type", "home") - .write("number", "212 555-1234") - .writeEnd() - .writeStartObject() - .write("type", "fax") - .write("number", "646 555-4567") - .writeEnd() - .writeEnd() - .writeEnd(); - } - } - -} diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ObjectResource.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ObjectResource.java deleted file mode 100644 index fb342d13..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ObjectResource.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.*; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; - -/** - * JsonObject as parameter and return type for a - * Jakarta RESTful Web Services resource - * Writes a person's representation as JSON using JsonObject - * - * @author Jitendra Kotamraju - */ -@Path("/object") -public class ObjectResource { - private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); - - @GET - @Produces(MediaType.APPLICATION_JSON) - public JsonObject doGet() { - return bf.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", bf.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", bf.createArrayBuilder() - .add(bf.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(bf.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void doPost(JsonObject structure) { - System.out.println(structure); - } - -} diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ParserResource.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ParserResource.java deleted file mode 100644 index 6e880780..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/ParserResource.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.Json; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParser.Event; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.StreamingOutput; -import java.io.*; -import java.net.URL; - -/** - * Filters JSON from flicker photo search REST API - * - * { - * photos : { - * photo: [ - * { id: "9889087315", secret: "40aeb70c83", server: "3818",farm: 4, ..}, - * { id: "9889087315", secret: "40aeb70c83", server: "3818",farm: 4, ..} - * ... - * ], - * ... - * } - * } - * - * @author Jitendra Kotamraju - */ -@Path("/parser") -public class ParserResource { - - @GET - @Produces("text/html") - public StreamingOutput doGet() { - return new StreamingOutput() { - public void write(OutputStream os) throws IOException { - writeFlickerFeed(os); - } - }; - } - - private void writeFlickerFeed(OutputStream os) throws IOException { - URL url = new URL("http://api.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=221160312e1c22ec60ecf336951b0e77&format=json&nojsoncallback=1&per_page=20"); - try(InputStream is = url.openStream(); - JsonParser parser = Json.createParser(is); - PrintWriter ps = new PrintWriter(new OutputStreamWriter(os, "UTF-8"))) { - String id = null; - String server = null; - String secret = null; - - ps.println(""); - while(parser.hasNext()) { - Event e = parser.next(); - if (e == Event.KEY_NAME) { - String str = parser.getString(); - switch (str) { - case "id" : - parser.next(); - id = parser.getString(); - break; - case "farm" : - parser.next(); - String farm = parser.getString(); - ps.println(""); - break; - case "server" : - parser.next(); - server = parser.getString(); - break; - case "secret" : - parser.next(); - secret = parser.getString(); - break; - } - } - } - ps.println(""); - ps.flush(); - } - } - -} diff --git a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/StructureResource.java b/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/StructureResource.java deleted file mode 100644 index dfdd9067..00000000 --- a/demos/jaxrs/src/main/java/org/eclipse/jsonp/demos/jaxrs/StructureResource.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jaxrs; - -import jakarta.json.*; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; - -/** - * JsonStructure as parameter and return type for a - * Jakarta RESTful Web Services resource - * - * @author Jitendra Kotamraju - */ -@Path("/structure") -public class StructureResource { - private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); - - @GET - @Produces(MediaType.APPLICATION_JSON) - public JsonStructure doGet() { - return bf.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", bf.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", bf.createArrayBuilder() - .add(bf.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(bf.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void doPost(JsonStructure structure) { - System.out.println(structure); - } - -} diff --git a/demos/jsonpointer/pom.xml b/demos/jsonpointer/pom.xml deleted file mode 100644 index 6b3658c6..00000000 --- a/demos/jsonpointer/pom.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - jar - http://maven.apache.org - jsondemos-jsonpointer - - - org.eclipse.jsonp.demos.jsonpointer.JsonpointerDemo - ${project.build.directory}/modules - - - - - jakarta.json - jakarta.json-api - compile - - - org.eclipse.jsonp - jsonp - compile - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - false - - - - org.apache.maven.plugins - maven-dependency-plugin - - true - ${modules.directory} - - - - get-dependencies - package - - copy-dependencies - - - - get-project-artifact - package - - copy - - - - - ${project.groupId} - ${project.artifactId} - ${project.version} - - - - - - - - org.codehaus.mojo - exec-maven-plugin - - java - - --module-path - ${modules.directory} - -m - org.eclipse.jsonp.demos.jsonpointer/${main.class} - - - - - example-jsonpointer - verify - - exec - - - - - - - diff --git a/demos/jsonpointer/src/main/java/module-info.java b/demos/jsonpointer/src/main/java/module-info.java deleted file mode 100644 index 26b1bbc6..00000000 --- a/demos/jsonpointer/src/main/java/module-info.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -module org.eclipse.jsonp.demos.jsonpointer { - requires jakarta.json; -} diff --git a/demos/jsonpointer/src/main/java/org/eclipse/jsonp/demos/jsonpointer/JsonpointerDemo.java b/demos/jsonpointer/src/main/java/org/eclipse/jsonp/demos/jsonpointer/JsonpointerDemo.java deleted file mode 100644 index fd3b2762..00000000 --- a/demos/jsonpointer/src/main/java/org/eclipse/jsonp/demos/jsonpointer/JsonpointerDemo.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.jsonpointer; - -import java.io.IOException; -import java.io.InputStream; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; - -/** - * JsonPointer (http://tools.ietf.org/html/rfc6901) demo with object model API - * - * @author Jitendra Kotamraju - */ -public class JsonpointerDemo { - - public static void main(String... args) throws Exception { - testWiki(); - testPointer(); - System.out.println("Both tests PASSED !!!"); - } - - private static void testWiki() throws IOException { - try (InputStream is = JsonpointerDemo.class.getResourceAsStream("/wiki.json"); - JsonReader rdr = Json.createReader(is)) { - JsonObject person = rdr.readObject(); - - assertEquals("NY", getString(person, "/address/state")); - assertEquals("212 555-1234", getString(person, "/phoneNumber/0/number")); - } - } - - private static void testPointer() throws IOException { - try (InputStream is = JsonpointerDemo.class.getResourceAsStream("/jsonpointer.json"); - JsonReader rdr = Json.createReader(is)) { - JsonObject root = rdr.readObject(); - - assertEquals(root, get(root, "")); - assertEquals(root.get("foo"), get(root, "/foo")); - assertEquals(root.getJsonArray("foo").get(0), get(root, "/foo/0")); - assertEquals(root.get(""), get(root, "/")); - assertEquals(root.get("a/b"), get(root, "/a~1b")); - assertEquals(root.get("c%d"), get(root, "/c%d")); - assertEquals(root.get("e^f"), get(root, "/e^f")); - assertEquals(root.get("k\"l"), get(root, "/k\"l")); - assertEquals(root.get("i\\j"), get(root, "/i\\j")); - assertEquals(root.get(" "), get(root, "/ ")); - assertEquals(root.get("m~n"), get(root, "/m~0n")); - - // Adding a parent to current root and try with it - JsonObject doc = Json.createObjectBuilder().add("doc", root).build(); - root = doc.getJsonObject("doc"); - assertEquals(doc, get(doc, "")); - assertEquals(root.get("foo"), get(doc, "/doc/foo")); - assertEquals(root.getJsonArray("foo").get(0), get(doc, "/doc/foo/0")); - assertEquals(root.get(""), get(doc, "/doc/")); - assertEquals(root.get("a/b"), get(doc, "/doc/a~1b")); - assertEquals(root.get("c%d"), get(doc, "/doc/c%d")); - assertEquals(root.get("e^f"), get(doc, "/doc/e^f")); - assertEquals(root.get("k\"l"), get(doc, "/doc/k\"l")); - assertEquals(root.get("i\\j"), get(doc, "/doc/i\\j")); - assertEquals(root.get(" "), get(doc, "/doc/ ")); - assertEquals(root.get("m~n"), get(doc, "/doc/m~0n")); - } - } - - private static String getString(JsonValue root, String pointer) { - return ((JsonString)get(root, pointer)).getString(); - } - - private static JsonValue get(JsonValue root, String pointer) { - if (pointer.isEmpty()) { - return root; - } - if (pointer.charAt(0) != '/') { - throw new IllegalArgumentException( - "JsonPointer "+pointer+" doesn't start with /"); - } - - StringBuilder referenceToken = new StringBuilder(); - for(int i=1; i < pointer.length(); i++) { // 1 to skip first / - char ch = pointer.charAt(i); - if (ch == '/') { - return get(newRoot(root, referenceToken.toString()), pointer.substring(i)); - } else if (ch == '~') { - // handle escaping ~0, ~1 - if (i+1 == pointer.length()) { - throw new IllegalArgumentException("Illegal escaping: expected ~0 or ~1, but got only ~ in pointer="+pointer); - } - ch = pointer.charAt(++i); - if (ch == '0') { - referenceToken.append('~'); - } else if (ch == '1') { - referenceToken.append('/'); - } else { - throw new IllegalArgumentException("Illegal escaping: expected ~0 or ~1, but got ~"+ch+" in pointer="+pointer); - } - } else { - referenceToken.append(ch); - } - } - return newRoot(root, referenceToken.toString()); - } - - private static JsonValue newRoot(JsonValue root, String referenceToken) { - if (root instanceof JsonObject) { - return ((JsonObject)root).get(referenceToken); - } else if (root instanceof JsonArray) { - return ((JsonArray)root).get(Integer.parseInt(referenceToken)); - } - throw new IllegalArgumentException("Illegal reference token="+referenceToken+" for value="+root); - } - - private static void assertEquals(JsonValue exp, JsonValue got) { - if (exp != got) { - throw new RuntimeException("Expected = "+exp+" but got = "+got); - } - } - - private static void assertEquals(String exp, String got) { - if (!exp.equals(got)) { - throw new RuntimeException("Expected = "+exp+" but got = "+got); - } - } - -} diff --git a/demos/jsonpointer/src/main/resources/jsonpointer.json b/demos/jsonpointer/src/main/resources/jsonpointer.json deleted file mode 100644 index 937a098c..00000000 --- a/demos/jsonpointer/src/main/resources/jsonpointer.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "foo": ["bar", "baz"], - "": 0, - "a/b": 1, - "c%d": 2, - "e^f": 3, - "g|h": 4, - "i\\j": 5, - "k\"l": 6, - " ": 7, - "m~n": 8 -} diff --git a/demos/jsonpointer/src/main/resources/wiki.json b/demos/jsonpointer/src/main/resources/wiki.json deleted file mode 100644 index 17bb1932..00000000 --- a/demos/jsonpointer/src/main/resources/wiki.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "firstName": "John", - "lastName": "Smith", - "age": 25, - "address": { - "streetAddress": "21 2nd Street", - "city": "New York", - "state": "NY", - "postalCode": "10021" - }, - "phoneNumber": [ - { - "type": "home", - "number": "212 555-1234" - }, - { - "type": "fax", - "number": "646 555-4567" - } - ] -} diff --git a/demos/pom.xml b/demos/pom.xml deleted file mode 100644 index 9ec70d49..00000000 --- a/demos/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - json - 2.0.2-SNAPSHOT - ../pom.xml - - - pom - http://maven.apache.org - org.eclipse.jsonp - demos - - - ${basedir}/.. - - - - jaxrs - twitter - facebook - jsonpointer - servlet - customprovider-jdk9 - - - diff --git a/demos/servlet/pom.xml b/demos/servlet/pom.xml deleted file mode 100644 index 4493725b..00000000 --- a/demos/servlet/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - war - http://maven.apache.org - jsondemos-servlet - - jsondemos-servlet - - - - jakarta.servlet - jakarta.servlet-api - provided - - - jakarta.json - jakarta.json-api - provided - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-war-plugin - - - jsondemos-servlet - - diff --git a/demos/servlet/src/main/java/org/eclipse/jsonp/demos/servlet/ArrayServlet.java b/demos/servlet/src/main/java/org/eclipse/jsonp/demos/servlet/ArrayServlet.java deleted file mode 100644 index ad1ebea6..00000000 --- a/demos/servlet/src/main/java/org/eclipse/jsonp/demos/servlet/ArrayServlet.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.servlet; - -import java.io.IOException; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonWriter; -import jakarta.json.JsonWriterFactory; - -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -/** - * Writes a JsonArray using HttpServletResponse#getWriter - * http://localhost:8080/jsondemos-servlet/array - * - * Writes a JsonArray using HttpServletResponse#getOutputStream - * http://localhost:8080/jsondemos-servlet/array?stream - * - * - * @author Jitendra Kotamraju - */ -@WebServlet("/array") -public class ArrayServlet extends HttpServlet { - private static final JsonBuilderFactory bf = Json.createBuilderFactory(null); - private static final JsonWriterFactory wf = Json.createWriterFactory(null); - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { - JsonArray array = bf.createArrayBuilder() - .add(bf.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(bf.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567")) - .build(); - res.setStatus(HttpServletResponse.SC_OK); - res.setContentType("application/json"); - res.setCharacterEncoding("UTF-8"); - - String q = req.getQueryString(); - boolean isStream = q != null && q.equals("stream"); - JsonWriter writer = isStream - ? wf.createWriter(res.getOutputStream()) - : wf.createWriter(res.getWriter()); - writer.write(array); - // not closing writer intentionally - } - -} diff --git a/demos/twitter/pom.xml b/demos/twitter/pom.xml deleted file mode 100644 index f8cccf85..00000000 --- a/demos/twitter/pom.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - demos - 2.0.2-SNAPSHOT - ../pom.xml - - - jar - http://maven.apache.org - jsondemos-twitter - - - org.eclipse.jsonp.demos.twitter.TwitterObjectSearch - - ${project.build.directory}/modules - - - - - jakarta.json - jakarta.json-api - - - org.eclipse.jsonp - jsonp - runtime - - - - jakarta.xml.bind - jakarta.xml.bind-api - - - com.sun.xml.bind - jaxb-impl - runtime - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - true - ${modules.directory} - - - - get-dependencies - package - - copy-dependencies - - - jakarta.activation-api - - - - get-project-artifact - package - - copy - - - - - ${project.groupId} - ${project.artifactId} - ${project.version} - - - - - - - - org.codehaus.mojo - exec-maven-plugin - - java - - --module-path - ${modules.directory} - -m - org.eclipse.jsonp.demos.twitter/${main.class} - - - - - example-twitter - - exec - - - - - - - - diff --git a/demos/twitter/src/main/java/module-info.java b/demos/twitter/src/main/java/module-info.java deleted file mode 100644 index 36e9c13a..00000000 --- a/demos/twitter/src/main/java/module-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -module org.eclipse.jsonp.demos.twitter { - requires jakarta.xml.bind; - requires jakarta.json; -} diff --git a/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterObjectSearch.java b/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterObjectSearch.java deleted file mode 100644 index 449d9b59..00000000 --- a/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterObjectSearch.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.twitter; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -import jakarta.json.*; -import jakarta.xml.bind.DatatypeConverter; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.*; - -/** - * Parses JSON from twitter search REST API using object model API. - * JSON would like : - * - * { - " statuses": [ - * { ..., "user" : { "name" : "xxx", ...}, "text: "yyy", ... }, - * { ..., "user" : { "name" : "ppp", ...}, "text: "qqq", ... }, - * ... - * ], - * ... - * } - * - * This codes writes the tweets to output as follows: - * xxx: yyy - * -------- - * ppp: qqq - * -------- - * - * @author Jitendra Kotamraju - */ -public class TwitterObjectSearch { - - public static void main(String... args) throws Exception { - try (InputStream is = getSearchStream(); - JsonReader rdr = Json.createReader(is)) { - - JsonObject obj = rdr.readObject(); - JsonArray results = obj.getJsonArray("statuses"); - for (JsonObject result : results.getValuesAs(JsonObject.class)) { - System.out.print(result.getJsonObject("user").getString("name", "anonymous")); - System.out.print(": "); - System.out.println(result.get("text")); - System.out.println("-----------"); - } - -// All the tweets are collected into Stream and printed -// obj.getJsonArray("statuses").getValuesAs(JsonObject.class) -// .stream() -// .map(v -> v.getString("text")) -// .forEach(s -> { System.out.println(s); } ); - } - } - - static InputStream getSearchStream() throws Exception { - final String searchStr = "#javaone"; - String searchUrl = "https://api.twitter.com/1.1/search/tweets.json"; - - Properties config = new Properties(); - config.load(TwitterObjectSearch.class.getResourceAsStream( - "/twitterconfig.properties")); - - final String consumerKey = (String)config.get("consumer-key"); - final String consumerSecret = (String)config.get("consumer-secret"); - final String accessToken = (String)config.get("access-token"); - final String accessTokenSecret = (String)config.get("access-token-secret"); - final int timestamp = (int)(System.currentTimeMillis()/1000); - - Map map = new TreeMap() {{ - put("count", "100"); - put("oauth_consumer_key", consumerKey); - put("oauth_nonce", "4b25256957d75b6370f33a4501dc5e7e"); // TODO - put("oauth_signature_method", "HMAC-SHA1"); - put("oauth_timestamp", ""+timestamp); - put("oauth_token", accessToken); - put("oauth_version", "1.0"); - put("q", searchStr); - }}; - - // Builds param string - StringBuilder paramsBuilder = new StringBuilder(); - boolean first = true; - for(Map.Entry e : map.entrySet()) { - if (!first) { - paramsBuilder.append('&'); - } - first = false; - paramsBuilder.append(e.getKey()); - paramsBuilder.append("="); - paramsBuilder.append(URLEncoder.encode(e.getValue(), "UTF-8")); - } - String paramsString = paramsBuilder.toString(); - - // builds signature string - StringBuilder signatureBuilder = new StringBuilder(); - signatureBuilder.append("GET"); - signatureBuilder.append('&'); - signatureBuilder.append(URLEncoder.encode(searchUrl, "UTF-8")); - signatureBuilder.append('&'); - signatureBuilder.append(URLEncoder.encode(paramsString, "UTF-8")); - String signatureBasedString = signatureBuilder.toString(); - - // Create authorization signature - Mac m = Mac.getInstance("HmacSHA1"); - m.init(new SecretKeySpec((consumerSecret+"&"+accessTokenSecret).getBytes(), "HmacSHA1")); - m.update(signatureBasedString.getBytes()); - byte[] res = m.doFinal(); - final String oauthSig = URLEncoder.encode(DatatypeConverter.printBase64Binary(res), "UTF-8"); - map.put("oauth_signature", oauthSig); - map.remove("count"); - map.remove("q"); - - // Build Authorization header - StringBuilder authorizationBuilder = new StringBuilder(); - authorizationBuilder.append("OAuth "); - first = true; - for(Map.Entry e : map.entrySet()) { - if (!first) { - authorizationBuilder.append(','); - authorizationBuilder.append(' '); - } - first = false; - authorizationBuilder.append(e.getKey()); - authorizationBuilder.append('='); - authorizationBuilder.append('"'); - authorizationBuilder.append(e.getValue()); - authorizationBuilder.append('"'); - } - - // Gets the search stream - URL url = new URL(searchUrl+"?q="+URLEncoder.encode(searchStr, "UTF-8")+ - "&count=100"); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); - con.addRequestProperty("Authorization", authorizationBuilder.toString()); - return con.getInputStream(); - } - -} diff --git a/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterStreamSearch.java b/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterStreamSearch.java deleted file mode 100644 index d07b2ef0..00000000 --- a/demos/twitter/src/main/java/org/eclipse/jsonp/demos/twitter/TwitterStreamSearch.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jsonp.demos.twitter; - -import jakarta.json.*; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParser.Event; -import java.io.*; - -/** - * Parses JSON from twitter search REST API using streaming API. - * JSON would like : - * - * { - " statuses": [ - * { ..., "user" : { "name" : "xxx", ...}, "text: "yyy", ... }, - * { ..., "user" : { "name" : "ppp", ...}, "text: "qqq", ... }, - * ... - * ], - * ... - * } - * - * This codes writes the tweets to output as follows: - * xxx: yyy - * -------- - * ppp: qqq - * -------- - * - * TODO need to do better, also the last tweet is repeated ! - * - * @author Jitendra Kotamraju - */ -public class TwitterStreamSearch { - - public static void main(String... args) throws Exception { - try (InputStream is = TwitterObjectSearch.getSearchStream(); - JsonParser parser = Json.createParser(is)) { - int depth = 0; - String name = null; - String text = null; - while (parser.hasNext()) { - Event e = parser.next(); - if (e == Event.KEY_NAME) { - switch (parser.getString()) { - case "name": - if (depth == 3) { - parser.next(); - name = parser.getString(); - } - break; - case "text": - if (depth == 2) { - parser.next(); - text = parser.getString(); - } - break; - } - } else if (e == Event.START_OBJECT) { - ++depth; - } else if (e == Event.END_OBJECT) { - --depth; - if (depth == 1) { - System.out.println(name+": "+text); - System.out.println("-----------"); - - } - } - } - } - } - -} diff --git a/demos/twitter/src/main/resources/twitterconfig.properties b/demos/twitter/src/main/resources/twitterconfig.properties deleted file mode 100644 index 87b5d72f..00000000 --- a/demos/twitter/src/main/resources/twitterconfig.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Distribution License v. 1.0, which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: BSD-3-Clause -# - - -consumer-key= -consumer-secret= -access-token= -access-token-secret= - diff --git a/etc/config/copyright-exclude b/etc/config/copyright-exclude deleted file mode 100644 index e7f6f88c..00000000 --- a/etc/config/copyright-exclude +++ /dev/null @@ -1,8 +0,0 @@ -.json -.md -speclicense.html -MANIFEST.MF -/META-INF/services/ -/etc/config/copyright-exclude -/etc/config/copyright.txt -/bundles/ri/src/main/resources/README.txt diff --git a/etc/config/copyright.txt b/etc/config/copyright.txt deleted file mode 100644 index 9c347b6f..00000000 --- a/etc/config/copyright.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) YYYY Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ diff --git a/etc/config/exclude.xml b/etc/config/exclude.xml deleted file mode 100644 index 7380f9d4..00000000 --- a/etc/config/exclude.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/impl/pom.xml b/impl/pom.xml deleted file mode 100644 index 4306dc14..00000000 --- a/impl/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - 4.0.0 - - - org.eclipse.jsonp - json - 2.0.2-SNAPSHOT - ../pom.xml - - - org.eclipse.jsonp - jsonp - 2.0.2-SNAPSHOT - Eclipse JSONP - Default provider for Jakarta JSON Processing - https://github.com/eclipse-ee4j/jsonp - - - - - - - - org.apache.felix - maven-bundle-plugin - - - osgi-manifest - - manifest - - - - ${project.groupId}:${project.artifactId} - ${project.version} - ${buildNumber} - org.eclipse.jsonp.api - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - false - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - false - - - 11 - true - - - - - - - jakarta.json - jakarta.json-api - - - junit - junit - test - - - - diff --git a/impl/src/main/java/module-info.java b/impl/src/main/java/module-info.java deleted file mode 100644 index efdd79af..00000000 --- a/impl/src/main/java/module-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -module org.eclipse.jsonp { - requires transitive jakarta.json; - exports org.eclipse.jsonp.api; - provides jakarta.json.spi.JsonProvider with org.eclipse.jsonp.JsonProviderImpl; -} diff --git a/impl/src/main/java/org/eclipse/jsonp/BufferPoolImpl.java b/impl/src/main/java/org/eclipse/jsonp/BufferPoolImpl.java deleted file mode 100644 index 141c3e29..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/BufferPoolImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import java.lang.ref.WeakReference; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * char[] pool that pool instances of char[] which are expensive to create. - * - * @author Jitendra Kotamraju - */ -class BufferPoolImpl implements BufferPool { - - // volatile since multiple threads may access queue reference - private volatile WeakReference> queue; - - /** - * Gets a new object from the pool. - * - *

- * If no object is available in the pool, this method creates a new one. - * - * @return - * always non-null. - */ - @Override - public final char[] take() { - char[] t = getQueue().poll(); - if (t==null) - return new char[4096]; - return t; - } - - private ConcurrentLinkedQueue getQueue() { - WeakReference> q = queue; - if (q != null) { - ConcurrentLinkedQueue d = q.get(); - if (d != null) - return d; - } - - // overwrite the queue - ConcurrentLinkedQueue d = new ConcurrentLinkedQueue<>(); - queue = new WeakReference<>(d); - - return d; - } - - /** - * Returns an object back to the pool. - */ - @Override - public final void recycle(char[] t) { - getQueue().offer(t); - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonArrayBuilderImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonArrayBuilderImpl.java deleted file mode 100644 index 8f7412b5..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonArrayBuilderImpl.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.*; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -/** - * JsonArrayBuilder implementation - * - * @author Jitendra Kotamraju - * @author Kin-man Chung - */ - -class JsonArrayBuilderImpl implements JsonArrayBuilder { - private ArrayList valueList; - private final BufferPool bufferPool; - - JsonArrayBuilderImpl(BufferPool bufferPool) { - this.bufferPool = bufferPool; - } - - JsonArrayBuilderImpl(JsonArray array, BufferPool bufferPool) { - this.bufferPool = bufferPool; - valueList = new ArrayList<>(); - valueList.addAll(array); - } - - JsonArrayBuilderImpl(Collection collection, BufferPool bufferPool) { - this.bufferPool = bufferPool; - valueList = new ArrayList<>(); - populate(collection); - } - - @Override - public JsonArrayBuilder add(JsonValue value) { - validateValue(value); - addValueList(value); - return this; - } - - @Override - public JsonArrayBuilder add(String value) { - validateValue(value); - addValueList(new JsonStringImpl(value)); - return this; - } - - @Override - public JsonArrayBuilder add(BigDecimal value) { - validateValue(value); - addValueList(JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(BigInteger value) { - validateValue(value); - addValueList(JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int value) { - addValueList(JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(long value) { - addValueList(JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(double value) { - addValueList(JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(boolean value) { - addValueList(value ? JsonValue.TRUE : JsonValue.FALSE); - return this; - } - - @Override - public JsonArrayBuilder addNull() { - addValueList(JsonValue.NULL); - return this; - } - - @Override - public JsonArrayBuilder add(JsonObjectBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); - } - addValueList(builder.build()); - return this; - } - - @Override - public JsonArrayBuilder add(JsonArrayBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_ARRAY_BUILDER_NULL()); - } - addValueList(builder.build()); - return this; - } - - @Override - public JsonArrayBuilder addAll(JsonArrayBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_ARRAY_BUILDER_NULL()); - } - if (valueList == null) { - valueList = new ArrayList<>(); - } - valueList.addAll(builder.build()); - return this; - } - - @Override - public JsonArrayBuilder add(int index, JsonValue value) { - validateValue(value); - addValueList(index, value); - return this; - } - - @Override - public JsonArrayBuilder add(int index, String value) { - validateValue(value); - addValueList(index, new JsonStringImpl(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, BigDecimal value) { - validateValue(value); - addValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, BigInteger value) { - validateValue(value); - addValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, int value) { - addValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, long value) { - addValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, double value) { - addValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder add(int index, boolean value) { - addValueList(index, value ? JsonValue.TRUE : JsonValue.FALSE); - return this; - } - - @Override - public JsonArrayBuilder addNull(int index) { - addValueList(index, JsonValue.NULL); - return this; - } - - @Override - public JsonArrayBuilder add(int index, JsonObjectBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); - } - addValueList(index, builder.build()); - return this; - } - - @Override - public JsonArrayBuilder add(int index, JsonArrayBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); - } - addValueList(index, builder.build()); - return this; - } - - @Override - public JsonArrayBuilder set(int index, JsonValue value) { - validateValue(value); - setValueList(index, value); - return this; - } - - @Override - public JsonArrayBuilder set(int index, String value) { - validateValue(value); - setValueList(index, new JsonStringImpl(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, BigDecimal value) { - validateValue(value); - setValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, BigInteger value) { - validateValue(value); - setValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, int value) { - setValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, long value) { - setValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, double value) { - setValueList(index, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonArrayBuilder set(int index, boolean value) { - setValueList(index, value ? JsonValue.TRUE : JsonValue.FALSE); - return this; - } - - @Override - public JsonArrayBuilder setNull(int index) { - setValueList(index, JsonValue.NULL); - return this; - } - - @Override - public JsonArrayBuilder set(int index, JsonObjectBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); - } - setValueList(index, builder.build()); - return this; - } - - @Override - public JsonArrayBuilder set(int index, JsonArrayBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); - } - setValueList(index, builder.build()); - return this; - } - - @Override - public JsonArrayBuilder remove(int index) { - if (valueList == null) { - throw new IndexOutOfBoundsException(JsonMessages.ARRBUILDER_VALUELIST_NULL(index, 0)); - } - valueList.remove(index); - return this; - } - - @Override - public JsonArray build() { - List snapshot; - if (valueList == null) { - snapshot = Collections.emptyList(); - } else { - // Should we trim to minimize storage ? - // valueList.trimToSize(); - snapshot = Collections.unmodifiableList(valueList); - } - valueList = null; - return new JsonArrayImpl(snapshot, bufferPool); - } - - private void populate(Collection collection) { - for (Object value : collection) { - if (value != null && value instanceof Optional) { - ((Optional) value).ifPresent(v -> - this.valueList.add(MapUtil.handle(v, bufferPool))); - } else { - this.valueList.add(MapUtil.handle(value, bufferPool)); - } - } - } - - private void addValueList(JsonValue value) { - if (valueList == null) { - valueList = new ArrayList<>(); - } - valueList.add(value); - } - - private void addValueList(int index, JsonValue value) { - if (valueList == null) { - valueList = new ArrayList<>(); - } - valueList.add(index, value); - } - - private void setValueList(int index, JsonValue value) { - if (valueList == null) { - throw new IndexOutOfBoundsException(JsonMessages.ARRBUILDER_VALUELIST_NULL(index, 0)); - } - valueList.set(index, value); - } - - private void validateValue(Object value) { - if (value == null) { - throw new NullPointerException(JsonMessages.ARRBUILDER_VALUE_NULL()); - } - } - - private static final class JsonArrayImpl extends AbstractList implements JsonArray { - private final List valueList; // Unmodifiable - private final BufferPool bufferPool; - private int hashCode; - - JsonArrayImpl(List valueList, BufferPool bufferPool) { - this.valueList = valueList; - this.bufferPool = bufferPool; - } - - @Override - public int size() { - return valueList.size(); - } - - @Override - public JsonObject getJsonObject(int index) { - return (JsonObject)valueList.get(index); - } - - @Override - public JsonArray getJsonArray(int index) { - return (JsonArray)valueList.get(index); - } - - @Override - public JsonNumber getJsonNumber(int index) { - return (JsonNumber)valueList.get(index); - } - - @Override - public JsonString getJsonString(int index) { - return (JsonString)valueList.get(index); - } - - @Override - @SuppressWarnings("unchecked") - public List getValuesAs(Class clazz) { - return (List)valueList; - } - - @Override - public String getString(int index) { - return getJsonString(index).getString(); - } - - @Override - public String getString(int index, String defaultValue) { - try { - return getString(index); - } catch (Exception e) { - return defaultValue; - } - } - - @Override - public int getInt(int index) { - return getJsonNumber(index).intValue(); - } - - @Override - public int getInt(int index, int defaultValue) { - try { - return getInt(index); - } catch (Exception e) { - return defaultValue; - } - } - - @Override - public boolean getBoolean(int index) { - JsonValue jsonValue = get(index); - if (jsonValue == JsonValue.TRUE) { - return true; - } else if (jsonValue == JsonValue.FALSE) { - return false; - } else { - throw new ClassCastException(); - } - } - - @Override - public boolean getBoolean(int index, boolean defaultValue) { - try { - return getBoolean(index); - } catch (Exception e) { - return defaultValue; - } - } - - @Override - public boolean isNull(int index) { - return valueList.get(index).equals(JsonValue.NULL); - } - - @Override - public ValueType getValueType() { - return ValueType.ARRAY; - } - - @Override - public JsonValue get(int index) { - return valueList.get(index); - } - - @Override - public int hashCode() { - if (hashCode == 0) { - hashCode = super.hashCode(); - } - return hashCode; - } - - @Override - public String toString() { - StringWriter sw = new StringWriter(); - try (JsonWriter jw = new JsonWriterImpl(sw, bufferPool)) { - jw.write(this); - } - return sw.toString(); - } - - @Override - public JsonArray asJsonArray() { - return this; - } - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonBuilderFactoryImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonBuilderFactoryImpl.java deleted file mode 100644 index a1618a9a..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonBuilderFactoryImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import java.util.Collection; -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonObject; -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObjectBuilder; -import java.util.Collections; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonBuilderFactoryImpl implements JsonBuilderFactory { - private final Map config; - private final BufferPool bufferPool; - private final boolean rejectDuplicateKeys; - - JsonBuilderFactoryImpl(BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.config = Collections.emptyMap(); - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - } - - @Override - public JsonObjectBuilder createObjectBuilder() { - return new JsonObjectBuilderImpl(bufferPool, rejectDuplicateKeys); - } - - @Override - public JsonObjectBuilder createObjectBuilder(JsonObject object) { - return new JsonObjectBuilderImpl(object, bufferPool, rejectDuplicateKeys); - } - - @Override - public JsonObjectBuilder createObjectBuilder(Map object) { - return new JsonObjectBuilderImpl(object, bufferPool, rejectDuplicateKeys); - } - - @Override - public JsonArrayBuilder createArrayBuilder() { - return new JsonArrayBuilderImpl(bufferPool); - } - - @Override - public JsonArrayBuilder createArrayBuilder(JsonArray array) { - return new JsonArrayBuilderImpl(array, bufferPool); - } - - @Override - public JsonArrayBuilder createArrayBuilder(Collection collection) { - return new JsonArrayBuilderImpl(collection, bufferPool); - } - - @Override - public Map getConfigInUse() { - return config; - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorFactoryImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorFactoryImpl.java deleted file mode 100644 index a8babb34..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorFactoryImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.stream.JsonGenerator; -import jakarta.json.stream.JsonGeneratorFactory; -import java.io.OutputStream; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonGeneratorFactoryImpl implements JsonGeneratorFactory { - - private final boolean prettyPrinting; - private final Map config; // unmodifiable map - private final BufferPool bufferPool; - - JsonGeneratorFactoryImpl(Map config, boolean prettyPrinting, - BufferPool bufferPool) { - this.config = config; - this.prettyPrinting = prettyPrinting; - this.bufferPool = bufferPool; - } - - @Override - public JsonGenerator createGenerator(Writer writer) { - return prettyPrinting - ? new JsonPrettyGeneratorImpl(writer, bufferPool) - : new JsonGeneratorImpl(writer, bufferPool); - } - - @Override - public JsonGenerator createGenerator(OutputStream out) { - return prettyPrinting - ? new JsonPrettyGeneratorImpl(out, bufferPool) - : new JsonGeneratorImpl(out, bufferPool); - } - - @Override - public JsonGenerator createGenerator(OutputStream out, Charset charset) { - return prettyPrinting - ? new JsonPrettyGeneratorImpl(out, charset, bufferPool) - : new JsonGeneratorImpl(out, charset, bufferPool); - } - - @Override - public Map getConfigInUse() { - return config; - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorImpl.java deleted file mode 100644 index dd64d2bf..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonGeneratorImpl.java +++ /dev/null @@ -1,733 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.*; -import jakarta.json.stream.JsonGenerationException; -import jakarta.json.stream.JsonGenerator; -import java.io.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonGeneratorImpl implements JsonGenerator { - - private static final char[] INT_MIN_VALUE_CHARS = "-2147483648".toCharArray(); - private static final int[] INT_CHARS_SIZE_TABLE = { 9, 99, 999, 9999, 99999, - 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE }; - - private static final char [] DIGIT_TENS = { - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', - '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', - '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', - '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', - '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', - '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', - '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', - '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', - '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', - } ; - - private static final char [] DIGIT_ONES = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - } ; - - /** - * All possible chars for representing a number as a String - */ - private static final char[] DIGITS = { - '0' , '1' , '2' , '3' , '4' , '5' , - '6' , '7' , '8' , '9' - }; - - private static enum Scope { - IN_NONE, - IN_OBJECT, - IN_FIELD, - IN_ARRAY - } - - private final BufferPool bufferPool; - private final Writer writer; - private Context currentContext = new Context(Scope.IN_NONE); - private final Deque stack = new ArrayDeque<>(); - - // Using own buffering mechanism as JDK's BufferedWriter uses synchronized - // methods. Also, flushBuffer() is useful when you don't want to actually - // flush the underlying output source - private final char buf[]; // capacity >= INT_MIN_VALUE_CHARS.length - private int len = 0; - - JsonGeneratorImpl(Writer writer, BufferPool bufferPool) { - this.writer = writer; - this.bufferPool = bufferPool; - this.buf = bufferPool.take(); - } - - JsonGeneratorImpl(OutputStream out, BufferPool bufferPool) { - this(out, StandardCharsets.UTF_8, bufferPool); - } - - JsonGeneratorImpl(OutputStream out, Charset encoding, BufferPool bufferPool) { - this(new OutputStreamWriter(out, encoding), bufferPool); - } - - @Override - public void flush() { - flushBuffer(); - try { - writer.flush(); - } catch (IOException ioe) { - throw new JsonException(JsonMessages.GENERATOR_FLUSH_IO_ERR(), ioe); - } - } - - @Override - public JsonGenerator writeStartObject() { - if (currentContext.scope == Scope.IN_OBJECT) { - throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { - throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); - } - writeComma(); - writeChar('{'); - stack.push(currentContext); - currentContext = new Context(Scope.IN_OBJECT); - return this; - } - - @Override - public JsonGenerator writeStartObject(String name) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeChar('{'); - stack.push(currentContext); - currentContext = new Context(Scope.IN_OBJECT); - return this; - } - - private JsonGenerator writeName(String name) { - writeComma(); - writeEscapedString(name); - writeColon(); - return this; - } - - @Override - public JsonGenerator write(String name, String fieldValue) { - write(name, (CharSequence) fieldValue); - return this; - } - - @Override - public JsonGenerator write(String name, int value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeInt(value); - return this; - } - - @Override - public JsonGenerator write(String name, long value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeString(String.valueOf(value)); - return this; - } - - @Override - public JsonGenerator write(String name, double value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - if (Double.isInfinite(value) || Double.isNaN(value)) { - throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); - } - writeName(name); - writeString(String.valueOf(value)); - return this; - } - - @Override - public JsonGenerator write(String name, BigInteger value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeString(String.valueOf(value)); - return this; - } - - @Override - public JsonGenerator write(String name, BigDecimal value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeString(String.valueOf(value)); - return this; - } - - @Override - public JsonGenerator write(String name, boolean value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeString(value? "true" : "false"); - return this; - } - - @Override - public JsonGenerator writeNull(String name) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeString("null"); - return this; - } - - @Override - public JsonGenerator write(JsonValue value) { - checkContextForValue(); - - switch (value.getValueType()) { - case ARRAY: - JsonArray array = (JsonArray)value; - writeStartArray(); - for(JsonValue child: array) { - write(child); - } - writeEnd(); - break; - case OBJECT: - JsonObject object = (JsonObject)value; - writeStartObject(); - for(Map.Entry member: object.entrySet()) { - write(member.getKey(), member.getValue()); - } - writeEnd(); - break; - case STRING: - JsonString str = (JsonString)value; - write(str.getString()); - break; - case NUMBER: - JsonNumber number = (JsonNumber)value; - writeValue(number.toString()); - popFieldContext(); - break; - case TRUE: - write(true); - break; - case FALSE: - write(false); - break; - case NULL: - writeNull(); - break; - } - - return this; - } - - @Override - public JsonGenerator writeStartArray() { - if (currentContext.scope == Scope.IN_OBJECT) { - throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { - throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); - } - writeComma(); - writeChar('['); - stack.push(currentContext); - currentContext = new Context(Scope.IN_ARRAY); - return this; - } - - @Override - public JsonGenerator writeStartArray(String name) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeChar('['); - stack.push(currentContext); - currentContext = new Context(Scope.IN_ARRAY); - return this; - } - - @Override - public JsonGenerator write(String name, JsonValue value) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - switch (value.getValueType()) { - case ARRAY: - JsonArray array = (JsonArray)value; - writeStartArray(name); - for(JsonValue child: array) { - write(child); - } - writeEnd(); - break; - case OBJECT: - JsonObject object = (JsonObject)value; - writeStartObject(name); - for(Map.Entry member: object.entrySet()) { - write(member.getKey(), member.getValue()); - } - writeEnd(); - break; - case STRING: - JsonString str = (JsonString)value; - write(name, str.getChars()); - break; - case NUMBER: - JsonNumber number = (JsonNumber)value; - writeValue(name, number.toString()); - break; - case TRUE: - write(name, true); - break; - case FALSE: - write(name, false); - break; - case NULL: - writeNull(name); - break; - } - return this; - } - - @Override - public JsonGenerator write(String value) { - checkContextForValue(); - writeComma(); - writeEscapedString(value); - popFieldContext(); - return this; - } - - - @Override - public JsonGenerator write(int value) { - checkContextForValue(); - writeComma(); - writeInt(value); - popFieldContext(); - return this; - } - - @Override - public JsonGenerator write(long value) { - checkContextForValue(); - writeValue(String.valueOf(value)); - popFieldContext(); - return this; - } - - @Override - public JsonGenerator write(double value) { - checkContextForValue(); - if (Double.isInfinite(value) || Double.isNaN(value)) { - throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); - } - writeValue(String.valueOf(value)); - popFieldContext(); - return this; - } - - @Override - public JsonGenerator write(BigInteger value) { - checkContextForValue(); - writeValue(value.toString()); - popFieldContext(); - return this; - } - - private void checkContextForValue() { - if ((!currentContext.first && currentContext.scope != Scope.IN_ARRAY && currentContext.scope != Scope.IN_FIELD) - || (currentContext.first && currentContext.scope == Scope.IN_OBJECT)) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - } - - @Override - public JsonGenerator write(BigDecimal value) { - checkContextForValue(); - writeValue(value.toString()); - popFieldContext(); - - return this; - } - - private void popFieldContext() { - if (currentContext.scope == Scope.IN_FIELD) { - currentContext = stack.pop(); - } - } - - @Override - public JsonGenerator write(boolean value) { - checkContextForValue(); - writeComma(); - writeString(value ? "true" : "false"); - popFieldContext(); - return this; - } - - @Override - public JsonGenerator writeNull() { - checkContextForValue(); - writeComma(); - writeString("null"); - popFieldContext(); - return this; - } - - private void writeValue(String value) { - writeComma(); - writeString(value); - } - - private void writeValue(String name, String value) { - writeComma(); - writeEscapedString(name); - writeColon(); - writeString(value); - } - - @Override - public JsonGenerator writeKey(String name) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - stack.push(currentContext); - currentContext = new Context(Scope.IN_FIELD); - currentContext.first = false; - return this; - } - - @Override - public JsonGenerator writeEnd() { - if (currentContext.scope == Scope.IN_NONE) { - throw new JsonGenerationException("writeEnd() cannot be called in no context"); - } - writeChar(currentContext.scope == Scope.IN_ARRAY ? ']' : '}'); - currentContext = stack.pop(); - popFieldContext(); - return this; - } - - void write(String name, CharSequence fieldValue) { - if (currentContext.scope != Scope.IN_OBJECT) { - throw new JsonGenerationException( - JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); - } - writeName(name); - writeEscapedString(fieldValue); - } - - protected void writeComma() { - if (isCommaAllowed()) { - writeChar(','); - } - currentContext.first = false; - } - - protected boolean inNone() { - return currentContext.scope == Scope.IN_NONE; - } - - boolean isCommaAllowed() { - return !currentContext.first && currentContext.scope != Scope.IN_FIELD; - } - - protected void writeColon() { - writeChar(':'); - } - - private static class Context { - boolean first = true; - final Scope scope; - - Context(Scope scope) { - this.scope = scope; - } - - } - - @Override - public void close() { - if (currentContext.scope != Scope.IN_NONE || currentContext.first) { - throw new JsonGenerationException(JsonMessages.GENERATOR_INCOMPLETE_JSON()); - } - flushBuffer(); - try { - writer.close(); - } catch (IOException ioe) { - throw new JsonException(JsonMessages.GENERATOR_CLOSE_IO_ERR(), ioe); - } - bufferPool.recycle(buf); - } - - // begin, end-1 indexes represent characters that need not - // be escaped - // - // XXXssssssssssssXXXXXXXXXXXXXXXXXXXXXXrrrrrrrrrrrrrrXXXXXX - // ^ ^ ^ ^ - // | | | | - // begin end begin end - void writeEscapedString(CharSequence string) { - writeChar('"'); - int len = string.length(); - for(int i = 0; i < len; i++) { - int begin = i, end = i; - char c = string.charAt(i); - // find all the characters that need not be escaped - // unescaped = %x20-21 | %x23-5B | %x5D-10FFFF - while(c >= 0x20 && c <= 0x10ffff && c != 0x22 && c != 0x5c) { - i++; end = i; - if (i < len) { - c = string.charAt(i); - } else { - break; - } - } - // Write characters without escaping - if (begin < end) { - writeString(string, begin, end); - if (i == len) { - break; - } - } - - switch (c) { - case '"': - case '\\': - writeChar('\\'); writeChar(c); - break; - case '\b': - writeChar('\\'); writeChar('b'); - break; - case '\f': - writeChar('\\'); writeChar('f'); - break; - case '\n': - writeChar('\\'); writeChar('n'); - break; - case '\r': - writeChar('\\'); writeChar('r'); - break; - case '\t': - writeChar('\\'); writeChar('t'); - break; - default: - String hex = "000" + Integer.toHexString(c); - writeString("\\u" + hex.substring(hex.length() - 4)); - } - } - writeChar('"'); - } - - void writeString(CharSequence str, int begin, int end) { - while (begin < end) { // source begin and end indexes - int no = Math.min(buf.length - len, end - begin); - if (str instanceof String) { - ((String)str).getChars(begin, begin + no, buf, len); - } else { - // if passed a non-string, assume this is deliberate - getChars(str, begin, begin + no, buf, len); - } - begin += no; // Increment source index - len += no; // Increment dest index - if (len >= buf.length) { - flushBuffer(); - } - } - } - - void writeString(CharSequence str) { - writeString(str, 0, str.length()); - } - - void writeChar(char c) { - if (len >= buf.length) { - flushBuffer(); - } - buf[len++] = c; - } - - // Not using Integer.toString() since it creates intermediary String - // Also, we want the chars to be copied to our buffer directly - void writeInt(int num) { - int size; - if (num == Integer.MIN_VALUE) { - size = INT_MIN_VALUE_CHARS.length; - } else { - size = (num < 0) ? stringSize(-num) + 1 : stringSize(num); - } - if (len+size >= buf.length) { - flushBuffer(); - } - if (num == Integer.MIN_VALUE) { - System.arraycopy(INT_MIN_VALUE_CHARS, 0, buf, len, size); - } else { - fillIntChars(num, buf, len+size); - } - len += size; - } - - // flushBuffer writes the buffered contents to writer. But incase of - // byte stream, an OuputStreamWriter is created and that buffers too. - // We may need to call OutputStreamWriter#flushBuffer() using - // reflection if that is really required (commented out below) - void flushBuffer() { - try { - if (len > 0) { - writer.write(buf, 0, len); - len = 0; - } - } catch (IOException ioe) { - throw new JsonException(JsonMessages.GENERATOR_WRITE_IO_ERR(), ioe); - } - } - -// private static final Method flushBufferMethod; -// static { -// Method m = null; -// try { -// m = OutputStreamWriter.class.getDeclaredMethod("flushBuffer"); -// m.setAccessible(true); -// } catch (Exception e) { -// // no-op -// } -// flushBufferMethod = m; -// } -// void flushBufferOSW() { -// flushBuffer(); -// if (writer instanceof OutputStreamWriter) { -// try { -// flushBufferMethod.invoke(writer); -// } catch (Exception e) { -// // no-op -// } -// } -// } - - // Requires positive x - private static int stringSize(int x) { - for (int i=0; ; i++) - if (x <= INT_CHARS_SIZE_TABLE[i]) - return i+1; - } - - void getChars(CharSequence str, int srcBegin, int srcEnd, char[] dst, int dstBegin) { - int length = srcEnd - srcBegin; - for (int i = 0 ; i < length ; i++) { - int srcIdx = srcBegin + i; - int dstIdx = dstBegin + i; - dst[dstIdx] = str.charAt(srcIdx); - } - } - - /** - * Places characters representing the integer i into the - * character array buf. The characters are placed into - * the buffer backwards starting with the least significant - * digit at the specified index (exclusive), and working - * backwards from there. - * - * Will fail if i == Integer.MIN_VALUE - */ - private static void fillIntChars(int i, char[] buf, int index) { - int q, r; - int charPos = index; - char sign = 0; - - if (i < 0) { - sign = '-'; - i = -i; - } - - // Generate two digits per iteration - while (i >= 65536) { - q = i / 100; - // really: r = i - (q * 100); - r = i - ((q << 6) + (q << 5) + (q << 2)); - i = q; - buf [--charPos] = DIGIT_ONES[r]; - buf [--charPos] = DIGIT_TENS[r]; - } - - // Fall thru to fast mode for smaller numbers - // assert(i <= 65536, i); - for (;;) { - q = (i * 52429) >>> (16+3); - r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ... - buf [--charPos] = DIGITS[r]; - i = q; - if (i == 0) break; - } - if (sign != 0) { - buf [--charPos] = sign; - } - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonLocationImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonLocationImpl.java deleted file mode 100644 index 484386f3..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonLocationImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.stream.JsonLocation; - -/** - * @author Jitendra Kotamraju - */ -class JsonLocationImpl implements JsonLocation { - static final JsonLocation UNKNOWN = new JsonLocationImpl(-1, -1, -1); - - private final long columnNo; - private final long lineNo; - private final long offset; - - JsonLocationImpl(long lineNo, long columnNo, long streamOffset) { - this.lineNo = lineNo; - this.columnNo = columnNo; - this.offset = streamOffset; - } - - @Override - public long getLineNumber() { - return lineNo; - } - - @Override - public long getColumnNumber() { - return columnNo; - } - - @Override - public long getStreamOffset() { - return offset; - } - - @Override - public String toString() { - return "(line no="+lineNo+", column no="+columnNo+", offset="+ offset +")"; - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonMergePatchImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonMergePatchImpl.java deleted file mode 100644 index 05d2161f..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonMergePatchImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonMergePatch; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; - -/** - * This class is an implementation of a JSON Merge Patch as specified in - * RFC 7396. - * - * @since 1.1 - */ - -public final class JsonMergePatchImpl implements JsonMergePatch { - - private JsonValue patch; - - public JsonMergePatchImpl(JsonValue patch) { - this.patch = patch; - } - - @Override - public JsonValue apply(JsonValue target) { - return mergePatch(target, patch); - } - - @Override - public JsonValue toJsonValue() { - return patch; - } - /** - * Applies the specified patch to the specified target. - * The target is not modified by the patch. - * - * @param target the {@code JsonValue} to apply the patch operations - * @param patch the patch - * @return the {@code JsonValue} as the result of applying the patch - * operations on the target. - */ - private static JsonValue mergePatch(JsonValue target, JsonValue patch) { - - if (patch.getValueType() != JsonValue.ValueType.OBJECT) { - return patch; - } - if (target.getValueType() != JsonValue.ValueType.OBJECT) { - target = JsonValue.EMPTY_JSON_OBJECT; - } - JsonObject targetJsonObject = target.asJsonObject(); - JsonObjectBuilder builder = - new JsonObjectBuilderImpl(targetJsonObject, JsonUtil.getInternalBufferPool()); - patch.asJsonObject().forEach((key, value) -> { - if (value == JsonValue.NULL) { - if (targetJsonObject.containsKey(key)) { - builder.remove(key); - } - } else if (targetJsonObject.containsKey(key)) { - builder.add(key, mergePatch(targetJsonObject.get(key), value)); - } else { - builder.add(key, mergePatch(JsonValue.EMPTY_JSON_OBJECT, value)); - } - }); - return builder.build(); - } - - /** - * Generate a JSON Merge Patch from the source and target {@code JsonValue}. - * @param source the source - * @param target the target - * @return a JSON Patch which when applied to the source, yields the target - */ - static JsonValue diff(JsonValue source, JsonValue target) { - if (source.getValueType() != JsonValue.ValueType.OBJECT || - target.getValueType() != JsonValue.ValueType.OBJECT) { - return target; - } - JsonObject s = (JsonObject) source; - JsonObject t = (JsonObject) target; - JsonObjectBuilder builder = new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()); - // First find members to be replaced or removed - s.forEach((key, value) -> { - if (t.containsKey(key)) { - // key present in both. - if (! value.equals(t.get(key))) { - // If the values are equal, nop, else get diff for the values - builder.add(key, diff(value, t.get(key))); - } - } else { - builder.addNull(key); - } - }); - // Then find members to be added - t.forEach((key, value) -> { - if (! s.containsKey(key)) - builder.add(key, value); - }); - return builder.build(); - } - -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonMessages.java b/impl/src/main/java/org/eclipse/jsonp/JsonMessages.java deleted file mode 100644 index e717311f..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonMessages.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - - -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import java.text.MessageFormat; -import java.util.ResourceBundle; -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; - -/** - * Defines string formatting method for each constant in the resource file - * - * @author Jitendra Kotamraju - */ -final class JsonMessages { - private static final ResourceBundle BUNDLE = - ResourceBundle.getBundle("org.eclipse.jsonp.messages"); - - // global/shared messages - static String INTERNAL_ERROR() { - return localize("internal.error"); - } - - // tokenizer messages - static String TOKENIZER_UNEXPECTED_CHAR(int unexpected, JsonLocation location) { - return localize("tokenizer.unexpected.char", unexpected, location); - } - - static String TOKENIZER_EXPECTED_CHAR(int unexpected, JsonLocation location, char expected) { - return localize("tokenizer.expected.char", unexpected, location, expected); - } - - static String TOKENIZER_IO_ERR() { - return localize("tokenizer.io.err"); - } - - - // parser messages - static String PARSER_GETSTRING_ERR(JsonParser.Event event) { - return localize("parser.getString.err", event); - } - - static String PARSER_ISINTEGRALNUMBER_ERR(JsonParser.Event event) { - return localize("parser.isIntegralNumber.err", event); - } - - static String PARSER_GETINT_ERR(JsonParser.Event event) { - return localize("parser.getInt.err", event); - } - - static String PARSER_GETLONG_ERR(JsonParser.Event event) { - return localize("parser.getLong.err", event); - } - - static String PARSER_GETBIGDECIMAL_ERR(JsonParser.Event event) { - return localize("parser.getBigDecimal.err", event); - } - - static String PARSER_GETARRAY_ERR(JsonParser.Event event) { - return localize("parser.getArray.err", event); - } - - static String PARSER_GETOBJECT_ERR(JsonParser.Event event) { - return localize("parser.getObject.err", event); - } - - static String PARSER_GETVALUE_ERR(JsonParser.Event event) { - return localize("parser.getValue.err", event); - } - - static String PARSER_GETVALUESTREAM_ERR() { - return localize("parser.getValueStream.err"); - } - - static String PARSER_EXPECTED_EOF(JsonTokenizer.JsonToken token) { - return localize("parser.expected.eof", token); - } - - static String PARSER_TOKENIZER_CLOSE_IO() { - return localize("parser.tokenizer.close.io"); - } - - static String PARSER_INVALID_TOKEN(JsonTokenizer.JsonToken token, JsonLocation location, String expectedTokens) { - return localize("parser.invalid.token", token, location, expectedTokens); - } - - static String PARSER_STATE_ERR(JsonValue.ValueType type) { - return localize("parser.state.err", type); - } - - static String PARSER_SCOPE_ERR(JsonValue value) { - return localize("parser.scope.err", value); - } - - static String PARSER_INPUT_ENC_DETECT_FAILED() { - return localize("parser.input.enc.detect.failed"); - } - - static String PARSER_INPUT_ENC_DETECT_IOERR() { - return localize("parser.input.enc.detect.ioerr"); - } - - static String DUPLICATE_KEY(String name) { - return localize("parser.duplicate.key", name); - } - - // generator messages - static String GENERATOR_FLUSH_IO_ERR() { - return localize("generator.flush.io.err"); - } - - static String GENERATOR_CLOSE_IO_ERR() { - return localize("generator.close.io.err"); - } - - static String GENERATOR_WRITE_IO_ERR() { - return localize("generator.write.io.err"); - } - - static String GENERATOR_ILLEGAL_METHOD(Object scope) { - return localize("generator.illegal.method", scope); - } - - static String GENERATOR_DOUBLE_INFINITE_NAN() { - return localize("generator.double.infinite.nan"); - } - - static String GENERATOR_INCOMPLETE_JSON() { - return localize("generator.incomplete.json"); - } - - static String GENERATOR_ILLEGAL_MULTIPLE_TEXT() { - return localize("generator.illegal.multiple.text"); - } - - - - // writer messages - static String WRITER_WRITE_ALREADY_CALLED() { - return localize("writer.write.already.called"); - } - - // reader messages - static String READER_READ_ALREADY_CALLED() { - return localize("reader.read.already.called"); - } - - - // obj builder messages - static String OBJBUILDER_NAME_NULL() { - return localize("objbuilder.name.null"); - } - - static String OBJBUILDER_VALUE_NULL() { - return localize("objbuilder.value.null"); - } - - static String OBJBUILDER_OBJECT_BUILDER_NULL() { - return localize("objbuilder.object.builder.null"); - } - - static String OBJBUILDER_ARRAY_BUILDER_NULL() { - return localize("objbuilder.array.builder.null"); - } - - - // array builder messages - static String ARRBUILDER_VALUE_NULL() { - return localize("arrbuilder.value.null"); - } - - static String ARRBUILDER_OBJECT_BUILDER_NULL() { - return localize("arrbuilder.object.builder.null"); - } - - static String ARRBUILDER_ARRAY_BUILDER_NULL() { - return localize("arrbuilder.array.builder.null"); - } - - static String ARRBUILDER_VALUELIST_NULL(int index, int size) { - return localize("arrbuilder.valuelist.null", index, size); - } - - // json pointer messages - static String POINTER_FORMAT_INVALID() { - return localize("pointer.format.invalid"); - } - - static String POINTER_MAPPING_MISSING(JsonObject object, String key) { - return localize("pointer.mapping.missing", object, key); - } - - static String POINTER_REFERENCE_INVALID(JsonValue.ValueType type) { - return localize("pointer.reference.invalid", type.name()); - } - - static String POINTER_ARRAY_INDEX_ERR(String token) { - return localize("pointer.array.index.err", token); - } - - static String POINTER_ARRAY_INDEX_ILLEGAL(String token) { - return localize("pointer.array.index.illegal", token); - } - - // nodereference messages - static String NODEREF_VALUE_ADD_ERR() { - return localize("noderef.value.add.err"); - } - - static String NODEREF_VALUE_CANNOT_REMOVE() { - return localize("noderef.value.cannot.remove"); - } - - static String NODEREF_OBJECT_MISSING(String key) { - return localize("noderef.object.missing", key); - } - - static String NODEREF_ARRAY_INDEX_ERR(int index, int size) { - return localize("noderef.array.index.err", index, size); - } - - // json patch messages - static String PATCH_MUST_BE_ARRAY() { - return localize("patch.must.be.array"); - } - - static String PATCH_MOVE_PROPER_PREFIX(String from, String path) { - return localize("patch.move.proper.prefix", from, path); - } - - static String PATCH_MOVE_TARGET_NULL(String from) { - return localize("patch.move.target.null", from); - } - - static String PATCH_TEST_FAILED(String path, String value) { - return localize("patch.test.failed", path, value); - } - - static String PATCH_ILLEGAL_OPERATION(String operation) { - return localize("patch.illegal.operation", operation); - } - - static String PATCH_MEMBER_MISSING(String operation, String member) { - return localize("patch.member.missing", operation, member); - } - - static String PATCH_OPERATION_MISSING() { - return localize("patch.operation.missing"); - } - - - private static String localize(String key, Object ... args) { - try { - String msg = BUNDLE.getString(key); - return MessageFormat.format(msg, args); - } catch (Exception e) { - return getDefaultMessage(key, args); - } - } - - private static String getDefaultMessage(String key, Object ... args) { - StringBuilder sb = new StringBuilder(); - sb.append("[failed to localize] "); - sb.append(key); - if (args != null) { - sb.append('('); - for (int i = 0; i < args.length; ++i) { - if (i != 0) - sb.append(", "); - sb.append(String.valueOf(args[i])); - } - sb.append(')'); - } - return sb.toString(); - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonNumberImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonNumberImpl.java deleted file mode 100644 index 80fbf169..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonNumberImpl.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonNumber; -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * JsonNumber impl. Subclasses provide optimized implementations - * when backed by int, long, BigDecimal - * - * @author Jitendra Kotamraju - */ -abstract class JsonNumberImpl implements JsonNumber { - - private int hashCode; - - static JsonNumber getJsonNumber(int num) { - return new JsonIntNumber(num); - } - - static JsonNumber getJsonNumber(long num) { - return new JsonLongNumber(num); - } - - static JsonNumber getJsonNumber(BigInteger value) { - return new JsonBigDecimalNumber(new BigDecimal(value)); - } - - static JsonNumber getJsonNumber(double value) { - //bigDecimal = new BigDecimal(value); - // This is the preferred way to convert double to BigDecimal - return new JsonBigDecimalNumber(BigDecimal.valueOf(value)); - } - - static JsonNumber getJsonNumber(BigDecimal value) { - return new JsonBigDecimalNumber(value); - } - - // Optimized JsonNumber impl for int numbers. - private static final class JsonIntNumber extends JsonNumberImpl { - private final int num; - private BigDecimal bigDecimal; // assigning it lazily on demand - - JsonIntNumber(int num) { - this.num = num; - } - - @Override - public boolean isIntegral() { - return true; - } - - @Override - public int intValue() { - return num; - } - - @Override - public int intValueExact() { - return num; - } - - @Override - public long longValue() { - return num; - } - - @Override - public long longValueExact() { - return num; - } - - @Override - public double doubleValue() { - return num; - } - - @Override - public BigDecimal bigDecimalValue() { - // reference assignments are atomic. At the most some more temp - // BigDecimal objects are created - BigDecimal bd = bigDecimal; - if (bd == null) { - bigDecimal = bd = new BigDecimal(num); - } - return bd; - } - - @Override - public Number numberValue() { - return num; - } - - @Override - public String toString() { - return Integer.toString(num); - } - } - - // Optimized JsonNumber impl for long numbers. - private static final class JsonLongNumber extends JsonNumberImpl { - private final long num; - private BigDecimal bigDecimal; // assigning it lazily on demand - - JsonLongNumber(long num) { - this.num = num; - } - - @Override - public boolean isIntegral() { - return true; - } - - @Override - public int intValue() { - return (int) num; - } - - @Override - public int intValueExact() { - return Math.toIntExact(num); - } - - @Override - public long longValue() { - return num; - } - - @Override - public long longValueExact() { - return num; - } - - @Override - public double doubleValue() { - return num; - } - - @Override - public BigDecimal bigDecimalValue() { - // reference assignments are atomic. At the most some more temp - // BigDecimal objects are created - BigDecimal bd = bigDecimal; - if (bd == null) { - bigDecimal = bd = new BigDecimal(num); - } - return bd; - } - - @Override - public Number numberValue() { - return num; - } - - @Override - public String toString() { - return Long.toString(num); - } - - } - - // JsonNumber impl using BigDecimal numbers. - private static final class JsonBigDecimalNumber extends JsonNumberImpl { - private final BigDecimal bigDecimal; - - JsonBigDecimalNumber(BigDecimal value) { - this.bigDecimal = value; - } - - @Override - public BigDecimal bigDecimalValue() { - return bigDecimal; - } - - @Override - public Number numberValue() { - return bigDecimalValue(); - } - - } - - @Override - public boolean isIntegral() { - return bigDecimalValue().scale() == 0; - } - - @Override - public int intValue() { - return bigDecimalValue().intValue(); - } - - @Override - public int intValueExact() { - return bigDecimalValue().intValueExact(); - } - - @Override - public long longValue() { - return bigDecimalValue().longValue(); - } - - @Override - public long longValueExact() { - return bigDecimalValue().longValueExact(); - } - - @Override - public double doubleValue() { - return bigDecimalValue().doubleValue(); - } - - @Override - public BigInteger bigIntegerValue() { - return bigDecimalValue().toBigInteger(); - } - - @Override - public BigInteger bigIntegerValueExact() { - return bigDecimalValue().toBigIntegerExact(); - } - - @Override - public ValueType getValueType() { - return ValueType.NUMBER; - } - - @Override - public int hashCode() { - if (hashCode == 0) { - hashCode = bigDecimalValue().hashCode(); - } - return hashCode; - } - - @Override - public boolean equals(Object obj) { - if (this == obj){ - return true; - } - if (!(obj instanceof JsonNumber)) { - return false; - } - JsonNumber other = (JsonNumber)obj; - return bigDecimalValue().equals(other.bigDecimalValue()); - } - - @Override - public String toString() { - return bigDecimalValue().toString(); - } - -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonObjectBuilderImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonObjectBuilderImpl.java deleted file mode 100644 index 393115cf..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonObjectBuilderImpl.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.*; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; - -/** - * JsonObjectBuilder implementation - * - * @author Jitendra Kotamraju - * @author Kin-man Chung - */ -class JsonObjectBuilderImpl implements JsonObjectBuilder { - - protected Map valueMap; - private final BufferPool bufferPool; - private final boolean rejectDuplicateKeys; - - JsonObjectBuilderImpl(BufferPool bufferPool) { - this.bufferPool = bufferPool; - rejectDuplicateKeys = false; - } - - JsonObjectBuilderImpl(BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - } - - JsonObjectBuilderImpl(JsonObject object, BufferPool bufferPool) { - this.bufferPool = bufferPool; - valueMap = new LinkedHashMap<>(); - valueMap.putAll(object); - rejectDuplicateKeys = false; - } - - JsonObjectBuilderImpl(JsonObject object, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - valueMap = new LinkedHashMap<>(); - valueMap.putAll(object); - this.rejectDuplicateKeys = rejectDuplicateKeys; - } - - JsonObjectBuilderImpl(Map map, BufferPool bufferPool) { - this.bufferPool = bufferPool; - valueMap = new LinkedHashMap<>(); - populate(map); - rejectDuplicateKeys = false; - } - - JsonObjectBuilderImpl(Map map, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - valueMap = new LinkedHashMap<>(); - populate(map); - this.rejectDuplicateKeys = rejectDuplicateKeys; - } - - @Override - public JsonObjectBuilder add(String name, JsonValue value) { - validateName(name); - validateValue(value); - putValueMap(name, value); - return this; - } - - @Override - public JsonObjectBuilder add(String name, String value) { - validateName(name); - validateValue(value); - putValueMap(name, new JsonStringImpl(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, BigInteger value) { - validateName(name); - validateValue(value); - putValueMap(name, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, BigDecimal value) { - validateName(name); - validateValue(value); - putValueMap(name, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, int value) { - validateName(name); - putValueMap(name, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, long value) { - validateName(name); - putValueMap(name, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, double value) { - validateName(name); - putValueMap(name, JsonNumberImpl.getJsonNumber(value)); - return this; - } - - @Override - public JsonObjectBuilder add(String name, boolean value) { - validateName(name); - putValueMap(name, value ? JsonValue.TRUE : JsonValue.FALSE); - return this; - } - - @Override - public JsonObjectBuilder addNull(String name) { - validateName(name); - putValueMap(name, JsonValue.NULL); - return this; - } - - @Override - public JsonObjectBuilder add(String name, JsonObjectBuilder builder) { - validateName(name); - if (builder == null) { - throw new NullPointerException(JsonMessages.OBJBUILDER_OBJECT_BUILDER_NULL()); - } - putValueMap(name, builder.build()); - return this; - } - - @Override - public JsonObjectBuilder add(String name, JsonArrayBuilder builder) { - validateName(name); - if (builder == null) { - throw new NullPointerException(JsonMessages.OBJBUILDER_ARRAY_BUILDER_NULL()); - } - putValueMap(name, builder.build()); - return this; - } - - @Override - public JsonObjectBuilder addAll(JsonObjectBuilder builder) { - if (builder == null) { - throw new NullPointerException(JsonMessages.OBJBUILDER_OBJECT_BUILDER_NULL()); - } - if (valueMap == null) { - this.valueMap = new LinkedHashMap<>(); - } - this.valueMap.putAll(builder.build()); - return this; - } - - @Override - public JsonObjectBuilder remove(String name) { - validateName(name); - this.valueMap.remove(name); - return this; - } - - @Override - public JsonObject build() { - Map snapshot = (valueMap == null) - ? Collections.emptyMap() - : Collections.unmodifiableMap(valueMap); - valueMap = null; - return new JsonObjectImpl(snapshot, bufferPool); - } - - private void populate(Map map) { - final Set fields = map.keySet(); - for (String field : fields) { - Object value = map.get(field); - if (value != null && value instanceof Optional) { - ((Optional) value).ifPresent(v -> - this.valueMap.put(field, MapUtil.handle(v, bufferPool))); - } else { - this.valueMap.put(field, MapUtil.handle(value, bufferPool)); - } - } - } - - private void putValueMap(String name, JsonValue value) { - if (valueMap == null) { - this.valueMap = new LinkedHashMap<>(); - } - JsonValue previousValue = valueMap.put(name, value); - if (rejectDuplicateKeys && previousValue != null) { - throw new IllegalStateException(JsonMessages.DUPLICATE_KEY(name)); - } - } - - private void validateName(String name) { - if (name == null) { - throw new NullPointerException(JsonMessages.OBJBUILDER_NAME_NULL()); - } - } - - private void validateValue(Object value) { - if (value == null) { - throw new NullPointerException(JsonMessages.OBJBUILDER_VALUE_NULL()); - } - } - - private static final class JsonObjectImpl extends AbstractMap implements JsonObject { - private final Map valueMap; // unmodifiable - private final BufferPool bufferPool; - private int hashCode; - - JsonObjectImpl(Map valueMap, BufferPool bufferPool) { - this.valueMap = valueMap; - this.bufferPool = bufferPool; - } - - @Override - public JsonArray getJsonArray(String name) { - return (JsonArray)get(name); - } - - @Override - public JsonObject getJsonObject(String name) { - return (JsonObject)get(name); - } - - @Override - public JsonNumber getJsonNumber(String name) { - return (JsonNumber)get(name); - } - - @Override - public JsonString getJsonString(String name) { - return (JsonString)get(name); - } - - @Override - public String getString(String name) { - return getJsonString(name).getString(); - } - - @Override - public String getString(String name, String defaultValue) { - JsonValue value = get(name); - if (value instanceof JsonString) { - return ((JsonString) value).getString(); - } else { - return defaultValue; - } - } - - @Override - public int getInt(String name) { - return getJsonNumber(name).intValue(); - } - - @Override - public int getInt(String name, int defaultValue) { - JsonValue value = get(name); - if (value instanceof JsonNumber) { - return ((JsonNumber) value).intValue(); - } else { - return defaultValue; - } - } - - @Override - public boolean getBoolean(String name) { - JsonValue value = get(name); - if (value == null) { - throw new NullPointerException(); - } else if (value == JsonValue.TRUE) { - return true; - } else if (value == JsonValue.FALSE) { - return false; - } else { - throw new ClassCastException(); - } - } - - @Override - public boolean getBoolean(String name, boolean defaultValue) { - JsonValue value = get(name); - if (value == JsonValue.TRUE) { - return true; - } else if (value == JsonValue.FALSE) { - return false; - } else { - return defaultValue; - } - } - - @Override - public boolean isNull(String name) { - return get(name).equals(JsonValue.NULL); - } - - @Override - public ValueType getValueType() { - return ValueType.OBJECT; - } - - @Override - public Set> entrySet() { - return valueMap.entrySet(); - } - - @Override - public int hashCode() { - if (hashCode == 0) { - hashCode = super.hashCode(); - } - return hashCode; - } - - @Override - public String toString() { - StringWriter sw = new StringWriter(); - try (JsonWriter jw = new JsonWriterImpl(sw, bufferPool)) { - jw.write(this); - } - return sw.toString(); - } - - @Override - public JsonObject asJsonObject() { - return this; - } - - @Override - public int size() { - return valueMap.size(); - } - - @Override - public JsonValue get(Object key) { - return valueMap.get(key); - } - - @Override - public boolean containsKey(Object key) { - return valueMap.containsKey(key); - } - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonParserFactoryImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonParserFactoryImpl.java deleted file mode 100644 index f3388858..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonParserFactoryImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.stream.JsonParserFactory; -import jakarta.json.stream.JsonParser; -import java.io.InputStream; -import java.io.Reader; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonParserFactoryImpl implements JsonParserFactory { - private final Map config = Collections.emptyMap(); - private final BufferPool bufferPool; - - JsonParserFactoryImpl(BufferPool bufferPool) { - this.bufferPool = bufferPool; - } - - @Override - public JsonParser createParser(Reader reader) { - return new JsonParserImpl(reader, bufferPool); - } - - @Override - public JsonParser createParser(InputStream in) { - return new JsonParserImpl(in, bufferPool); - } - - @Override - public JsonParser createParser(InputStream in, Charset charset) { - return new JsonParserImpl(in, charset, bufferPool); - } - - @Override - public JsonParser createParser(JsonArray array) { - return new JsonStructureParser(array); - } - - @Override - public Map getConfigInUse() { - return config; - } - - @Override - public JsonParser createParser(JsonObject object) { - return new JsonStructureParser(object); - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonParserImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonParserImpl.java deleted file mode 100644 index ac993b46..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonParserImpl.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.math.BigDecimal; -import java.nio.charset.Charset; -import java.util.AbstractMap; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParsingException; - -import org.eclipse.jsonp.JsonTokenizer.JsonToken; -import org.eclipse.jsonp.api.BufferPool; - -/** - * JSON parser implementation. NoneContext, ArrayContext, ObjectContext is used - * to go to next parser state. - * - * @author Jitendra Kotamraju - * @author Kin-man Chung - */ -public class JsonParserImpl implements JsonParser { - - private final BufferPool bufferPool; - private final boolean rejectDuplicateKeys; - private Context currentContext = new NoneContext(); - private Event currentEvent; - - private final Stack stack = new Stack(); - private final JsonTokenizer tokenizer; - - public JsonParserImpl(Reader reader, BufferPool bufferPool) { - this(reader, bufferPool, false); - } - - public JsonParserImpl(Reader reader, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - tokenizer = new JsonTokenizer(reader, bufferPool); - } - - public JsonParserImpl(InputStream in, BufferPool bufferPool) { - this(in, bufferPool, false); - } - - public JsonParserImpl(InputStream in, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - UnicodeDetectingInputStream uin = new UnicodeDetectingInputStream(in); - tokenizer = new JsonTokenizer(new InputStreamReader(uin, uin.getCharset()), bufferPool); - } - - public JsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool) { - this(in, encoding, bufferPool, false); - } - - public JsonParserImpl(InputStream in, Charset encoding, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - tokenizer = new JsonTokenizer(new InputStreamReader(in, encoding), bufferPool); - } - - @Override - public String getString() { - if (currentEvent == Event.KEY_NAME || currentEvent == Event.VALUE_STRING - || currentEvent == Event.VALUE_NUMBER) { - return tokenizer.getValue(); - } - throw new IllegalStateException( - JsonMessages.PARSER_GETSTRING_ERR(currentEvent)); - } - - @Override - public boolean isIntegralNumber() { - if (currentEvent != Event.VALUE_NUMBER) { - throw new IllegalStateException( - JsonMessages.PARSER_ISINTEGRALNUMBER_ERR(currentEvent)); - } - return tokenizer.isIntegral(); - } - - @Override - public int getInt() { - if (currentEvent != Event.VALUE_NUMBER) { - throw new IllegalStateException( - JsonMessages.PARSER_GETINT_ERR(currentEvent)); - } - return tokenizer.getInt(); - } - - boolean isDefinitelyInt() { - return tokenizer.isDefinitelyInt(); - } - - boolean isDefinitelyLong() { - return tokenizer.isDefinitelyLong(); - } - - @Override - public long getLong() { - if (currentEvent != Event.VALUE_NUMBER) { - throw new IllegalStateException( - JsonMessages.PARSER_GETLONG_ERR(currentEvent)); - } - return tokenizer.getLong(); - } - - @Override - public BigDecimal getBigDecimal() { - if (currentEvent != Event.VALUE_NUMBER) { - throw new IllegalStateException( - JsonMessages.PARSER_GETBIGDECIMAL_ERR(currentEvent)); - } - return tokenizer.getBigDecimal(); - } - - @Override - public JsonArray getArray() { - if (currentEvent != Event.START_ARRAY) { - throw new IllegalStateException( - JsonMessages.PARSER_GETARRAY_ERR(currentEvent)); - } - return getArray(new JsonArrayBuilderImpl(bufferPool)); - } - - @Override - public JsonObject getObject() { - if (currentEvent != Event.START_OBJECT) { - throw new IllegalStateException( - JsonMessages.PARSER_GETOBJECT_ERR(currentEvent)); - } - return getObject(new JsonObjectBuilderImpl(bufferPool, rejectDuplicateKeys)); - } - - @Override - public JsonValue getValue() { - switch (currentEvent) { - case START_ARRAY: - return getArray(new JsonArrayBuilderImpl(bufferPool)); - case START_OBJECT: - return getObject(new JsonObjectBuilderImpl(bufferPool, rejectDuplicateKeys)); - case KEY_NAME: - case VALUE_STRING: - return new JsonStringImpl(getCharSequence()); - case VALUE_NUMBER: - if (isDefinitelyInt()) { - return JsonNumberImpl.getJsonNumber(getInt()); - } else if (isDefinitelyLong()) { - return JsonNumberImpl.getJsonNumber(getLong()); - } - return JsonNumberImpl.getJsonNumber(getBigDecimal()); - case VALUE_TRUE: - return JsonValue.TRUE; - case VALUE_FALSE: - return JsonValue.FALSE; - case VALUE_NULL: - return JsonValue.NULL; - case END_ARRAY: - case END_OBJECT: - default: - throw new IllegalStateException(JsonMessages.PARSER_GETVALUE_ERR(currentEvent)); - } - } - - @Override - public Stream getArrayStream() { - if (currentEvent != Event.START_ARRAY) { - throw new IllegalStateException( - JsonMessages.PARSER_GETARRAY_ERR(currentEvent)); - } - Spliterator spliterator = - new Spliterators.AbstractSpliterator(Long.MAX_VALUE, Spliterator.ORDERED) { - @Override - public Spliterator trySplit() { - return null; - } - @Override - public boolean tryAdvance(Consumer action) { - if (action == null) { - throw new NullPointerException(); - } - if (! hasNext()) { - return false; - } - if (next() == JsonParser.Event.END_ARRAY) { - return false; - } - action.accept(getValue()); - return true; - } - }; - return StreamSupport.stream(spliterator, false); - } - - @Override - public Stream> getObjectStream() { - if (currentEvent != Event.START_OBJECT) { - throw new IllegalStateException( - JsonMessages.PARSER_GETOBJECT_ERR(currentEvent)); - } - Spliterator> spliterator = - new Spliterators.AbstractSpliterator>(Long.MAX_VALUE, Spliterator.ORDERED) { - @Override - public Spliterator> trySplit() { - return null; - } - @Override - public boolean tryAdvance(Consumer> action) { - if (action == null) { - throw new NullPointerException(); - } - if (! hasNext()) { - return false; - } - JsonParser.Event e = next(); - if (e == JsonParser.Event.END_OBJECT) { - return false; - } - if (e != JsonParser.Event.KEY_NAME) { - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - String key = getString(); - if (! hasNext()) { - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - next(); - JsonValue value = getValue(); - action.accept(new AbstractMap.SimpleImmutableEntry<>(key, value)); - return true; - } - }; - return StreamSupport.stream(spliterator, false); - } - - @Override - public Stream getValueStream() { - if (! (currentContext instanceof NoneContext)) { - throw new IllegalStateException( - JsonMessages.PARSER_GETVALUESTREAM_ERR()); - } - Spliterator spliterator = - new Spliterators.AbstractSpliterator(Long.MAX_VALUE, Spliterator.ORDERED) { - @Override - public Spliterator trySplit() { - return null; - } - @Override - public boolean tryAdvance(Consumer action) { - if (action == null) { - throw new NullPointerException(); - } - if (! hasNext()) { - return false; - } - next(); - action.accept(getValue()); - return true; - } - }; - return StreamSupport.stream(spliterator, false); - } - - @Override - public void skipArray() { - if (currentEvent == Event.START_ARRAY) { - currentContext.skip(); - currentContext = stack.pop(); - currentEvent = Event.END_ARRAY; - } - } - - @Override - public void skipObject() { - if (currentEvent == Event.START_OBJECT) { - currentContext.skip(); - currentContext = stack.pop(); - currentEvent = Event.END_OBJECT; - } - } - - private JsonArray getArray(JsonArrayBuilder builder) { - while(hasNext()) { - JsonParser.Event e = next(); - if (e == JsonParser.Event.END_ARRAY) { - return builder.build(); - } - builder.add(getValue()); - } - throw parsingException(JsonToken.EOF, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL, SQUARECLOSE]"); - } - - private CharSequence getCharSequence() { - if (currentEvent == Event.KEY_NAME || currentEvent == Event.VALUE_STRING - || currentEvent == Event.VALUE_NUMBER) { - return tokenizer.getCharSequence(); - } - throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(currentEvent)); - } - - private JsonObject getObject(JsonObjectBuilder builder) { - while(hasNext()) { - JsonParser.Event e = next(); - if (e == JsonParser.Event.END_OBJECT) { - return builder.build(); - } - String key = getString(); - next(); - builder.add(key, getValue()); - } - throw parsingException(JsonToken.EOF, "[STRING, CURLYCLOSE]"); - } - - @Override - public JsonLocation getLocation() { - return tokenizer.getLocation(); - } - - public JsonLocation getLastCharLocation() { - return tokenizer.getLastCharLocation(); - } - - @Override - public boolean hasNext() { - if (stack.isEmpty() && (currentEvent != null && currentEvent.compareTo(Event.KEY_NAME) > 0)) { - JsonToken token = tokenizer.nextToken(); - if (token != JsonToken.EOF) { - throw new JsonParsingException(JsonMessages.PARSER_EXPECTED_EOF(token), - getLastCharLocation()); - } - return false; - } else if (!stack.isEmpty() && !tokenizer.hasNextToken()) { - currentEvent = currentContext.getNextEvent(); - return false; - } - return true; - } - - @Override - public Event next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return currentEvent = currentContext.getNextEvent(); - } - - @Override - public void close() { - try { - tokenizer.close(); - } catch (IOException e) { - throw new JsonException(JsonMessages.PARSER_TOKENIZER_CLOSE_IO(), e); - } - } - - // Using the optimized stack impl as we don't require other things - // like iterator etc. - private static final class Stack { - private Context head; - - private void push(Context context) { - context.next = head; - head = context; - } - - private Context pop() { - if (head == null) { - throw new NoSuchElementException(); - } - Context temp = head; - head = head.next; - return temp; - } - - private Context peek() { - return head; - } - - private boolean isEmpty() { - return head == null; - } - } - - private abstract class Context { - Context next; - abstract Event getNextEvent(); - abstract void skip(); - } - - private final class NoneContext extends Context { - @Override - public Event getNextEvent() { - // Handle 1. { 2. [ 3. value - JsonToken token = tokenizer.nextToken(); - if (token == JsonToken.CURLYOPEN) { - stack.push(currentContext); - currentContext = new ObjectContext(); - return Event.START_OBJECT; - } else if (token == JsonToken.SQUAREOPEN) { - stack.push(currentContext); - currentContext = new ArrayContext(); - return Event.START_ARRAY; - } else if (token.isValue()) { - return token.getEvent(); - } - throw parsingException(token, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]"); - } - - @Override - void skip() { - // no-op - } - } - - private JsonParsingException parsingException(JsonToken token, String expectedTokens) { - JsonLocation location = getLastCharLocation(); - return new JsonParsingException( - JsonMessages.PARSER_INVALID_TOKEN(token, location, expectedTokens), location); - } - - private final class ObjectContext extends Context { - private boolean firstValue = true; - - /* - * Some more things could be optimized. For example, instead - * tokenizer.nextToken(), one could use tokenizer.matchColonToken() to - * match ':'. That might optimize a bit, but will fragment nextToken(). - * I think the current one is more readable. - * - */ - @Override - public Event getNextEvent() { - // Handle 1. } 2. name:value 3. ,name:value - JsonToken token = tokenizer.nextToken(); - if (token == JsonToken.EOF) { - switch (currentEvent) { - case START_OBJECT: - throw parsingException(token, "[STRING, CURLYCLOSE]"); - case KEY_NAME: - throw parsingException(token, "[COLON]"); - default: - throw parsingException(token, "[COMMA, CURLYCLOSE]"); - } - } else if (currentEvent == Event.KEY_NAME) { - // Handle 1. :value - if (token != JsonToken.COLON) { - throw parsingException(token, "[COLON]"); - } - token = tokenizer.nextToken(); - if (token.isValue()) { - return token.getEvent(); - } else if (token == JsonToken.CURLYOPEN) { - stack.push(currentContext); - currentContext = new ObjectContext(); - return Event.START_OBJECT; - } else if (token == JsonToken.SQUAREOPEN) { - stack.push(currentContext); - currentContext = new ArrayContext(); - return Event.START_ARRAY; - } - throw parsingException(token, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]"); - } else { - // Handle 1. } 2. name 3. ,name - if (token == JsonToken.CURLYCLOSE) { - currentContext = stack.pop(); - return Event.END_OBJECT; - } - if (firstValue) { - firstValue = false; - } else { - if (token != JsonToken.COMMA) { - throw parsingException(token, "[COMMA]"); - } - token = tokenizer.nextToken(); - } - if (token == JsonToken.STRING) { - return Event.KEY_NAME; - } - throw parsingException(token, "[STRING]"); - } - } - - @Override - void skip() { - JsonToken token; - int depth = 1; - do { - token = tokenizer.nextToken(); - switch (token) { - case CURLYCLOSE: - depth--; - break; - case CURLYOPEN: - depth++; - break; - } - } while (!(token == JsonToken.CURLYCLOSE && depth == 0)); - } - - } - - private final class ArrayContext extends Context { - private boolean firstValue = true; - - // Handle 1. ] 2. value 3. ,value - @Override - public Event getNextEvent() { - JsonToken token = tokenizer.nextToken(); - if (token == JsonToken.EOF) { - switch (currentEvent) { - case START_ARRAY: - throw parsingException(token, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]"); - default: - throw parsingException(token, "[COMMA, CURLYCLOSE]"); - } - } - if (token == JsonToken.SQUARECLOSE) { - currentContext = stack.pop(); - return Event.END_ARRAY; - } - if (firstValue) { - firstValue = false; - } else { - if (token != JsonToken.COMMA) { - throw parsingException(token, "[COMMA]"); - } - token = tokenizer.nextToken(); - } - if (token.isValue()) { - return token.getEvent(); - } else if (token == JsonToken.CURLYOPEN) { - stack.push(currentContext); - currentContext = new ObjectContext(); - return Event.START_OBJECT; - } else if (token == JsonToken.SQUAREOPEN) { - stack.push(currentContext); - currentContext = new ArrayContext(); - return Event.START_ARRAY; - } - throw parsingException(token, "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]"); - } - - @Override - void skip() { - JsonToken token; - int depth = 1; - do { - token = tokenizer.nextToken(); - switch (token) { - case SQUARECLOSE: - depth--; - break; - case SQUAREOPEN: - depth++; - break; - } - } while (!(token == JsonToken.SQUARECLOSE && depth == 0)); - } - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonPatchBuilderImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonPatchBuilderImpl.java deleted file mode 100644 index 6c436f3e..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonPatchBuilderImpl.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonException; -import jakarta.json.JsonPatch; -import jakarta.json.JsonPatch.Operation; -import jakarta.json.JsonPatchBuilder; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -/** - * A builder for constructing a JSON Patch by adding - * JSON Patch operations incrementally. - *

- * The following illustrates the approach. - *

- *   JsonPatchBuilder builder = Json.createPatchBuilder();
- *   JsonPatch patch = builder.add("/John/phones/office", "1234-567")
- *                            .remove("/Amy/age")
- *                            .build();
- * 
- * The result is equivalent to the following JSON Patch. - *
- * [
- *    {"op" = "add", "path" = "/John/phones/office", "value" = "1234-567"},
- *    {"op" = "remove", "path" = "/Amy/age"}
- * ] 
- * - * @since 1.1 - */ -public final class JsonPatchBuilderImpl implements JsonPatchBuilder { - - private final JsonArrayBuilder builder; - - /** - * Creates a JsonPatchBuilderImpl, starting with the specified - * JSON Patch - * @param patch the JSON Patch - */ - public JsonPatchBuilderImpl(JsonArray patch) { - builder = new JsonArrayBuilderImpl(patch, JsonUtil.getInternalBufferPool()); - } - - /** - * Creates JsonPatchBuilderImpl with empty JSON Patch - */ - public JsonPatchBuilderImpl() { - builder = new JsonArrayBuilderImpl(JsonUtil.getInternalBufferPool()); - } - - /** - * A convenience method for {@code new JsonPatchImpl(build()).apply(target)}. - * The target is not modified by the patch. - * - * @param the target type, must be a subtype of {@link JsonStructure} - * @param target the target to apply the patch operations - * @return the transformed target after the patch - * @throws JsonException if the supplied JSON Patch is malformed or if - * it contains references to non-existing members - */ - public T apply(T target) { - return build().apply(target); - } - - /** - * Adds an "add" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder add(String path, JsonValue value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.ADD.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds an "add" JSON Patch operation - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder add(String path, String value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.ADD.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds an "add" JSON Patch operation - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder add(String path, int value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.ADD.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds an "add" JSON Patch operation - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder add(String path, boolean value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.ADD.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "remove" JSON Patch operation. - * @param path the "path" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder remove(String path) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.REMOVE.operationName()) - .add("path", path) - ); - return this; - } - - /** - * Adds a "replace" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder replace(String path, JsonValue value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.REPLACE.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "replace" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder replace(String path, String value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.REPLACE.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "replace" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder replace(String path, int value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.REPLACE.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "replace" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder replace(String path, boolean value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.REPLACE.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "move" JSON Patch operation. - * @param path the "path" member of the operation - * @param from the "from" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder move(String path, String from) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.MOVE.operationName()) - .add("path", path) - .add("from", from) - ); - return this; - } - - /** - * Adds a "copy" JSON Patch operation. - * @param path the "path" member of the operation - * @param from the "from" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder copy(String path, String from) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.COPY.operationName()) - .add("path", path) - .add("from", from) - ); - return this; - } - - /** - * Adds a "test" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder test(String path, JsonValue value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.TEST.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "test" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder test(String path, String value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.TEST.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "test" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder test(String path, int value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.TEST.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Adds a "test" JSON Patch operation. - * @param path the "path" member of the operation - * @param value the "value" member of the operation - * @return this JsonPatchBuilder - */ - @Override - public JsonPatchBuilder test(String path, boolean value) { - builder.add(new JsonObjectBuilderImpl(JsonUtil.getInternalBufferPool()) - .add("op", Operation.TEST.operationName()) - .add("path", path) - .add("value", value) - ); - return this; - } - - /** - * Returns the patch operations in a JsonArray - * @return the patch operations in a JsonArray - */ - public JsonArray buildAsJsonArray() { - return builder.build(); - } - - /** - * Returns the patch operation in a JsonPatch - * @return the patch operation in a JsonPatch - */ - @Override - public JsonPatch build() { - return new JsonPatchImpl(buildAsJsonArray()); - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonPatchImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonPatchImpl.java deleted file mode 100644 index e285b6da..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonPatchImpl.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonPatch; -import jakarta.json.JsonPatchBuilder; -import jakarta.json.JsonPointer; -import jakarta.json.JsonString; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; -import jakarta.json.JsonValue.ValueType; - -/** - * This class is an immutable representation of a JSON Patch as specified in - * RFC 6902. - *

A {@code JsonPatch} can be instantiated with {@link Json#createPatch(JsonArray)} - * by specifying the patch operations in a JSON Patch. Alternately, it - * can also be constructed with a {@link JsonPatchBuilder}. - *

- * The following illustrates both approaches. - *

1. Construct a JsonPatch with a JSON Patch. - *

{@code
- *   JsonArray contacts = ... // The target to be patched
- *   JsonArray patch = ...  ; // JSON Patch
- *   JsonPatch jsonpatch = Json.createPatch(patch);
- *   JsonArray result = jsonpatch.apply(contacts);
- * } 
- * 2. Construct a JsonPatch with JsonPatchBuilder. - *
{@code
- *   JsonPatchBuilder builder = Json.createPatchBuilder();
- *   JsonArray result = builder.add("/John/phones/office", "1234-567")
- *                             .remove("/Amy/age")
- *                             .build()
- *                             .apply(contacts);
- * } 
- * - * @since 1.1 - */ -public class JsonPatchImpl implements JsonPatch { - - private final JsonArray patch; - - /** - * Constructs a JsonPatchImpl - * @param patch the JSON Patch - */ - public JsonPatchImpl(JsonArray patch) { - this.patch = patch; - } - - /** - * Compares this {@code JsonPatchImpl} with another object. - * @param obj the object to compare this {@code JsonPatchImpl} against - * @return true if the given object is a {@code JsonPatchImpl} with the same - * reference tokens as this one, false otherwise. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || obj.getClass() != JsonPatchImpl.class) - return false; - return patch.equals(((JsonPatchImpl)obj).patch); - } - - /** - * Returns the hash code value for this {@code JsonPatchImpl}. - * - * @return the hash code value for this {@code JsonPatchImpl} object - */ - @Override - public int hashCode() { - return patch.hashCode(); - } - - /** - * Returns the JSON Patch text - * @return the JSON Patch text - */ - @Override - public String toString() { - return patch.toString(); - } - - /** - * Applies the patch operations to the specified {@code target}. - * The target is not modified by the patch. - * - * @param target the target to apply the patch operations - * @return the transformed target after the patch - * @throws JsonException if the supplied JSON Patch is malformed or if - * it contains references to non-existing members - */ - @Override - public JsonStructure apply(JsonStructure target) { - - JsonStructure result = target; - - for (JsonValue operation: patch) { - if (operation.getValueType() != ValueType.OBJECT) { - throw new JsonException(JsonMessages.PATCH_MUST_BE_ARRAY()); - } - result = apply(result, (JsonObject) operation); - } - return result; - } - - @Override - public JsonArray toJsonArray() { - return patch; - } - - /** - * Generates a JSON Patch from the source and target {@code JsonStructure}. - * The generated JSON Patch need not be unique. - * @param source the source - * @param target the target, must be the same type as the source - * @return a JSON Patch which when applied to the source, yields the target - */ - public static JsonArray diff(JsonStructure source, JsonStructure target) { - return (new DiffGenerator()).diff(source, target); - } - - /** - * Applies a JSON Patch operation to the target. - * @param target the target to apply the operation - * @param operation the JSON Patch operation - * @return the target after the patch - */ - private JsonStructure apply(JsonStructure target, JsonObject operation) { - - JsonPointer pointer = getPointer(operation, "path"); - JsonPointer from; - JsonString op = operation.getJsonString("op"); - if (op == null) { - throw new JsonException(JsonMessages.PATCH_OPERATION_MISSING()); - } - switch (Operation.fromOperationName(op.getString())) { - case ADD: - return pointer.add(target, getValue(operation)); - case REPLACE: - return pointer.replace(target, getValue(operation)); - case REMOVE: - return pointer.remove(target); - case COPY: - from = getPointer(operation, "from"); - return pointer.add(target, from.getValue(target)); - case MOVE: - // Check if from is a proper prefix of path - String dest = operation.getString("path"); - String src = operation.getString("from"); - if (dest.startsWith(src) && src.length() < dest.length()) { - throw new JsonException(JsonMessages.PATCH_MOVE_PROPER_PREFIX(src, dest)); - } - from = getPointer(operation, "from"); - // Check if 'from' exists in target object - if (!from.containsValue(target)) { - throw new JsonException(JsonMessages.PATCH_MOVE_TARGET_NULL(src)); - } - if (pointer.equals(from)) { - // nop - return target; - } - return pointer.add(from.remove(target), from.getValue(target)); - case TEST: - if (! getValue(operation).equals(pointer.getValue(target))) { - throw new JsonException(JsonMessages.PATCH_TEST_FAILED(operation.getString("path"), getValue(operation).toString())); - } - return target; - default: - throw new JsonException(JsonMessages.PATCH_ILLEGAL_OPERATION(operation.getString("op"))); - } - } - - private JsonPointer getPointer(JsonObject operation, String member) { - JsonString pointerString = operation.getJsonString(member); - if (pointerString == null) { - missingMember(operation.getString("op"), member); - } - return new JsonPointerImpl(pointerString.getString()); - } - - private JsonValue getValue(JsonObject operation) { - JsonValue value = operation.get("value"); - if (value == null) { - missingMember(operation.getString("op"), "value"); - } - return value; - } - - private void missingMember(String op, String member) { - throw new JsonException(JsonMessages.PATCH_MEMBER_MISSING(op, member)); - } - - static class DiffGenerator { - private JsonPatchBuilder builder; - - JsonArray diff(JsonStructure source, JsonStructure target) { - builder = new JsonPatchBuilderImpl(); - diff("", source, target); - return builder.build().toJsonArray(); - } - - private void diff(String path, JsonValue source, JsonValue target) { - if (source.equals(target)) { - return; - } - ValueType s = source.getValueType(); - ValueType t = target.getValueType(); - if (s == ValueType.OBJECT && t == ValueType.OBJECT) { - diffObject(path, (JsonObject) source, (JsonObject) target); - } else if (s == ValueType.ARRAY && t == ValueType.ARRAY) { - diffArray(path, (JsonArray) source, (JsonArray) target); - } else { - builder.replace(path, target); - } - } - - private void diffObject(String path, JsonObject source, JsonObject target) { - source.forEach((key, value) -> { - if (target.containsKey(key)) { - diff(path + '/' + Json.encodePointer(key), value, target.get(key)); - } else { - builder.remove(path + '/' + Json.encodePointer(key)); - } - }); - target.forEach((key, value) -> { - if (! source.containsKey(key)) { - builder.add(path + '/' + Json.encodePointer(key), value); - } - }); - } - - /* - * For array element diff, find the longest common subsequence, per - * http://en.wikipedia.org/wiki/Longest_common_subsequence_problem . - * We modify the algorithm to generate a replace if possible. - */ - private void diffArray(String path, JsonArray source, JsonArray target) { - /* The array c keeps track of length of the subsequence. To avoid - * computing the equality of array elements again, we - * left shift its value by 1, and use the low order bit to mark - * that two items are equal. - */ - int m = source.size(); - int n = target.size(); - int [][] c = new int[m+1][n+1]; - for (int i = 0; i < m+1; i++) - c[i][0] = 0; - for (int i = 0; i < n+1; i++) - c[0][i] = 0; - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - if (source.get(i).equals(target.get(j))) { - c[i+1][j+1] = ((c[i][j]) & ~1) + 3; - // 3 = (1 << 1) | 1; - } else { - c[i+1][j+1] = Math.max(c[i+1][j], c[i][j+1]) & ~1; - } - } - } - - emit(path, source, target, c, m, n); - } - - private void emit(final String path, - final JsonArray source, - final JsonArray target, - final int[][] c, - final int i, - final int j) { - if (i == 0) { - if (j > 0) { - emit(path, source, target, c, i, j - 1); - builder.add(path + '/' + (j - 1), target.get(j - 1)); - } - } else if (j == 0) { - if (i > 0) { - builder.remove(path + '/' + (i - 1)); - emit(path, source, target, c, i - 1, j); - } - } else if ((c[i][j] & 1) == 1) { - emit(path, source, target, c, i - 1, j - 1); - } else { - final int f = c[i][j-1] >> 1; - final int g = c[i-1][j] >> 1; - if (f > g) { - emit(path, source, target, c, i, j - 1); - builder.add(path + '/' + (j - 1), target.get(j - 1)); - } else if (f < g) { - builder.remove(path + '/' + (i - 1)); - emit(path, source, target, c, i - 1, j); - } else { // f == g) { - diff(path + '/' + (i - 1), source.get(i - 1), - target.get(j - 1)); - emit(path, source, target, c, i - 1, j - 1); - } - } - } - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonPointerImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonPointerImpl.java deleted file mode 100644 index 395dcc86..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonPointerImpl.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonArray; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonPointer; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; -import java.io.Serializable; -import java.util.function.BiFunction; - -/** - *

This class is an immutable representation of a JSON Pointer as specified in - * RFC 6901. - *

- *

A JSON Pointer, when applied to a target {@link JsonValue}, - * defines a reference location in the target.

- *

An empty JSON Pointer string defines a reference to the target itself.

- *

If the JSON Pointer string is non-empty, it must be a sequence - * of '/' prefixed tokens, and the target must either be a {@link JsonArray} - * or {@link JsonObject}. If the target is a {@code JsonArray}, the pointer - * defines a reference to an array element, and the last token specifies the index. - * If the target is a {@link JsonObject}, the pointer defines a reference to a - * name/value pair, and the last token specifies the name. - *

- *

The method {@link #getValue getValue()} returns the referenced value. - * The methods {@link #add add()}, {@link #replace replace()}, - * and {@link #remove remove()} executes the operations specified in - * RFC 6902.

- * - * @since 1.1 - */ - -public final class JsonPointerImpl implements JsonPointer, Serializable { - - private static final long serialVersionUID = -8123110179640843141L; - private final String[] tokens; - private final String jsonPointer; - - /** - * Constructs and initializes a JsonPointerImpl. - * @param jsonPointer the JSON Pointer string - * @throws NullPointerException if {@code jsonPointer} is {@code null} - * @throws JsonException if {@code jsonPointer} is not a valid JSON Pointer - */ - public JsonPointerImpl(String jsonPointer) { - this.jsonPointer = jsonPointer; - tokens = jsonPointer.split("/", -1); // keep the trailing blanks - if (! "".equals(tokens[0])) { - throw new JsonException(JsonMessages.POINTER_FORMAT_INVALID()); - } - for (int i = 1; i < tokens.length; i++) { - String token = tokens[i]; - StringBuilder reftoken = new StringBuilder(); - for (int j = 0; j < token.length(); j++) { - char ch = token.charAt(j); - if (ch == '~' && j < token.length() - 1) { - char ch1 = token.charAt(j+1); - if (ch1 == '0') { - ch = '~'; j++; - } else if (ch1 == '1') { - ch = '/'; j++; - } - } - reftoken.append(ch); - } - tokens[i] = reftoken.toString(); - } - } - - /** - * Compares this {@code JsonPointer} with another object. - * @param obj the object to compare this {@code JsonPointer} against - * @return true if the given object is a {@code JsonPointer} with the same - * reference tokens as this one, false otherwise. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || obj.getClass() != JsonPointerImpl.class) - return false; - return jsonPointer.equals(((JsonPointerImpl)obj).jsonPointer); - } - - /** - * Returns the hash code value for this {@code JsonPointer} object. - * The hash code of this object is defined by the hash codes of it's reference tokens. - * - * @return the hash code value for this {@code JsonPointer} object - */ - @Override - public int hashCode() { - return jsonPointer.hashCode(); - } - - /** - * Returns {@code true} if there is a value at the referenced location in the specified {@code target}. - * - * @param target the target referenced by this {@code JsonPointer} - * @return {@code true} if this pointer points to a value in a specified {@code target}. - */ - @Override - public boolean containsValue(JsonStructure target) { - NodeReference[] refs = getReferences(target); - return refs[0].contains(); - } - - /** - * Returns the value at the referenced location in the specified {@code target} - * - * @param target the target referenced by this {@code JsonPointer} - * @return the referenced value in the target. - * @throws NullPointerException if {@code target} is null - * @throws JsonException if the referenced value does not exist - */ - @Override - public JsonValue getValue(JsonStructure target) { - NodeReference[] refs = getReferences(target); - return refs[0].get(); - } - - /** - * Adds or replaces a value at the referenced location in the specified - * {@code target} with the specified {@code value}. - *
    - *
  1. If the reference is the target (empty JSON Pointer string), - * the specified {@code value}, which must be the same type as - * specified {@code target}, is returned.
  2. - *
  3. If the reference is an array element, the specified {@code value} is inserted - * into the array, at the referenced index. The value currently at that location, and - * any subsequent values, are shifted to the right (adds one to the indices). - * Index starts with 0. If the reference is specified with a "-", or if the - * index is equal to the size of the array, the value is appended to the array.
  4. - *
  5. If the reference is a name/value pair of a {@code JsonObject}, and the - * referenced value exists, the value is replaced by the specified {@code value}. - * If the value does not exist, a new name/value pair is added to the object.
  6. - *
- * - * @param target the target referenced by this {@code JsonPointer} - * @param value the value to be added - * @return the transformed {@code target} after the value is added. - * @throws NullPointerException if {@code target} is {@code null} - * @throws JsonException if the reference is an array element and - * the index is out of range ({@code index < 0 || index > array size}), - * or if the pointer contains references to non-existing objects or arrays. - */ - @Override - public JsonStructure add(JsonStructure target, JsonValue value) { - return execute(NodeReference::add, target, value); - } - - /** - * Replaces the value at the referenced location in the specified - * {@code target} with the specified {@code value}. - * - * @param target the target referenced by this {@code JsonPointer} - * @param value the value to be stored at the referenced location - * @return the transformed {@code target} after the value is replaced. - * @throws NullPointerException if {@code target} is {@code null} - * @throws JsonException if the referenced value does not exist, - * or if the reference is the target. - */ - @Override - public JsonStructure replace(JsonStructure target, JsonValue value) { - return execute(NodeReference::replace, target, value); - } - - /** - * Removes the value at the reference location in the specified {@code target} - * - * @param target the target referenced by this {@code JsonPointer} - * @return the transformed {@code target} after the value is removed. - * @throws NullPointerException if {@code target} is {@code null} - * @throws JsonException if the referenced value does not exist, - * or if the reference is the target. - */ - @Override - public JsonStructure remove(JsonStructure target) { - return execute((r,v)->r.remove(), target, null); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return jsonPointer; - } - - /** - * Executes the operation - * @param op a {code BiFunction} used to specify the operation to execute on - * the leaf node of the Json Pointer - * @param target the target JsonStructure for this JsonPointer - * @param value the JsonValue for add and replace, can be null for getvalue and remove - */ - private JsonStructure execute(BiFunction op, - JsonStructure target, JsonValue value) { - - NodeReference[] refs = getReferences(target); - JsonStructure result = op.apply(refs[0], value); - for (int i = 1; i < refs.length; i++) { - result = refs[i].replace(result); - } - return result; - } - - /** - * Computes the {@code NodeReference}s for each node on the path of - * the JSON Pointer, in reverse order, starting from the leaf node - */ - private NodeReference[] getReferences(JsonStructure target) { - NodeReference[] references; - // First check if this is a reference to a JSON value tree - if (tokens.length == 1) { - references = new NodeReference[1]; - references[0] = NodeReference.of(target); - return references; - } - - references = new NodeReference[tokens.length-1]; - JsonValue value = target; - int s = tokens.length; - for (int i = 1; i < s; i++) { - // Start with index 1, skipping the "" token - switch (value.getValueType()) { - case OBJECT: - JsonObject object = (JsonObject) value; - references[s-i-1] = NodeReference.of(object, tokens[i]); - if (i < s-1) { - value = object.get(tokens[i]); - if (value == null) { - // Except for the last name, the mapping must exist - throw new JsonException(JsonMessages.POINTER_MAPPING_MISSING(object, tokens[i])); - } - } - break; - case ARRAY: - int index = getIndex(tokens[i]); - JsonArray array = (JsonArray) value; - references[s-i-1] = NodeReference.of(array, index); - if (i < s-1 && index != -1) { - if (index >= array.size()) { - throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); - } - // The last array index in the path can have index value of -1 - // ("-" in the JSON pointer) - value = array.get(index); - } - break; - default: - throw new JsonException(JsonMessages.POINTER_REFERENCE_INVALID(value.getValueType())); - } - } - return references; - } - - /** - * Computes the array index - * @param token the input string token - * @return the array index. -1 if the token is "-" - * @throws JsonException if the string token is not in correct format - */ - static private int getIndex(String token) { - if (token == null || token.length() == 0) { - throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ERR(token)); - } - if (token.equals("-")) { - return -1; - } - if (token.equals("0")) { - return 0; - } - if (token.charAt(0) == '+' || token.charAt(0) == '-') { - throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ERR(token)); - } - try { - return Integer.parseInt(token); - } catch (NumberFormatException ex) { - throw new JsonException(JsonMessages.POINTER_ARRAY_INDEX_ILLEGAL(token), ex); - } - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonPrettyGeneratorImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonPrettyGeneratorImpl.java deleted file mode 100644 index fc75005c..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonPrettyGeneratorImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.stream.JsonGenerator; -import java.io.OutputStream; -import java.io.Writer; -import java.nio.charset.Charset; - -/** - * @author Jitendra Kotamraju - */ -public class JsonPrettyGeneratorImpl extends JsonGeneratorImpl { - private int indentLevel; - private static final String INDENT = " "; - - public JsonPrettyGeneratorImpl(Writer writer, BufferPool bufferPool) { - super(writer, bufferPool); - } - - public JsonPrettyGeneratorImpl(OutputStream out, BufferPool bufferPool) { - super(out, bufferPool); - } - - public JsonPrettyGeneratorImpl(OutputStream out, Charset encoding, BufferPool bufferPool) { - super(out, encoding, bufferPool); - } - - @Override - public JsonGenerator writeStartObject() { - super.writeStartObject(); - indentLevel++; - return this; - } - - @Override - public JsonGenerator writeStartObject(String name) { - super.writeStartObject(name); - indentLevel++; - return this; - } - - @Override - public JsonGenerator writeStartArray() { - super.writeStartArray(); - indentLevel++; - return this; - } - - @Override - public JsonGenerator writeStartArray(String name) { - super.writeStartArray(name); - indentLevel++; - return this; - } - - @Override - public JsonGenerator writeEnd() { - writeNewLine(); - indentLevel--; - writeIndent(); - super.writeEnd(); - return this; - } - - private void writeIndent() { - for(int i=0; i < indentLevel; i++) { - writeString(INDENT); - } - } - - @Override - protected void writeComma() { - super.writeComma(); - if (isCommaAllowed() && !inNone()) { - writeChar('\n'); - writeIndent(); - } - } - - @Override - protected void writeColon() { - super.writeColon(); - writeChar(' '); - } - - private void writeNewLine() { - writeChar('\n'); - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonProviderImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonProviderImpl.java deleted file mode 100644 index 698e71a7..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonProviderImpl.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; -import org.eclipse.jsonp.api.JsonConfig; - -import jakarta.json.*; -import jakarta.json.stream.JsonGenerator; -import jakarta.json.stream.JsonGeneratorFactory; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParserFactory; -import jakarta.json.spi.JsonProvider; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * @author Jitendra Kotamraju - * @author Kin-man Chung - * @author Alex Soto - */ -public class JsonProviderImpl extends JsonProvider { - private final BufferPool bufferPool = new BufferPoolImpl(); - - @Override - public JsonGenerator createGenerator(Writer writer) { - return new JsonGeneratorImpl(writer, bufferPool); - } - - @Override - public JsonGenerator createGenerator(OutputStream out) { - return new JsonGeneratorImpl(out, bufferPool); - } - - @Override - public JsonParser createParser(Reader reader) { - return new JsonParserImpl(reader, bufferPool); - } - - @Override - public JsonParser createParser(InputStream in) { - return new JsonParserImpl(in, bufferPool); - } - - @Override - public JsonParserFactory createParserFactory(Map config) { - BufferPool pool = null; - if (config != null && config.containsKey(BufferPool.class.getName())) { - pool = (BufferPool)config.get(BufferPool.class.getName()); - } - if (pool == null) { - pool = bufferPool; - } - return new JsonParserFactoryImpl(pool); - } - - @Override - public JsonGeneratorFactory createGeneratorFactory(Map config) { - Map providerConfig; - boolean prettyPrinting; - BufferPool pool; - if (config == null) { - providerConfig = Collections.emptyMap(); - prettyPrinting = false; - pool = bufferPool; - } else { - providerConfig = new HashMap<>(); - if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) { - providerConfig.put(JsonGenerator.PRETTY_PRINTING, true); - } - pool = (BufferPool)config.get(BufferPool.class.getName()); - if (pool != null) { - providerConfig.put(BufferPool.class.getName(), pool); - } else { - pool = bufferPool; - } - providerConfig = Collections.unmodifiableMap(providerConfig); - } - - return new JsonGeneratorFactoryImpl(providerConfig, prettyPrinting, pool); - } - - @Override - public JsonReader createReader(Reader reader) { - return new JsonReaderImpl(reader, bufferPool); - } - - @Override - public JsonReader createReader(InputStream in) { - return new JsonReaderImpl(in, bufferPool); - } - - @Override - public JsonWriter createWriter(Writer writer) { - return new JsonWriterImpl(writer, bufferPool); - } - - @Override - public JsonWriter createWriter(OutputStream out) { - return new JsonWriterImpl(out, bufferPool); - } - - @Override - public JsonWriterFactory createWriterFactory(Map config) { - Map providerConfig; - boolean prettyPrinting; - BufferPool pool; - if (config == null) { - providerConfig = Collections.emptyMap(); - prettyPrinting = false; - pool = bufferPool; - } else { - providerConfig = new HashMap<>(); - if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) { - providerConfig.put(JsonGenerator.PRETTY_PRINTING, true); - } - pool = (BufferPool)config.get(BufferPool.class.getName()); - if (pool != null) { - providerConfig.put(BufferPool.class.getName(), pool); - } else { - pool = bufferPool; - } - providerConfig = Collections.unmodifiableMap(providerConfig); - } - return new JsonWriterFactoryImpl(providerConfig, prettyPrinting, pool); - } - - @Override - public JsonReaderFactory createReaderFactory(Map config) { - Map providerConfig; - boolean rejectDuplicateKeys; - BufferPool pool; - if (config == null) { - providerConfig = Collections.emptyMap(); - rejectDuplicateKeys = false; - pool = bufferPool; - } else { - providerConfig = new HashMap<>(); - if (rejectDuplicateKeys = JsonProviderImpl.isRejectDuplicateKeysEnabled(config)) { - providerConfig.put(JsonConfig.REJECT_DUPLICATE_KEYS, true); - } - pool = (BufferPool) config.get(BufferPool.class.getName()); - if (pool != null) { - providerConfig.put(BufferPool.class.getName(), pool); - } else { - pool = bufferPool; - } - providerConfig = Collections.unmodifiableMap(providerConfig); - } - return new JsonReaderFactoryImpl(providerConfig, pool, rejectDuplicateKeys); - } - - @Override - public JsonObjectBuilder createObjectBuilder() { - return new JsonObjectBuilderImpl(bufferPool); - } - - @Override - public JsonObjectBuilder createObjectBuilder(JsonObject object) { - return new JsonObjectBuilderImpl(object, bufferPool); - } - - @Override - public JsonObjectBuilder createObjectBuilder(Map map) { - return new JsonObjectBuilderImpl(map, bufferPool); - } - - @Override - public JsonArrayBuilder createArrayBuilder() { - return new JsonArrayBuilderImpl(bufferPool); - } - - @Override - public JsonArrayBuilder createArrayBuilder(JsonArray array) { - return new JsonArrayBuilderImpl(array, bufferPool); - } - - @Override - public JsonArrayBuilder createArrayBuilder(Collection collection) { - return new JsonArrayBuilderImpl(collection, bufferPool); - } - - @Override - public JsonPointer createPointer(String jsonPointer) { - return new JsonPointerImpl(jsonPointer); - } - - @Override - public JsonPatchBuilder createPatchBuilder() { - return new JsonPatchBuilderImpl(); - } - - @Override - public JsonPatchBuilder createPatchBuilder(JsonArray array) { - return new JsonPatchBuilderImpl(array); - } - - @Override - public JsonPatch createPatch(JsonArray array) { - return new JsonPatchImpl(array); - } - - @Override - public JsonPatch createDiff(JsonStructure source, JsonStructure target) { - return new JsonPatchImpl(JsonPatchImpl.diff(source, target)); - } - - @Override - public JsonMergePatch createMergePatch(JsonValue patch) { - return new JsonMergePatchImpl(patch); - } - - @Override - public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) { - return new JsonMergePatchImpl(JsonMergePatchImpl.diff(source, target)); - } - - @Override - public JsonString createValue(String value) { - return new JsonStringImpl(value); - } - - @Override - public JsonNumber createValue(int value) { - return JsonNumberImpl.getJsonNumber(value); - } - - @Override - public JsonNumber createValue(long value) { - return JsonNumberImpl.getJsonNumber(value); - } - - @Override - public JsonNumber createValue(double value) { - return JsonNumberImpl.getJsonNumber(value); - } - - @Override - public JsonNumber createValue(BigInteger value) { - return JsonNumberImpl.getJsonNumber(value); - } - - @Override - public JsonNumber createValue(BigDecimal value) { - return JsonNumberImpl.getJsonNumber(value); - } - - @Override - public JsonBuilderFactory createBuilderFactory(Map config) { - BufferPool pool = bufferPool; - boolean rejectDuplicateKeys = false; - if (config != null) { - if (config.containsKey(BufferPool.class.getName())) { - pool = (BufferPool) config.get(BufferPool.class.getName()); - } - rejectDuplicateKeys = JsonProviderImpl.isRejectDuplicateKeysEnabled(config); - } - return new JsonBuilderFactoryImpl(pool, rejectDuplicateKeys); - } - - static boolean isPrettyPrintingEnabled(Map config) { - return config.containsKey(JsonGenerator.PRETTY_PRINTING); - } - - static boolean isRejectDuplicateKeysEnabled(Map config) { - return config.containsKey(JsonConfig.REJECT_DUPLICATE_KEYS); - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonReaderFactoryImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonReaderFactoryImpl.java deleted file mode 100644 index d55d07a7..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonReaderFactoryImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonReader; -import jakarta.json.JsonReaderFactory; -import java.io.InputStream; -import java.io.Reader; -import java.nio.charset.Charset; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonReaderFactoryImpl implements JsonReaderFactory { - private final Map config; - private final BufferPool bufferPool; - private final boolean rejectDuplicateKeys; - - JsonReaderFactoryImpl(Map config, BufferPool bufferPool, boolean rejectDuplicateKeys) { - this.config = config; - this.bufferPool = bufferPool; - this.rejectDuplicateKeys = rejectDuplicateKeys; - } - - @Override - public JsonReader createReader(Reader reader) { - return new JsonReaderImpl(reader, bufferPool, rejectDuplicateKeys); - } - - @Override - public JsonReader createReader(InputStream in) { - return new JsonReaderImpl(in, bufferPool, rejectDuplicateKeys); - } - - @Override - public JsonReader createReader(InputStream in, Charset charset) { - return new JsonReaderImpl(in, charset, bufferPool, rejectDuplicateKeys); - } - - @Override - public Map getConfigInUse() { - return config; - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonReaderImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonReaderImpl.java deleted file mode 100644 index b8300346..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonReaderImpl.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import java.io.InputStream; -import java.io.Reader; -import java.nio.charset.Charset; -import jakarta.json.JsonArray; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParsingException; - -/** - * JsonReader impl using parser and builders. - * - * @author Jitendra Kotamraju - */ -class JsonReaderImpl implements JsonReader { - private final JsonParserImpl parser; - private boolean readDone; - private final BufferPool bufferPool; - - JsonReaderImpl(Reader reader, BufferPool bufferPool) { - this(reader, bufferPool, false); - } - - JsonReaderImpl(Reader reader, BufferPool bufferPool, boolean rejectDuplicateKeys) { - parser = new JsonParserImpl(reader, bufferPool, rejectDuplicateKeys); - this.bufferPool = bufferPool; - } - - JsonReaderImpl(InputStream in, BufferPool bufferPool) { - this(in, bufferPool, false); - } - - JsonReaderImpl(InputStream in, BufferPool bufferPool, boolean rejectDuplicateKeys) { - parser = new JsonParserImpl(in, bufferPool, rejectDuplicateKeys); - this.bufferPool = bufferPool; - } - - JsonReaderImpl(InputStream in, Charset charset, BufferPool bufferPool) { - this(in, charset, bufferPool, false); - } - - JsonReaderImpl(InputStream in, Charset charset, BufferPool bufferPool, boolean rejectDuplicateKeys) { - parser = new JsonParserImpl(in, charset, bufferPool, rejectDuplicateKeys); - this.bufferPool = bufferPool; - } - - @Override - public JsonStructure read() { - if (readDone) { - throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED()); - } - readDone = true; - if (parser.hasNext()) { - try { - JsonParser.Event e = parser.next(); - if (e == JsonParser.Event.START_ARRAY) { - return parser.getArray(); - } else if (e == JsonParser.Event.START_OBJECT) { - return parser.getObject(); - } - } catch (IllegalStateException ise) { - throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation()); - } - } - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - - @Override - public JsonObject readObject() { - if (readDone) { - throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED()); - } - readDone = true; - if (parser.hasNext()) { - try { - parser.next(); - return parser.getObject(); - } catch (IllegalStateException ise) { - throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation()); - } - } - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - - @Override - public JsonArray readArray() { - if (readDone) { - throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED()); - } - readDone = true; - if (parser.hasNext()) { - try { - parser.next(); - return parser.getArray(); - } catch (IllegalStateException ise) { - throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation()); - } - } - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - - @Override - public JsonValue readValue() { - if (readDone) { - throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED()); - } - readDone = true; - if (parser.hasNext()) { - try { - parser.next(); - return parser.getValue(); - } catch (IllegalStateException ise) { - throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation()); - } - } - throw new JsonException(JsonMessages.INTERNAL_ERROR()); - } - - @Override - public void close() { - readDone = true; - parser.close(); - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonStringImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonStringImpl.java deleted file mode 100644 index d75ae86d..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonStringImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonString; - -/** - * JsonString impl - * - * @author Jitendra Kotamraju - */ -final class JsonStringImpl implements JsonString { - - private final CharSequence value; - - JsonStringImpl(CharSequence value) { - this.value = value; - } - - @Override - public String getString() { - return value.toString(); - } - - @Override - public CharSequence getChars() { - return value; - } - - @Override - public ValueType getValueType() { - return ValueType.STRING; - } - - @Override - public int hashCode() { - return getString().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj){ - return true; - } - if (!(obj instanceof JsonString)) { - return false; - } - JsonString other = (JsonString)obj; - return getString().equals(other.getString()); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append('"'); - - for(int i = 0; i < value.length(); i++) { - char c = value.charAt(i); - // unescaped = %x20-21 | %x23-5B | %x5D-10FFFF - if (c >= 0x20 && c <= 0x10ffff && c != 0x22 && c != 0x5c) { - sb.append(c); - } else { - switch (c) { - case '"': - case '\\': - sb.append('\\'); sb.append(c); - break; - case '\b': - sb.append('\\'); sb.append('b'); - break; - case '\f': - sb.append('\\'); sb.append('f'); - break; - case '\n': - sb.append('\\'); sb.append('n'); - break; - case '\r': - sb.append('\\'); sb.append('r'); - break; - case '\t': - sb.append('\\'); sb.append('t'); - break; - default: - String hex = "000" + Integer.toHexString(c); - sb.append("\\u").append(hex.substring(hex.length() - 4)); - } - } - } - - sb.append('"'); - return sb.toString(); - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonStructureParser.java b/impl/src/main/java/org/eclipse/jsonp/JsonStructureParser.java deleted file mode 100644 index 1d5a414f..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonStructureParser.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.*; -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import java.math.BigDecimal; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; - -/** - * {@link JsonParser} implementation on top of JsonArray/JsonObject - * - * @author Jitendra Kotamraju - */ -class JsonStructureParser implements JsonParser { - - private Scope current; - private Event state; - private final Deque scopeStack = new ArrayDeque<>(); - - JsonStructureParser(JsonArray array) { - current = new ArrayScope(array); - } - - JsonStructureParser(JsonObject object) { - current = new ObjectScope(object); - } - - @Override - public String getString() { - switch (state) { - case KEY_NAME: - return ((ObjectScope)current).key; - case VALUE_STRING: - return ((JsonString)current.getJsonValue()).getString(); - case VALUE_NUMBER: - return ((JsonNumber)current.getJsonValue()).toString(); - default: - throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(state)); - } - } - - @Override - public boolean isIntegralNumber() { - if (state == Event.VALUE_NUMBER) { - return ((JsonNumber)current.getJsonValue()).isIntegral(); - } - throw new IllegalStateException(JsonMessages.PARSER_ISINTEGRALNUMBER_ERR(state)); - } - - @Override - public int getInt() { - if (state == Event.VALUE_NUMBER) { - return ((JsonNumber)current.getJsonValue()).intValue(); - } - throw new IllegalStateException(JsonMessages.PARSER_GETINT_ERR(state)); - } - - @Override - public long getLong() { - if (state == Event.VALUE_NUMBER) { - return ((JsonNumber)current.getJsonValue()).longValue(); - } - throw new IllegalStateException(JsonMessages.PARSER_GETLONG_ERR(state)); - } - - @Override - public BigDecimal getBigDecimal() { - if (state == Event.VALUE_NUMBER) { - return ((JsonNumber)current.getJsonValue()).bigDecimalValue(); - } - throw new IllegalStateException(JsonMessages.PARSER_GETBIGDECIMAL_ERR(state)); - } - - @Override - public JsonLocation getLocation() { - return JsonLocationImpl.UNKNOWN; - } - - @Override - public boolean hasNext() { - return !((state == Event.END_OBJECT || state == Event.END_ARRAY) && scopeStack.isEmpty()); - } - - @Override - public Event next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - transition(); - return state; - } - - private void transition() { - if (state == null) { - state = current instanceof ArrayScope ? Event.START_ARRAY : Event.START_OBJECT; - } else { - if (state == Event.END_OBJECT || state == Event.END_ARRAY) { - current = scopeStack.pop(); - } - if (current instanceof ArrayScope) { - if (current.hasNext()) { - current.next(); - state = getState(current.getJsonValue()); - if (state == Event.START_ARRAY || state == Event.START_OBJECT) { - scopeStack.push(current); - current = Scope.createScope(current.getJsonValue()); - } - } else { - state = Event.END_ARRAY; - } - } else { - // ObjectScope - if (state == Event.KEY_NAME) { - state = getState(current.getJsonValue()); - if (state == Event.START_ARRAY || state == Event.START_OBJECT) { - scopeStack.push(current); - current = Scope.createScope(current.getJsonValue()); - } - } else { - if (current.hasNext()) { - current.next(); - state = Event.KEY_NAME; - } else { - state = Event.END_OBJECT; - } - } - } - } - } - - @Override - public void close() { - // no-op - } - - @Override - public void skipObject() { - if (current instanceof ObjectScope) { - int depth = 1; - do { - if (state == Event.KEY_NAME) { - state = getState(current.getJsonValue()); - switch (state) { - case START_OBJECT: - depth++; - break; - case END_OBJECT: - depth--; - break; - default: - //no-op - } - } else { - if (current.hasNext()) { - current.next(); - state = Event.KEY_NAME; - } else { - state = Event.END_OBJECT; - depth--; - } - } - } while (state != Event.END_OBJECT && depth > 0); - } - } - - @Override - public void skipArray() { - if (current instanceof ArrayScope) { - int depth = 1; - do { - if (current.hasNext()) { - current.next(); - state = getState(current.getJsonValue()); - switch (state) { - case START_ARRAY: - depth++; - break; - case END_ARRAY: - depth--; - break; - default: - //no-op - } - } else { - state = Event.END_ARRAY; - depth--; - } - } while (!(state == Event.END_ARRAY && depth == 0)); - } - } - - private static Event getState(JsonValue value) { - switch (value.getValueType()) { - case ARRAY: - return Event.START_ARRAY; - case OBJECT: - return Event.START_OBJECT; - case STRING: - return Event.VALUE_STRING; - case NUMBER: - return Event.VALUE_NUMBER; - case TRUE: - return Event.VALUE_TRUE; - case FALSE: - return Event.VALUE_FALSE; - case NULL: - return Event.VALUE_NULL; - default: - throw new JsonException(JsonMessages.PARSER_STATE_ERR(value.getValueType())); - } - } - - private static abstract class Scope implements Iterator { - abstract JsonValue getJsonValue(); - - static Scope createScope(JsonValue value) { - if (value instanceof JsonArray) { - return new ArrayScope((JsonArray)value); - } else if (value instanceof JsonObject) { - return new ObjectScope((JsonObject)value); - } - throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value)); - } - } - - private static class ArrayScope extends Scope { - private final Iterator it; - private JsonValue value; - - ArrayScope(JsonArray array) { - this.it = array.iterator(); - } - - @Override - public boolean hasNext() { - return it.hasNext(); - } - - @Override - public JsonValue next() { - value = it.next(); - return value; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - JsonValue getJsonValue() { - return value; - } - - } - - private static class ObjectScope extends Scope { - private final Iterator> it; - private JsonValue value; - private String key; - - ObjectScope(JsonObject object) { - this.it = object.entrySet().iterator(); - } - - @Override - public boolean hasNext() { - return it.hasNext(); - } - - @Override - public Map.Entry next() { - Map.Entry next = it.next(); - this.key = next.getKey(); - this.value = next.getValue(); - return next; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - JsonValue getJsonValue() { - return value; - } - - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonTokenizer.java b/impl/src/main/java/org/eclipse/jsonp/JsonTokenizer.java deleted file mode 100644 index c1b980d9..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonTokenizer.java +++ /dev/null @@ -1,593 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonException; -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParsingException; -import java.io.Closeable; -import java.io.IOException; -import java.io.Reader; -import java.math.BigDecimal; -import java.util.Arrays; - -import jakarta.json.stream.JsonParser.Event; - -/** - * JSON Tokenizer - * - * @author Jitendra Kotamraju - */ -final class JsonTokenizer implements Closeable { - // Table to look up hex ch -> value (for e.g HEX['F'] = 15, HEX['5'] = 5) - private final static int[] HEX = new int[128]; - static { - Arrays.fill(HEX, -1); - for (int i='0'; i <= '9'; i++) { - HEX[i] = i-'0'; - } - for (int i='A'; i <= 'F'; i++) { - HEX[i] = 10+i-'A'; - } - for (int i='a'; i <= 'f'; i++) { - HEX[i] = 10+i-'a'; - } - } - private final static int HEX_LENGTH = HEX.length; - - private final BufferPool bufferPool; - - private final Reader reader; - - // Internal buffer that is used for parsing. It is also used - // for storing current string and number value token - private char[] buf; - - // Indexes in buffer - // - // XXXssssssssssssXXXXXXXXXXXXXXXXXXXXXXrrrrrrrrrrrrrrXXXXXX - // ^ ^ ^ ^ - // | | | | - // storeBegin storeEnd readBegin readEnd - private int readBegin; - private int readEnd; - private int storeBegin; - private int storeEnd; - - // line number of the current pointer of parsing char - private long lineNo = 1; - - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // ^ - // | - // bufferOffset - // - // offset of the last \r\n or \n. will be used to calculate column number - // of a token or an error. This may be outside of the buffer. - private long lastLineOffset = 0; - // offset in the stream for the start of the buffer, will be used in - // calculating JsonLocation's stream offset, column no. - private long bufferOffset = 0; - - private boolean minus; - private boolean fracOrExp; - private BigDecimal bd; - - enum JsonToken { - CURLYOPEN(Event.START_OBJECT, false), - SQUAREOPEN(Event.START_ARRAY, false), - COLON(null, false), - COMMA(null, false), - STRING(Event.VALUE_STRING, true), - NUMBER(Event.VALUE_NUMBER, true), - TRUE(Event.VALUE_TRUE, true), - FALSE(Event.VALUE_FALSE, true), - NULL(Event.VALUE_NULL, true), - CURLYCLOSE(Event.END_OBJECT, false), - SQUARECLOSE(Event.END_ARRAY, false), - EOF(null, false); - - private final JsonParser.Event event; - private final boolean value; - - JsonToken(JsonParser.Event event, boolean value) { - this.event = event; - this.value = value; - } - - JsonParser.Event getEvent() { - return event; - } - - boolean isValue() { - return value; - } - } - - JsonTokenizer(Reader reader, BufferPool bufferPool) { - this.reader = reader; - this.bufferPool = bufferPool; - buf = bufferPool.take(); - } - - private void readString() { - // when inPlace is true, no need to copy chars - boolean inPlace = true; - storeBegin = storeEnd = readBegin; - - do { - // Write unescaped char block within the current buffer - if (inPlace) { - int ch; - while(readBegin < readEnd && ((ch=buf[readBegin]) >= 0x20) && ch != '\\') { - if (ch == '"') { - storeEnd = readBegin++; // ++ to consume quote char - return; // Got the entire string - } - readBegin++; // consume unescaped char - } - storeEnd = readBegin; - } - - // string may be crossing buffer boundaries and may contain - // escaped characters. - int ch = read(); - if (ch >= 0x20 && ch != 0x22 && ch != 0x5c) { - if (!inPlace) { - buf[storeEnd] = (char)ch; - } - storeEnd++; - continue; - } - switch (ch) { - case '\\': - inPlace = false; // Now onwards need to copy chars - unescape(); - break; - case '"': - return; - default: - throw unexpectedChar(ch); - } - } while (true); - } - - private void unescape() { - int ch = read(); - switch (ch) { - case 'b': - buf[storeEnd++] = '\b'; - break; - case 't': - buf[storeEnd++] = '\t'; - break; - case 'n': - buf[storeEnd++] = '\n'; - break; - case 'f': - buf[storeEnd++] = '\f'; - break; - case 'r': - buf[storeEnd++] = '\r'; - break; - case '"': - case '\\': - case '/': - buf[storeEnd++] = (char)ch; - break; - case 'u': { - int unicode = 0; - for (int i = 0; i < 4; i++) { - int ch3 = read(); - int digit = (ch3 >= 0 && ch3 < HEX_LENGTH) ? HEX[ch3] : -1; - if (digit < 0) { - throw unexpectedChar(ch3); - } - unicode = (unicode << 4)|digit; - } - buf[storeEnd++] = (char)unicode; - break; - } - default: - throw unexpectedChar(ch); - } - } - - // Reads a number char. If the char is within the buffer, directly - // reads from the buffer. Otherwise, uses read() which takes care - // of resizing, filling up the buf, adjusting the pointers - private int readNumberChar() { - if (readBegin < readEnd) { - return buf[readBegin++]; - } else { - storeEnd = readBegin; - return read(); - } - } - - private void readNumber(int ch) { - storeBegin = storeEnd = readBegin-1; - // sign - if (ch == '-') { - this.minus = true; - ch = readNumberChar(); - if (ch < '0' || ch >'9') { - throw unexpectedChar(ch); - } - } - - // int - if (ch == '0') { - ch = readNumberChar(); - } else { - do { - ch = readNumberChar(); - } while (ch >= '0' && ch <= '9'); - } - - // frac - if (ch == '.') { - this.fracOrExp = true; - int count = 0; - do { - ch = readNumberChar(); - count++; - } while (ch >= '0' && ch <= '9'); - if (count == 1) { - throw unexpectedChar(ch); - } - } - - // exp - if (ch == 'e' || ch == 'E') { - this.fracOrExp = true; - ch = readNumberChar(); - if (ch == '+' || ch == '-') { - ch = readNumberChar(); - } - int count; - for (count = 0; ch >= '0' && ch <= '9'; count++) { - ch = readNumberChar(); - } - if (count == 0) { - throw unexpectedChar(ch); - } - } - if (ch != -1) { - // Only reset readBegin if eof has not been reached - readBegin--; - storeEnd = readBegin; - } - } - - private void readTrue() { - int ch1 = read(); - if (ch1 != 'r') { - throw expectedChar(ch1, 'r'); - } - int ch2 = read(); - if (ch2 != 'u') { - throw expectedChar(ch2, 'u'); - } - int ch3 = read(); - if (ch3 != 'e') { - throw expectedChar(ch3, 'e'); - } - } - - private void readFalse() { - int ch1 = read(); - if (ch1 != 'a') { - throw expectedChar(ch1, 'a'); - } - int ch2 = read(); - if (ch2 != 'l') { - throw expectedChar(ch2, 'l'); - } - int ch3 = read(); - if (ch3 != 's') { - throw expectedChar(ch3, 's'); - } - int ch4 = read(); - if (ch4 != 'e') { - throw expectedChar(ch4, 'e'); - } - } - - private void readNull() { - int ch1 = read(); - if (ch1 != 'u') { - throw expectedChar(ch1, 'u'); - } - int ch2 = read(); - if (ch2 != 'l') { - throw expectedChar(ch2, 'l'); - } - int ch3 = read(); - if (ch3 != 'l') { - throw expectedChar(ch3, 'l'); - } - } - - /* - * Could be optimized if the parser uses separate methods to match colon - * etc (that would avoid the switch statement cost in certain cases) - */ - JsonToken nextToken() { - reset(); - int ch = read(); - - // whitespace - while (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0d) { - if (ch == '\r') { - ++lineNo; - ch = read(); - if (ch == '\n') { - lastLineOffset = bufferOffset+readBegin; - } else { - lastLineOffset = bufferOffset+readBegin-1; - continue; - } - } else if (ch == '\n') { - ++lineNo; - lastLineOffset = bufferOffset+readBegin; - } - ch = read(); - } - - switch (ch) { - case '"': - readString(); - return JsonToken.STRING; - case '{': - return JsonToken.CURLYOPEN; - case '[': - return JsonToken.SQUAREOPEN; - case ':': - return JsonToken.COLON; - case ',': - return JsonToken.COMMA; - case 't': - readTrue(); - return JsonToken.TRUE; - case 'f': - readFalse(); - return JsonToken.FALSE; - case 'n': - readNull(); - return JsonToken.NULL; - case ']': - return JsonToken.SQUARECLOSE; - case '}': - return JsonToken.CURLYCLOSE; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - readNumber(ch); - return JsonToken.NUMBER; - case -1: - return JsonToken.EOF; - default: - throw unexpectedChar(ch); - } - } - - boolean hasNextToken() { - reset(); - int ch = peek(); - - // whitespace - while (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0d) { - if (ch == '\r') { - ++lineNo; - ++readBegin; - ch = peek(); - if (ch == '\n') { - lastLineOffset = bufferOffset+readBegin+1; - } else { - lastLineOffset = bufferOffset+readBegin; - continue; - } - } else if (ch == '\n') { - ++lineNo; - lastLineOffset = bufferOffset+readBegin+1; - } - ++readBegin; - ch = peek(); - } - return ch != -1; - } - - private int peek() { - try { - if (readBegin == readEnd) { // need to fill the buffer - int len = fillBuf(); - if (len == -1) { - return -1; - } - assert len != 0; - readBegin = storeEnd; - readEnd = readBegin+len; - } - return buf[readBegin]; - } catch (IOException ioe) { - throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe); - } - } - - // Gives the location of the last char. Used for - // JsonParsingException.getLocation - JsonLocation getLastCharLocation() { - // Already read the char, so subtracting -1 - return new JsonLocationImpl(lineNo, bufferOffset +readBegin-lastLineOffset, bufferOffset +readBegin-1); - } - - // Gives the parser location. Used for JsonParser.getLocation - JsonLocation getLocation() { - return new JsonLocationImpl(lineNo, bufferOffset +readBegin-lastLineOffset+1, bufferOffset +readBegin); - } - - private int read() { - try { - if (readBegin == readEnd) { // need to fill the buffer - int len = fillBuf(); - if (len == -1) { - return -1; - } - assert len != 0; - readBegin = storeEnd; - readEnd = readBegin+len; - } - return buf[readBegin++]; - } catch (IOException ioe) { - throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe); - } - } - - private int fillBuf() throws IOException { - if (storeEnd != 0) { - int storeLen = storeEnd-storeBegin; - if (storeLen > 0) { - // there is some store data - if (storeLen == buf.length) { - // buffer is full, double the capacity - char[] doubleBuf = Arrays.copyOf(buf, 2 * buf.length); - bufferPool.recycle(buf); - buf = doubleBuf; - } else { - // Left shift all the stored data to make space - System.arraycopy(buf, storeBegin, buf, 0, storeLen); - storeEnd = storeLen; - storeBegin = 0; - bufferOffset += readBegin-storeEnd; - } - } else { - storeBegin = storeEnd = 0; - bufferOffset += readBegin; - } - } else { - bufferOffset += readBegin; - } - // Fill the rest of the buf - return reader.read(buf, storeEnd, buf.length-storeEnd); - } - - // state associated with the current token is no more valid - private void reset() { - if (storeEnd != 0) { - storeBegin = 0; - storeEnd = 0; - bd = null; - minus = false; - fracOrExp = false; - } - } - - String getValue() { - return new String(buf, storeBegin, storeEnd-storeBegin); - } - - CharSequence getCharSequence() { - int len = storeEnd - storeBegin; - return new StringBuilder(len).append(buf, storeBegin, len); - } - - BigDecimal getBigDecimal() { - if (bd == null) { - bd = new BigDecimal(buf, storeBegin, storeEnd-storeBegin); - } - return bd; - } - - int getInt() { - // no need to create BigDecimal for common integer values (1-9 digits) - int storeLen = storeEnd-storeBegin; - if (!fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10))) { - int num = 0; - int i = minus ? 1 : 0; - for(; i < storeLen; i++) { - num = num * 10 + (buf[storeBegin+i] - '0'); - } - return minus ? -num : num; - } else { - return getBigDecimal().intValue(); - } - } - - long getLong() { - // no need to create BigDecimal for common integer values (1-18 digits) - int storeLen = storeEnd-storeBegin; - if (!fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19))) { - long num = 0; - int i = minus ? 1 : 0; - for(; i < storeLen; i++) { - num = num * 10 + (buf[storeBegin+i] - '0'); - } - return minus ? -num : num; - } else { - return getBigDecimal().longValue(); - } - } - - // returns true for common integer values (1-9 digits). - // So there are cases it will return false even though the number is int - boolean isDefinitelyInt() { - int storeLen = storeEnd-storeBegin; - return !fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10)); - } - - // returns true for common long values (1-18 digits). - // So there are cases it will return false even though the number is long - boolean isDefinitelyLong() { - int storeLen = storeEnd-storeBegin; - return !fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19)); - } - - boolean isIntegral() { - return !fracOrExp || getBigDecimal().scale() == 0; - } - - @Override - public void close() throws IOException { - reader.close(); - bufferPool.recycle(buf); - } - - private JsonParsingException unexpectedChar(int ch) { - JsonLocation location = getLastCharLocation(); - return new JsonParsingException( - JsonMessages.TOKENIZER_UNEXPECTED_CHAR(ch, location), location); - } - - private JsonParsingException expectedChar(int unexpected, char expected) { - JsonLocation location = getLastCharLocation(); - return new JsonParsingException( - JsonMessages.TOKENIZER_EXPECTED_CHAR(unexpected, location, expected), location); - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonUtil.java b/impl/src/main/java/org/eclipse/jsonp/JsonUtil.java deleted file mode 100644 index 1ca9f2f8..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import java.io.StringReader; -import jakarta.json.JsonReader; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonParsingException; -import org.eclipse.jsonp.api.BufferPool; - -/** - * A utility class - * - * @since 1.1 - */ -public final class JsonUtil { - - private static BufferPool internalPool; - - private JsonUtil() { - } - - static BufferPool getInternalBufferPool() { - if (internalPool == null) { - internalPool = new BufferPoolImpl(); - } - return internalPool; - } - - /** - * Reads the input JSON text and returns a JsonValue. - *

For convenience, single quotes as well as double quotes - * are allowed to delimit JSON strings. If single quotes are - * used, any quotes, single or double, in the JSON string must be - * escaped (prepend with a '\'). - * - * @param jsonString the input JSON data - * @return the object model for {@code jsonString} - * @throws JsonParsingException if the input is not legal JSON text - */ - public static JsonValue toJson(String jsonString) { - StringBuilder builder = new StringBuilder(); - boolean single_context = false; - for (int i = 0; i < jsonString.length(); i++) { - char ch = jsonString.charAt(i); - if (ch == '\\') { - i = i + 1; - if (i < jsonString.length()) { - ch = jsonString.charAt(i); - if (!(single_context && ch == '\'')) { - // unescape ' inside single quotes - builder.append('\\'); - } - } - } else if (ch == '\'') { - // Turn ' into ", for proper JSON string - ch = '"'; - single_context = ! single_context; - } - builder.append(ch); - } - - JsonReader reader = new JsonReaderImpl( - new StringReader(builder.toString()), - getInternalBufferPool()); - JsonValue value = reader.readValue(); - reader.close(); - return value; - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonWriterFactoryImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonWriterFactoryImpl.java deleted file mode 100644 index f48f2d46..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonWriterFactoryImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonWriter; -import jakarta.json.JsonWriterFactory; -import java.io.OutputStream; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -class JsonWriterFactoryImpl implements JsonWriterFactory { - private final Map config; // unmodifiable map - private final boolean prettyPrinting; - private final BufferPool bufferPool; - - JsonWriterFactoryImpl(Map config, boolean prettyPrinting, - BufferPool bufferPool) { - this.config = config; - this.prettyPrinting = prettyPrinting; - this.bufferPool = bufferPool; - } - - @Override - public JsonWriter createWriter(Writer writer) { - return new JsonWriterImpl(writer, prettyPrinting, bufferPool); - } - - @Override - public JsonWriter createWriter(OutputStream out) { - return new JsonWriterImpl(out, prettyPrinting, bufferPool); - } - - @Override - public JsonWriter createWriter(OutputStream out, Charset charset) { - return new JsonWriterImpl(out, charset, prettyPrinting, bufferPool); - } - - @Override - public Map getConfigInUse() { - return config; - } -} diff --git a/impl/src/main/java/org/eclipse/jsonp/JsonWriterImpl.java b/impl/src/main/java/org/eclipse/jsonp/JsonWriterImpl.java deleted file mode 100644 index b8db100b..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/JsonWriterImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.*; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Map; - -/** - * JsonWriter impl using generator. - * - * @author Jitendra Kotamraju - */ -class JsonWriterImpl implements JsonWriter { - - private final JsonGeneratorImpl generator; - private boolean writeDone; - private final NoFlushOutputStream os; - - JsonWriterImpl(Writer writer, BufferPool bufferPool) { - this(writer, false, bufferPool); - } - - JsonWriterImpl(Writer writer, boolean prettyPrinting, BufferPool bufferPool) { - generator = prettyPrinting - ? new JsonPrettyGeneratorImpl(writer, bufferPool) - : new JsonGeneratorImpl(writer, bufferPool); - os = null; - } - - JsonWriterImpl(OutputStream out, BufferPool bufferPool) { - this(out, StandardCharsets.UTF_8, false, bufferPool); - } - - JsonWriterImpl(OutputStream out, boolean prettyPrinting, BufferPool bufferPool) { - this(out, StandardCharsets.UTF_8, prettyPrinting, bufferPool); - } - - JsonWriterImpl(OutputStream out, Charset charset, - boolean prettyPrinting, BufferPool bufferPool) { - // Decorating the given stream, so that buffered contents can be - // written without actually flushing the stream. - this.os = new NoFlushOutputStream(out); - generator = prettyPrinting - ? new JsonPrettyGeneratorImpl(os, charset, bufferPool) - : new JsonGeneratorImpl(os, charset, bufferPool); - } - - @Override - public void writeArray(JsonArray array) { - if (writeDone) { - throw new IllegalStateException(JsonMessages.WRITER_WRITE_ALREADY_CALLED()); - } - writeDone = true; - generator.writeStartArray(); - for(JsonValue value : array) { - generator.write(value); - } - generator.writeEnd(); - // Flush the generator's buffered contents. This won't work for byte - // streams as intermediary OutputStreamWriter buffers. - generator.flushBuffer(); - // Flush buffered contents but not the byte stream. generator.flush() - // does OutputStreamWriter#flushBuffer (package private) and underlying - // byte stream#flush(). Here underlying stream's flush() is no-op. - if (os != null) { - generator.flush(); - } - } - - @Override - public void writeObject(JsonObject object) { - if (writeDone) { - throw new IllegalStateException(JsonMessages.WRITER_WRITE_ALREADY_CALLED()); - } - writeDone = true; - generator.writeStartObject(); - for(Map.Entry e : object.entrySet()) { - generator.write(e.getKey(), e.getValue()); - } - generator.writeEnd(); - // Flush the generator's buffered contents. This won't work for byte - // streams as intermediary OutputStreamWriter buffers. - generator.flushBuffer(); - // Flush buffered contents but not the byte stream. generator.flush() - // does OutputStreamWriter#flushBuffer (package private) and underlying - // byte stream#flush(). Here underlying stream's flush() is no-op. - if (os != null) { - generator.flush(); - } - } - - @Override - public void write(JsonStructure value) { - if (value instanceof JsonArray) { - writeArray((JsonArray)value); - } else { - writeObject((JsonObject)value); - } - } - - @Override - public void write(JsonValue value) { - switch (value.getValueType()) { - case OBJECT: - writeObject((JsonObject) value); - return; - case ARRAY: - writeArray((JsonArray) value); - return; - default: - if (writeDone) { - throw new IllegalStateException(JsonMessages.WRITER_WRITE_ALREADY_CALLED()); - } - writeDone = true; - generator.write(value); - generator.flushBuffer(); - if (os != null) { - generator.flush(); - } - } - } - - @Override - public void close() { - writeDone = true; - generator.close(); - } - - private static final class NoFlushOutputStream extends FilterOutputStream { - public NoFlushOutputStream(OutputStream out) { - super(out); - } - - @Override - public void write(byte b[], int off, int len) throws IOException { - out.write(b, off ,len); - } - - @Override - public void flush() { - // no-op - } - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/MapUtil.java b/impl/src/main/java/org/eclipse/jsonp/MapUtil.java deleted file mode 100644 index 640a52a9..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/MapUtil.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Collection; -import java.util.Map; - -/** - * Util for transforming a Map to a Json objects. - * - * @author asotobu - */ -public final class MapUtil { - - private MapUtil() { - super(); - } - - static JsonValue handle(Object value, BufferPool bufferPool) { - if (value == null) { - return JsonValue.NULL; - } else if (value instanceof JsonValue) { - return (JsonValue) value; - } else if (value instanceof JsonArrayBuilder) { - return ((JsonArrayBuilder) value).build(); - } else if (value instanceof JsonObjectBuilder) { - return ((JsonObjectBuilder) value).build(); - } else if (value instanceof BigDecimal) { - return JsonNumberImpl.getJsonNumber((BigDecimal) value); - } else if (value instanceof BigInteger) { - return JsonNumberImpl.getJsonNumber((BigInteger) value); - } else if (value instanceof Boolean) { - Boolean b = (Boolean) value; - return b ? JsonValue.TRUE : JsonValue.FALSE; - } else if (value instanceof Double) { - return JsonNumberImpl.getJsonNumber((Double) value); - } else if (value instanceof Integer) { - return JsonNumberImpl.getJsonNumber((Integer) value); - } else if (value instanceof Long) { - return JsonNumberImpl.getJsonNumber((Long) value); - } else if (value instanceof String) { - return new JsonStringImpl((String) value); - } else if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection collection = (Collection) value; - JsonArrayBuilder jsonArrayBuilder = new JsonArrayBuilderImpl(collection, bufferPool); - return jsonArrayBuilder.build(); - } else if (value instanceof Map) { - @SuppressWarnings("unchecked") - JsonObjectBuilder object = new JsonObjectBuilderImpl((Map) value, bufferPool); - return object.build(); - } - - throw new IllegalArgumentException(String.format("Type %s is not supported.", value.getClass())); - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/NodeReference.java b/impl/src/main/java/org/eclipse/jsonp/NodeReference.java deleted file mode 100644 index 992bcff5..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/NodeReference.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -/** - * This class is a helper class for JsonPointer implementation, - * and is not part of the API. - * - * This class encapsulates a reference to a JSON node. - * There are three types of references. - *

  1. a reference to the root of a JSON tree.
  2. - *
  3. a reference to a name/value (possibly non-existing) pair of a JSON object, identified by a name.
  4. - *
  5. a reference to a member value of a JSON array, identified by an index.
  6. - *
- * Static factory methods are provided for creating these references. - * - *

A referenced value can be retrieved or replaced. - * The value of a JSON object or JSON array can be - * removed. A new value can be added to a JSON object or - * inserted into a JSON array

- * - *

Since a {@code JsonObject} or {@code JsonArray} is immutable, these operations - * must not modify the referenced JSON object or array. The methods {@link #add}, - * {@link #replace}, and {@link #remove} returns a new - * JSON object or array after the execution of the operation.

- */ -abstract class NodeReference { - - /** - * Return {@code true} if a reference points to a valid value, {@code false} otherwise. - * - * @return {@code true} if a reference points to a value - */ - abstract public boolean contains(); - - /** - * Get the value at the referenced location. - * - * @return the JSON value referenced - * @throws JsonException if the referenced value does not exist - */ - abstract public JsonValue get(); - - /** - * Add or replace a value at the referenced location. - * If the reference is the root of a JSON tree, the added value must be - * a JSON object or array, which becomes the referenced JSON value. - * If the reference is an index of a JSON array, the value is inserted - * into the array at the index. If the index is -1, the value is - * appended to the array. - * If the reference is a name of a JSON object, the name/value pair is added - * to the object, replacing any pair with the same name. - * - * @param value the value to be added - * @return the JsonStructure after the operation - * @throws JsonException if the index to the array is not -1 or is out of range - */ - abstract public JsonStructure add(JsonValue value); - - /** - * Remove the name/value pair from the JSON object, or the value in a JSON array, as specified by the reference - * - * @return the JsonStructure after the operation - * @throws JsonException if the name/value pair of the referenced JSON object - * does not exist, or if the index of the referenced JSON array is - * out of range, or if the reference is a root reference - */ - abstract public JsonStructure remove(); - - /** - * Replace the referenced value with the specified value. - * - * @param value the JSON value to be stored at the referenced location - * @return the JsonStructure after the operation - * @throws JsonException if the name/value pair of the referenced JSON object - * does not exist, or if the index of the referenced JSON array is - * out of range, or if the reference is a root reference - */ - abstract public JsonStructure replace(JsonValue value); - - /** - * Returns a {@code NodeReference} for a {@code JsonStructure}. - * - * @param structure the {@code JsonStructure} referenced - * @return the {@code NodeReference} - */ - public static NodeReference of(JsonStructure structure) { - return new RootReference(structure); - } - - /** - * Returns a {@code NodeReference} for a name/value pair in a - * JSON object. - * - * @param object the referenced JSON object - * @param name the name of the name/pair - * @return the {@code NodeReference} - */ - public static NodeReference of(JsonObject object, String name) { - return new ObjectReference(object, name); - } - - /** - * Returns a {@code NodeReference} for a member value in a - * JSON array. - * - * @param array the referenced JSON array - * @param index the index of the member value in the JSON array - * @return the {@code NodeReference} - */ - public static NodeReference of(JsonArray array, int index) { - return new ArrayReference(array, index); - } - - static class RootReference extends NodeReference { - - private JsonStructure root; - - RootReference(JsonStructure root) { - this.root = root; - } - - @Override - public boolean contains() { - return root != null; - } - - @Override - public JsonValue get() { - return root; - } - - @Override - public JsonStructure add(JsonValue value) { - switch (value.getValueType() ) { - case OBJECT: - case ARRAY: - this.root = (JsonStructure) value; - break; - default: - throw new JsonException(JsonMessages.NODEREF_VALUE_ADD_ERR()); - } - return root; - } - - @Override - public JsonStructure remove() { - throw new JsonException(JsonMessages.NODEREF_VALUE_CANNOT_REMOVE()); - } - - @Override - public JsonStructure replace(JsonValue value) { - return add(value); - } - } - - static class ObjectReference extends NodeReference { - - private final JsonObject object; - private final String key; - - ObjectReference(JsonObject object, String key) { - this.object = object; - this.key = key; - } - - @Override - public boolean contains() { - return object != null && object.containsKey(key); - } - - @Override - public JsonValue get() { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key)); - } - return object.get(key); - } - - @Override - public JsonObject add(JsonValue value) { - return new JsonObjectBuilderImpl(object, JsonUtil.getInternalBufferPool()).add(key, value).build(); - } - - @Override - public JsonObject remove() { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key)); - } - return new JsonObjectBuilderImpl(object, JsonUtil.getInternalBufferPool()).remove(key).build(); - } - - @Override - public JsonObject replace(JsonValue value) { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key)); - } - return add(value); - } - } - - static class ArrayReference extends NodeReference { - - private final JsonArray array; - private final int index; // -1 means "-" in JSON Pointer - - ArrayReference(JsonArray array, int index) { - this.array = array; - this.index = index; - } - - @Override - public boolean contains() { - return array != null && index > -1 && index < array.size(); - } - - @Override - public JsonValue get() { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); - } - return array.get(index); - } - - @Override - public JsonArray add(JsonValue value) { - //TODO should we check for arrayoutofbounds? - // The spec seems to say index = array.size() is allowed. This is handled as append - JsonArrayBuilder builder = new JsonArrayBuilderImpl(this.array, JsonUtil.getInternalBufferPool()); - if (index == -1 || index == array.size()) { - builder.add(value); - } else { - if(index < array.size()) { - builder.add(index, value); - } else { - throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); - } - } - return builder.build(); - } - - @Override - public JsonArray remove() { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); - } - JsonArrayBuilder builder = new JsonArrayBuilderImpl(this.array, JsonUtil.getInternalBufferPool()); - return builder.remove(index).build(); - } - - @Override - public JsonArray replace(JsonValue value) { - if (!contains()) { - throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); - } - JsonArrayBuilder builder = new JsonArrayBuilderImpl(this.array, JsonUtil.getInternalBufferPool()); - return builder.set(index, value).build(); - } - } -} - diff --git a/impl/src/main/java/org/eclipse/jsonp/UnicodeDetectingInputStream.java b/impl/src/main/java/org/eclipse/jsonp/UnicodeDetectingInputStream.java deleted file mode 100644 index f722f34f..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/UnicodeDetectingInputStream.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp; - -import jakarta.json.JsonException; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/** - * A filter stream that detects the unicode encoding for the original - * stream - * - * @author Jitendra Kotamraju - */ -class UnicodeDetectingInputStream extends FilterInputStream { - - private static final Charset UTF_32LE = Charset.forName("UTF-32LE"); - private static final Charset UTF_32BE = Charset.forName("UTF-32BE"); - - private static final byte FF = (byte)0xFF; - private static final byte FE = (byte)0xFE; - private static final byte EF = (byte)0xEF; - private static final byte BB = (byte)0xBB; - private static final byte BF = (byte)0xBF; - private static final byte NUL = (byte)0x00; - - private final byte[] buf = new byte[4]; - private int bufLen; - private int curIndex; - private final Charset charset; - - UnicodeDetectingInputStream(InputStream is) { - super(is); - charset = detectEncoding(); - } - - Charset getCharset() { - return charset; - } - - private void fillBuf() { - int b1; - int b2; - int b3; - int b4; - - try { - b1 = in.read(); - if (b1 == -1) { - return; - } - - b2 = in.read(); - if (b2 == -1) { - bufLen = 1; - buf[0] = (byte)b1; - return; - } - - b3 = in.read(); - if (b3 == -1) { - bufLen = 2; - buf[0] = (byte)b1; - buf[1] = (byte)b2; - return; - } - - b4 = in.read(); - if (b4 == -1) { - bufLen = 3; - buf[0] = (byte)b1; - buf[1] = (byte)b2; - buf[2] = (byte)b3; - return; - } - bufLen = 4; - buf[0] = (byte)b1; - buf[1] = (byte)b2; - buf[2] = (byte)b3; - buf[3] = (byte)b4; - } catch (IOException ioe) { - throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_IOERR(), ioe); - } - } - - private Charset detectEncoding() { - fillBuf(); - if (bufLen < 2) { - throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_FAILED()); - } else if (bufLen == 4) { - // Use BOM to detect encoding - if (buf[0] == NUL && buf[1] == NUL && buf[2] == FE && buf[3] == FF) { - curIndex = 4; - return UTF_32BE; - } else if (buf[0] == FF && buf[1] == FE && buf[2] == NUL && buf[3] == NUL) { - curIndex = 4; - return UTF_32LE; - } else if (buf[0] == FE && buf[1] == FF) { - curIndex = 2; - return StandardCharsets.UTF_16BE; - } else if (buf[0] == FF && buf[1] == FE) { - curIndex = 2; - return StandardCharsets.UTF_16LE; - } else if (buf[0] == EF && buf[1] == BB && buf[2] == BF) { - curIndex = 3; - return StandardCharsets.UTF_8; - } - // No BOM, just use JSON RFC's encoding algo to auto-detect - if (buf[0] == NUL && buf[1] == NUL && buf[2] == NUL) { - return UTF_32BE; - } else if (buf[0] == NUL && buf[2] == NUL) { - return StandardCharsets.UTF_16BE; - } else if (buf[1] == NUL && buf[2] == NUL && buf[3] == NUL) { - return UTF_32LE; - } else if (buf[1] == NUL && buf[3] == NUL) { - return StandardCharsets.UTF_16LE; - } - } - return StandardCharsets.UTF_8; - } - - @Override - public int read() throws IOException { - if (curIndex < bufLen) { - return buf[curIndex++]; - } - return in.read(); - } - - @Override - public int read(byte b[], int off, int len) throws IOException { - if (curIndex < bufLen) { - if (len == 0) { - return 0; - } - if (off < 0 || len < 0 || len > b.length -off) { - throw new IndexOutOfBoundsException(); - } - int min = Math.min(bufLen-curIndex, len); - System.arraycopy(buf, curIndex, b, off, min); - curIndex += min; - return min; - } - return in.read(b, off, len); - } - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/api/BufferPool.java b/impl/src/main/java/org/eclipse/jsonp/api/BufferPool.java deleted file mode 100644 index 1950b93e..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/api/BufferPool.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.api; - -/** - * char[] pool that pool instances of char[] which are expensive to create. - * - * @author Jitendra Kotamraju - */ -public interface BufferPool { - - /** - * Gets a new char[] object from the pool. - * - *

- * If no object is available in the pool, this method creates a new one. - * - * @return - * always non-null. - */ - char[] take(); - - /** - * Returns an object back to the pool. - * - * @param buf object to return back to the pool - */ - void recycle(char[] buf); - -} diff --git a/impl/src/main/java/org/eclipse/jsonp/api/JsonConfig.java b/impl/src/main/java/org/eclipse/jsonp/api/JsonConfig.java deleted file mode 100644 index d2f16ae2..00000000 --- a/impl/src/main/java/org/eclipse/jsonp/api/JsonConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.api; - -public interface JsonConfig { - /** - * Configuration property to reject duplicate keys. The value of the property could be - * be anything. - */ - String REJECT_DUPLICATE_KEYS = "org.eclipse.jsonp.rejectDuplicateKeys"; -} diff --git a/impl/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider b/impl/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider deleted file mode 100644 index 4ff9d592..00000000 --- a/impl/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.jsonp.JsonProviderImpl diff --git a/impl/src/main/resources/org/eclipse/jsonp/messages.properties b/impl/src/main/resources/org/eclipse/jsonp/messages.properties deleted file mode 100644 index 1c693105..00000000 --- a/impl/src/main/resources/org/eclipse/jsonp/messages.properties +++ /dev/null @@ -1,92 +0,0 @@ -# -# Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0, which is available at -# http://www.eclipse.org/legal/epl-2.0. -# -# This Source Code may also be made available under the following Secondary -# Licenses when the conditions for such availability set forth in the -# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -# version 2 with the GNU Classpath Exception, which is available at -# https://www.gnu.org/software/classpath/license.html. -# -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -# - - - -internal.error=Internal Error - -parser.getString.err=JsonParser#getString() is valid only for KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. \ - But current parser state is {0} -parser.isIntegralNumber.err=JsonParser#isIntegralNumber() is valid only for VALUE_NUMBER parser state. \ - But current parser state is {0} -parser.getInt.err=JsonParser#getInt() is valid only for VALUE_NUMBER parser state. \ - But current parser state is {0} -parser.getLong.err=JsonParser#getLong() is valid only for VALUE_NUMBER parser state. \ - But current parser state is {0} -parser.getBigDecimal.err=JsonParser#getBigDecimal() is valid only for VALUE_NUMBER parser state. \ - But current parser state is {0} -parser.getArray.err=JsonParser#getArray() or JsonParser#getArrayStream() is valid only for START_ARRAY parser state. \ - But current parser state is {0} -parser.getObject.err=JsonParser#getObject() or JsonParser#getObjectStream() is valid only for START_OBJECT parser state. \ - But current parser state is {0} -parser.getValue.err=JsonParser#getValue() is valid only for START_ARRAY, START_OBJECT, KEY_NAME, VALUE_STRING, VALUE_NUMBER, VALUE_NULL, VALUE_FALSE, VALUE_TRUE parser states. \ - But current parser state is {0} -parser.getValueStream.err=JsonParser#getValueStream() the parser must not be in an array or object. \ - But current parser state is {0} -parser.expected.eof=Expected EOF token, but got {0} -parser.tokenizer.close.io=I/O error while closing JSON tokenizer -parser.invalid.token=Invalid token={0} at {1}. Expected tokens are: {2} -parser.state.err=Unknown value type {0} -parser.scope.err=Cannot be called for value {0} -parser.input.enc.detect.failed=Cannot auto-detect encoding, not enough chars -parser.input.enc.detect.ioerr=I/O error while auto-detecting the encoding of stream -parser.duplicate.key=Duplicate key ''{0}'' is not allowed - -generator.flush.io.err=I/O error while flushing generated JSON -generator.close.io.err=I/O error while closing JsonGenerator -generator.write.io.err=I/O error while writing in JsonGenerator -generator.illegal.method=Illegal method during JSON generation, \ - not valid in current context {0} -generator.double.infinite.nan=double value cannot be Infinite or NaN -generator.incomplete.json=Generating incomplete JSON -generator.illegal.multiple.text=Cannot generate more than one JSON text - -writer.write.already.called=write/writeObject/writeArray/close method is already called - -reader.read.already.called=read/readObject/readArray/close method is already called - -objbuilder.name.null=Name in JsonObject's name/value pair cannot be null -objbuilder.value.null=Value in JsonObject's name/value pair cannot be null -objbuilder.object.builder.null=Object builder that is used to create a value in JsonObject's name/value pair cannot be null -objbuilder.array.builder.null=Array builder that is used to create a value in JsonObject's name/value pair cannot be null - -arrbuilder.value.null=Cannot invoke add(null) while building JsonArray. -arrbuilder.object.builder.null=Object builder that is used to add a value to JSON array cannot be null -arrbuilder.array.builder.null=Array builder that is used to add a value to JSON array cannot be null -arrbuilder.valuelist.null=Index: {0}, Size: {1} - -tokenizer.unexpected.char=Unexpected char {0} at {1} -tokenizer.expected.char=Unexpected char {0} at {1}, expecting ''{2}'' -tokenizer.io.err=I/O error while parsing JSON - -pointer.format.invalid=A non-empty JSON Pointer must begin with a ''/'' -pointer.mapping.missing=The JSON Object ''{0}'' contains no mapping for the name ''{1}'' -pointer.reference.invalid=The reference value in a JSON Pointer must be a JSON Object or a JSON Array, was ''{0}'' -pointer.array.index.err=Array index format error, was ''{0}'' -pointer.array.index.illegal=Illegal integer format, was ''{0}'' - -noderef.value.add.err=The root value only allows adding a JSON object or array -noderef.value.cannot.remove=The JSON value at the root cannot be removed -noderef.object.missing=Non-existing name/value pair in the object for key {0} -noderef.array.index.err=An array item index is out of range. Index: {0}, Size: {1} - -patch.must.be.array=A JSON Patch must be an array of JSON Objects -patch.move.proper.prefix=The ''{0}'' path of the patch operation ''move'' is a proper prefix of the ''{1}'' path -patch.move.target.null=The ''{0}'' path of the patch operation ''move'' does not exist in target object -patch.test.failed=The JSON Patch operation ''test'' failed for path ''{0}'' and value ''{1}'' -patch.illegal.operation=Illegal value for the op member of the JSON Patch operation: ''{0}'' -patch.member.missing=The JSON Patch operation ''{0}'' must contain a ''{1}'' member -patch.operation.missing=The JSON Patch must contain ''op'' member diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonArrayTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonArrayTest.java deleted file mode 100644 index ea65e3b4..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonArrayTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Jitendra Kotamraju - */ -public class JsonArrayTest extends TestCase { - public JsonArrayTest(String testName) { - super(testName); - } - - public void testArrayEquals() throws Exception { - JsonArray expected = Json.createArrayBuilder() - .add(JsonValue.TRUE) - .add(JsonValue.FALSE) - .add(JsonValue.NULL) - .add(Integer.MAX_VALUE) - .add(Long.MAX_VALUE) - .add(Double.MAX_VALUE) - .add(Integer.MIN_VALUE) - .add(Long.MIN_VALUE) - .add(Double.MIN_VALUE) - .add(Json.createArrayBuilder().add("abc")) - .add(Json.createObjectBuilder().add("one", 1)) - .build(); - - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.writeArray(expected); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonArray actual = reader.readArray(); - reader.close(); - - assertEquals(expected, actual); - } - - public void testArrayEqualsUsingCollection() { - List list = new ArrayList<>(); - list.add(JsonValue.TRUE); - list.add(JsonValue.FALSE); - list.add(JsonValue.NULL); - list.add(Integer.MAX_VALUE); - list.add(Long.MAX_VALUE); - list.add(Double.MAX_VALUE); - list.add(Integer.MIN_VALUE); - list.add(Long.MIN_VALUE); - list.add(Double.MIN_VALUE); - list.add(Json.createArrayBuilder().add("abc")); - list.add(Json.createObjectBuilder().add("one", 1)); - - JsonArray expected = Json.createArrayBuilder(list).build(); - - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.writeArray(expected); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonArray actual = reader.readArray(); - reader.close(); - - assertEquals(expected, actual); - } - - public void testStringValue() throws Exception { - JsonArray array = Json.createArrayBuilder() - .add("John") - .build(); - assertEquals("John", array.getString(0)); - } - - public void testIntValue() throws Exception { - JsonArray array = Json.createArrayBuilder() - .add(20) - .build(); - assertEquals(20, array.getInt(0)); - } - - public void testAdd() { - JsonArray array = Json.createArrayBuilder().build(); - try { - array.add(JsonValue.FALSE); - fail("JsonArray#add() should throw UnsupportedOperationException"); - } catch(UnsupportedOperationException e) { - // Expected - } - } - - public void testRemove() { - JsonArray array = Json.createArrayBuilder().build(); - try { - array.remove(0); - fail("JsonArray#remove() should throw UnsupportedOperationException"); - } catch(UnsupportedOperationException e) { - // Expected - } - } - - public void testNumberView() throws Exception { - JsonArray array = Json.createArrayBuilder().add(20).add(10).build(); - - List numberList = array.getValuesAs(JsonNumber.class); - for(JsonNumber num : numberList) { - num.intValue(); - } - - assertEquals(20, array.getInt(0)); - assertEquals(10, array.getInt(1)); - } - - public void testArrayBuilderNpe() { - try { - JsonArray array = Json.createArrayBuilder().add((JsonValue)null).build(); - fail("JsonArrayBuilder#add(null) should throw NullPointerException"); - } catch(NullPointerException e) { - // Expected - } - } - - public void testHashCode() { - JsonArray array1 = Json.createArrayBuilder().add(1).add(2).add(3).build(); - assertTrue(array1.hashCode() == array1.hashCode()); //1st call compute hashCode, 2nd call returns cached value - - JsonArray array2 = Json.createArrayBuilder().add(1).add(2).add(3).build(); - assertTrue(array1.hashCode() == array2.hashCode()); - - JsonArray array3 = Json.createArrayBuilder().build(); //org.eclipse.jsonp.JsonArrayBuilderImpl.JsonArrayImpl - JsonArray array4 = JsonValue.EMPTY_JSON_ARRAY; //jakarta.json.EmptyArray - - assertTrue(array3.equals(array4)); - assertTrue(array3.hashCode() == array4.hashCode()); //equal instances have same hashCode - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderFactoryTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderFactoryTest.java deleted file mode 100644 index 1d5f44cf..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderFactoryTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import java.util.Map; -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import org.junit.Assert; -import org.junit.Test; - -/** - * - * @author lukas - */ -public class JsonBuilderFactoryTest { - - @Test - public void testArrayBuilder() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - Assert.assertNotNull(builderFactory.createArrayBuilder()); - } - - @Test(expected = NullPointerException.class) - public void testArrayBuilderNPE() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - builderFactory.createArrayBuilder(null); - } - - @Test - public void testArrayBuilderFromArray() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - JsonArrayBuilder builder = builderFactory.createArrayBuilder(JsonBuilderTest.buildPhone()); - Assert.assertEquals(JsonBuilderTest.buildPhone(), builder.build()); - } - - @Test - public void testObjectBuilder() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - Assert.assertNotNull(builderFactory.createObjectBuilder()); - } - - @Test(expected = NullPointerException.class) - public void testObjectBuilderNPE() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - builderFactory.createObjectBuilder((JsonObject) null); - } - - @Test(expected = NullPointerException.class) - public void testObjectBuilderNPE_map() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - builderFactory.createObjectBuilder((Map) null); - } - - @Test - public void testObjectBuilderFromObject() { - JsonBuilderFactory builderFactory = Json.createBuilderFactory(null); - JsonObjectBuilder builder = builderFactory.createObjectBuilder(JsonBuilderTest.buildPerson()); - Assert.assertEquals(JsonBuilderTest.buildPerson(), builder.build()); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderTest.java deleted file mode 100644 index 621fcef5..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonBuilderTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -/** - * @author Jitendra Kotamraju - */ -public class JsonBuilderTest extends TestCase { - public JsonBuilderTest(String testName) { - super(testName); - } - - public void testEmptyObject() throws Exception { - JsonObject empty = Json.createObjectBuilder() - .build(); - - JsonObjectTest.testEmpty(empty); - } - - public void testEmptyArray() throws Exception { - JsonArray empty = Json.createArrayBuilder() - .build(); - - assertTrue(empty.isEmpty()); - } - - public void testObject() throws Exception { - JsonObject person = buildPerson(); - JsonObjectTest.testPerson(person); - } - - public void testNumber() throws Exception { - JsonObject person = buildPerson(); - JsonNumber number = person.getJsonNumber("age"); - assertEquals(25, number.intValueExact()); - assertEquals(25, number.intValue()); - assertTrue(number.isIntegral()); - JsonObjectTest.testPerson(person); - } - - public void testJsonObjectCopy() { - JsonObject person = buildPerson(); - final JsonObjectBuilder objectBuilder = Json.createObjectBuilder(person); - final JsonObject copyPerson = objectBuilder.build(); - - JsonNumber number = copyPerson.getJsonNumber("age"); - assertEquals(25, number.intValueExact()); - assertEquals(25, number.intValue()); - assertTrue(number.isIntegral()); - JsonObjectTest.testPerson(copyPerson); - - } - - public void testJsonObjectMap() { - Map person = buildPersonAsMap(); - final JsonObjectBuilder objectBuilder = Json.createObjectBuilder(person); - final JsonObject copyPerson = objectBuilder.build(); - - JsonNumber number = copyPerson.getJsonNumber("age"); - assertEquals(25, number.intValueExact()); - assertEquals(25, number.intValue()); - assertTrue(number.isIntegral()); - JsonObjectTest.testPerson(copyPerson); - } - - static Map buildPersonAsMap() { - Map person = new HashMap<>(); - person.put("firstName", "John"); - person.put("lastName", "Smith"); - person.put("age", 25); - - Map address = Optional.of(new HashMap()).get(); - address.put("streetAddress", "21 2nd Street"); - address.put("city", "New York"); - address.put("state", "NY"); - address.put("postalCode", "10021"); - - person.put("address", address); - person.put("mailingAddress", Optional.empty()); - - Collection> phones = new ArrayList<>(); - - Map phone1 = new HashMap<>(); - phone1.put("type", "home"); - phone1.put("number", "212 555-1234"); - phones.add(phone1); - - Map phone2 = new HashMap<>(); - phone2.put("type", "fax"); - phone2.put("number", "646 555-4567"); - phones.add(phone2); - - person.put("phoneNumber", phones); - - return person; - } - - static JsonObject buildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - - static JsonObject buildAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - - static JsonArray buildPhone() { - return Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567")) - .build(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonCollectorTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonCollectorTest.java deleted file mode 100644 index f43a4e96..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonCollectorTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import org.junit.BeforeClass; -import org.junit.Test; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonPatchBuilder; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonCollectors; -import org.eclipse.jsonp.JsonUtil; - -import static org.junit.Assert.assertEquals; - -/** - * Some JSON query tests/examples, using Java stream operations, with JSON collectors. - * @author Kin-man Chung - */ -public class JsonCollectorTest { - - static JsonArray contacts; - - @BeforeClass - public static void setUpClass() { - // The JSON source - contacts = (JsonArray) JsonUtil.toJson( - "[ " + - " { 'name': 'Duke', " + - " 'age': 18, " + - " 'gender': 'M', " + - " 'phones': { " + - " 'home': '650-123-4567', " + - " 'mobile': '650-234-5678'}}," + - " { 'name': 'Jane', " + - " 'age': 23, " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '707-999-5555'}}," + - " { 'name': 'Joanna', " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '505-333-4444'}} " + - " ]"); - } - - @Test - public void testToJsonArray() { - /* - * Query: retrieve the names of female contacts - * Returns a JsonArray of names - */ - JsonArray result = contacts.getValuesAs(JsonObject.class).stream() - .filter(x->"F".equals(x.getString("gender"))) - .map(x-> x.get("name")) - .collect(JsonCollectors.toJsonArray()); - JsonValue expected = JsonUtil.toJson("['Jane','Joanna']"); - assertEquals(expected, result); - } - - @Test - public void testToJsonObject() { - /* - * Query: retrieve the names and mobile phones of female contacts - * Returns a JsonObject of name phones pairs - */ - JsonObject result = contacts.getValuesAs(JsonObject.class).stream() - .filter(x->"F".equals(x.getString("gender"))) - .collect(JsonCollectors.toJsonObject( - x->x.asJsonObject().getString("name"), - x->x.asJsonObject().getJsonObject("phones").get("mobile"))) - ; - JsonValue expected = JsonUtil.toJson( - "{'Jane': '707-999-5555', 'Joanna': '505-333-4444'}"); - assertEquals(expected, result); - } - - @Test - public void testGroupBy() { - /* - * Query: group the contacts according to gender - * Returns a JsonObject, with gender/constacts value pairs - */ - JsonObject result = contacts.getValuesAs(JsonObject.class).stream() - .collect(JsonCollectors.groupingBy(x->((JsonObject)x).getString("gender"))); - JsonValue expected = JsonUtil.toJson( - "{'F': " + - " [ " + - " { 'name': 'Jane', " + - " 'age': 23, " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '707-999-5555'}}," + - " { 'name': 'Joanna', " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '505-333-4444'}} " + - " ], " + - "'M': " + - " [ " + - " { 'name': 'Duke', " + - " 'age': 18, " + - " 'gender': 'M', " + - " 'phones': { " + - " 'home': '650-123-4567', " + - " 'mobile': '650-234-5678'}} " + - " ] " + - "}"); - - assertEquals(result,expected); - } - - static int index; //for keeping track of the array index - @Test - public void testQueryAndPatch() { - /* - * Query and patch: Increment the ages of contacts with an age entry - * PatchBuilder is used for building the necessary JsonPatch. - */ - index = -1; - JsonPatchBuilder builder = Json.createPatchBuilder(); - contacts.getValuesAs(JsonObject.class).stream() - .peek(p->index++) - .filter(p->p.containsKey("age")) - .forEach(p-> builder.replace("/"+index+"/age", p.getInt("age")+1)); - JsonArray result = builder.build().apply(contacts); - - JsonValue expected = (JsonArray) JsonUtil.toJson( - "[ " + - " { 'name': 'Duke', " + - " 'age': 19, " + - " 'gender': 'M', " + - " 'phones': { " + - " 'home': '650-123-4567', " + - " 'mobile': '650-234-5678'}}," + - " { 'name': 'Jane', " + - " 'age': 24, " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '707-999-5555'}}," + - " { 'name': 'Joanna', " + - " 'gender': 'F', " + - " 'phones': { " + - " 'mobile': '505-333-4444'}} " + - " ]"); - - assertEquals(expected, result); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonDuplicateKeyTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonDuplicateKeyTest.java deleted file mode 100644 index 0fdbeb15..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonDuplicateKeyTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.StringReader; -import java.util.Collections; - -import org.eclipse.jsonp.api.JsonConfig; -import org.junit.Test; - -import jakarta.json.Json; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonReader; -import jakarta.json.JsonReaderFactory; -import jakarta.json.stream.JsonParsingException; - -public class JsonDuplicateKeyTest { - @Test - public void testJsonReaderDuplicateKey1() { - String json = "{\"a\":\"b\",\"a\":\"c\"}"; - JsonReader jsonReader = Json.createReader(new StringReader(json)); - JsonObject jsonObject = jsonReader.readObject(); - assertEquals(jsonObject.getString("a"), "c"); - } - - @Test - public void testJsonReaderDuplicateKey2() { - String json = "{\"a\":\"b\",\"a\":\"c\"}"; - JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true)); - JsonReader jsonReader = jsonReaderFactory.createReader(new StringReader(json)); - try { - jsonReader.readObject(); - fail(); - } catch (Exception e) { - assertTrue(e instanceof JsonParsingException); - assertEquals("Duplicate key 'a' is not allowed", e.getMessage()); - } - } - - @Test - public void testJsonReaderDuplicateKey3() { - String json = "{\"a\":\"b\",\"b\":{\"c\":\"d\",\"c\":\"e\"}}"; - JsonReader jsonReader = Json.createReader(new StringReader(json)); - JsonObject jsonObject = jsonReader.readObject(); - assertEquals(jsonObject.getJsonObject("b").getString("c"), "e"); - } - - @Test - public void testJsonReaderDuplicateKey4() { - String json = "{\"a\":\"b\",\"b\":{\"c\":\"d\",\"c\":\"e\"}}";; - JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true)); - JsonReader jsonReader = jsonReaderFactory.createReader(new StringReader(json)); - try { - jsonReader.readObject(); - fail(); - } catch (Exception e) { - assertTrue(e instanceof JsonParsingException); - assertEquals("Duplicate key 'c' is not allowed", e.getMessage()); - } - } - - @Test - public void testJsonObjectBuilderDuplcateKey1() { - JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); - JsonObject jsonObject = objectBuilder.add("a", "b").add("a", "c").build(); - assertEquals(jsonObject.getString("a"), "c"); - } - - @Test - public void testJsonObjectBuilderDuplcateKey2() { - JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true)); - JsonObjectBuilder objectBuilder = jsonBuilderFactory.createObjectBuilder(); - try { - objectBuilder.add("a", "b").add("a", "c").build(); - fail(); - } catch (Exception e) { - assertTrue(e instanceof IllegalStateException); - assertEquals("Duplicate key 'a' is not allowed", e.getMessage()); - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonFieldTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonFieldTest.java deleted file mode 100644 index 0f9530b4..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonFieldTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.Json; -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonGenerationException; -import jakarta.json.stream.JsonGenerator; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.concurrent.Callable; - -/** - * Test for writing json field names without values. - * - * @author Roman Grigoriadi - */ -public class JsonFieldTest extends TestCase { - - public void testFieldAsOnlyMember() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("fName"); - generator.write("fValue"); - generator.writeEnd(); - - generator.close(); - assertEquals("{\"fName\":\"fValue\"}", sw.toString()); - } - - public void testFieldAsFirstMember() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("f1Name"); - generator.write("f1Value"); - generator.write("f2Name", "f2Value"); - generator.writeEnd(); - - generator.close(); - assertEquals("{\"f1Name\":\"f1Value\",\"f2Name\":\"f2Value\"}", sw.toString()); - } - - public void testFieldAsLastMember() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.write("f1Name", "f1Value"); - generator.writeKey("f2Name"); - generator.write("f2Value"); - generator.writeEnd(); - - generator.close(); - assertEquals("{\"f1Name\":\"f1Value\",\"f2Name\":\"f2Value\"}", sw.toString()); - } - - - public void testFieldObject() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("f1Name"); - generator.writeStartObject(); - generator.write("innerFieldName", "innerFieldValue"); - generator.writeEnd(); - generator.write("f2Name", "f2Value"); - generator.writeEnd(); - - generator.close(); - assertEquals("{\"f1Name\":{\"innerFieldName\":\"innerFieldValue\"},\"f2Name\":\"f2Value\"}", sw.toString()); - } - - public void testFieldArray() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("f1Name"); - generator.writeStartArray(); - generator.write("arrayValue"); - generator.writeEnd(); - generator.write("f2Name", "f2Value"); - generator.writeEnd(); - - generator.close(); - assertEquals("{\"f1Name\":[\"arrayValue\"],\"f2Name\":\"f2Value\"}", sw.toString()); - } - - public void testFailFieldInField() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("f1Name"); - - try { - generator.write("f2Name", "f2Value"); - fail("Field value, start object/array expected"); - } catch (JsonGenerationException exception) { - //ok - } - } - - - public void testFailFieldKeyInArray() { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartArray(); - - try { - generator.writeKey("f1Value"); - fail("Not allowed in array ."); - } catch (JsonGenerationException exception) { - //ok - } - } - - public void testWriteString() { - assertEquals("{\"f1Name\":\"f1Value\"}", writeValue((gen)->gen.write("f1Value"))); - } - - public void testWriteBigDec() { - assertEquals("{\"f1Name\":10}", writeValue((gen)->gen.write(BigDecimal.TEN))); - } - - public void testWriteBigInt() { - assertEquals("{\"f1Name\":10}", writeValue((gen)->gen.write(BigInteger.TEN))); - } - - public void testWriteBool() { - assertEquals("{\"f1Name\":true}", writeValue((gen)->gen.write(true))); - } - - public void testWriteInt() { - assertEquals("{\"f1Name\":10}", writeValue((gen)->gen.write(10))); - } - - public void testWriteLong() { - assertEquals("{\"f1Name\":10}", writeValue((gen)->gen.write(10L))); - } - - public void testWriteDouble() { - assertEquals("{\"f1Name\":10.0}", writeValue((gen)->gen.write(10d))); - } - - public void testWriteNull() { - assertEquals("{\"f1Name\":null}", writeValue(JsonGenerator::writeNull)); - } - - public void testWriteJsonValue() { - JsonObjectBuilder builder = Json.createObjectBuilder(); - builder.add("first", "value"); - final JsonObject build = builder.build(); - assertEquals("{\"f1Name\":\"value\"}", writeValue((gen)->gen.write(build.getValue("/first")))); - } - - private String writeValue(WriteValueFunction writeValueCallback) { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - - generator.writeStartObject(); - generator.writeKey("f1Name"); - writeValueCallback.writeValue(generator); - generator.writeEnd(); - generator.close(); - return sw.toString(); - } - - private interface WriteValueFunction { - void writeValue(JsonGenerator generator); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorFactoryTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorFactoryTest.java deleted file mode 100644 index 2748965d..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorFactoryTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import jakarta.json.stream.JsonGenerator; -import jakarta.json.stream.JsonGeneratorFactory; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Map; - -/** - * Tests JsonGeneratorFactory - * - * @author Jitendra Kotamraju - */ -public class JsonGeneratorFactoryTest extends TestCase { - - public JsonGeneratorFactoryTest(String testName) { - super(testName); - } - - public void testGeneratorFactory() { - JsonGeneratorFactory generatorFactory = Json.createGeneratorFactory(null); - - JsonGenerator generator1 = generatorFactory.createGenerator(new StringWriter()); - generator1.writeStartArray().writeEnd(); - generator1.close(); - - JsonGenerator generator2 = generatorFactory.createGenerator(new StringWriter()); - generator2.writeStartArray().writeEnd(); - generator2.close(); - } - - public void testGeneratorFactoryWithConfig() { - Map config = new HashMap<>(); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonGeneratorFactory generatorFactory = Json.createGeneratorFactory(config); - Map config1 = generatorFactory.getConfigInUse(); - if (config1.size() != 1) { - throw new JsonException("Expecting no of properties=1, got="+config1.size()); - } - assertTrue(config1.containsKey(JsonGenerator.PRETTY_PRINTING)); - - JsonGenerator generator1 = generatorFactory.createGenerator(new StringWriter()); - generator1.writeStartArray().writeEnd(); - generator1.close(); - - JsonGenerator generator2 = generatorFactory.createGenerator(new StringWriter()); - generator2.writeStartArray().writeEnd(); - generator2.close(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorTest.java deleted file mode 100644 index 1ca810d9..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonGeneratorTest.java +++ /dev/null @@ -1,545 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; -import org.eclipse.jsonp.api.BufferPool; - -import jakarta.json.*; -import jakarta.json.stream.*; -import java.io.*; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -/** - * {@link JsonGenerator} tests - * - * @author Jitendra Kotamraju - */ -public class JsonGeneratorTest extends TestCase { - public JsonGeneratorTest(String testName) { - super(testName); - } - - public void testObjectWriter() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - testObject(generator); - generator.close(); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(writer.toString())); - JsonObject person = reader.readObject(); - JsonObjectTest.testPerson(person); - } - - public void testObjectStream() throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - JsonGenerator generator = Json.createGenerator(out); - testObject(generator); - generator.close(); - out.close(); - - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - JsonReader reader = Json.createReader(in); - JsonObject person = reader.readObject(); - JsonObjectTest.testPerson(person); - reader.close(); - in.close(); - } - - static void testObject(JsonGenerator generator) throws Exception { - generator - .writeStartObject() - .write("firstName", "John") - .write("lastName", "Smith") - .write("age", 25) - .writeStartObject("address") - .write("streetAddress", "21 2nd Street") - .write("city", "New York") - .write("state", "NY") - .write("postalCode", "10021") - .writeEnd() - .writeStartArray("phoneNumber") - .writeStartObject() - .write("type", "home") - .write("number", "212 555-1234") - .writeEnd() - .writeStartObject() - .write("type", "fax") - .write("number", "646 555-4567") - .writeEnd() - .writeEnd() - .writeEnd(); - } - - public void testArray() throws Exception { - Writer sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - generator - .writeStartArray() - .writeStartObject() - .write("type", "home") - .write("number", "212 555-1234") - .writeEnd() - .writeStartObject() - .write("type", "fax") - .write("number", "646 555-4567") - .writeEnd() - .writeEnd(); - generator.close(); - } - - // tests JsonGenerator when JsonValue is used for generation - public void testJsonValue() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator - .writeStartObject() - .write("firstName", "John") - .write("lastName", "Smith") - .write("age", 25) - .write("address", JsonBuilderTest.buildAddress()) - .write("phoneNumber", JsonBuilderTest.buildPhone()) - .writeEnd(); - generator.close(); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(writer.toString())); - JsonObject person = reader.readObject(); - JsonObjectTest.testPerson(person); - } - - public void testArrayString() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartArray().write("string").writeEnd(); - generator.close(); - writer.close(); - - assertEquals("[\"string\"]", writer.toString()); - } - - public void testEscapedString() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartArray().write("\u0000").writeEnd(); - generator.close(); - writer.close(); - - assertEquals("[\"\\u0000\"]", writer.toString()); - } - - public void testEscapedString1() throws Exception { - String expected = "\u0000\u00ff"; - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - generator.writeStartArray().write("\u0000\u00ff").writeEnd(); - generator.close(); - sw.close(); - - JsonReader jr = Json.createReader(new StringReader(sw.toString())); - JsonArray array = jr.readArray(); - String got = array.getString(0); - jr.close(); - - assertEquals(expected, got); - } - - public void testGeneratorEquals() throws Exception { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - generator.writeStartArray() - .write(JsonValue.TRUE) - .write(JsonValue.FALSE) - .write(JsonValue.NULL) - .write(Integer.MAX_VALUE) - .write(Long.MAX_VALUE) - .write(Double.MAX_VALUE) - .write(Integer.MIN_VALUE) - .write(Long.MIN_VALUE) - .write(Double.MIN_VALUE) - .writeEnd(); - generator.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonArray expected = reader.readArray(); - reader.close(); - - JsonArray actual = Json.createArrayBuilder() - .add(JsonValue.TRUE) - .add(JsonValue.FALSE) - .add(JsonValue.NULL) - .add(Integer.MAX_VALUE) - .add(Long.MAX_VALUE) - .add(Double.MAX_VALUE) - .add(Integer.MIN_VALUE) - .add(Long.MIN_VALUE) - .add(Double.MIN_VALUE) - .build(); - - assertEquals(expected, actual); - } - - public void testPrettyObjectWriter() throws Exception { - StringWriter writer = new StringWriter(); - Map config = new HashMap<>(); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonGenerator generator = Json.createGeneratorFactory(config) - .createGenerator(writer); - testObject(generator); - generator.close(); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(writer.toString())); - JsonObject person = reader.readObject(); - JsonObjectTest.testPerson(person); - } - - public void testPrettyPrinting() throws Exception { - String[][] lines = {{"firstName", "John"}, {"lastName", "Smith"}}; - StringWriter writer = new StringWriter(); - Map config = new HashMap<>(); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonGenerator generator = Json.createGeneratorFactory(config) - .createGenerator(writer); - generator.writeStartObject() - .write("firstName", "John") - .write("lastName", "Smith") - .writeEnd(); - generator.close(); - writer.close(); - - BufferedReader reader = new BufferedReader(new StringReader(writer.toString())); - int numberOfLines = 0; - String line; - while ((line = reader.readLine()) != null) { - numberOfLines++; - if (numberOfLines > 1 && numberOfLines < 4) { - assertTrue(line.contains("\"" + lines[numberOfLines - 2][0] + "\": \"" + lines[numberOfLines - 2][1] + "\"")); - } - } - assertEquals(4, numberOfLines); - } - - public void testPrettyObjectStream() throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - Map config = new HashMap<>(); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonGenerator generator = Json.createGeneratorFactory(config) - .createGenerator(out); - testObject(generator); - generator.close(); - out.close(); - - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - JsonReader reader = Json.createReader(in); - JsonObject person = reader.readObject(); - JsonObjectTest.testPerson(person); - reader.close(); - in.close(); - } - - public void testGenerationException1() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartObject(); - try { - generator.writeStartObject(); - fail("Expected JsonGenerationException, writeStartObject() cannot be called more than once"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException2() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartObject(); - try { - generator.writeStartArray(); - fail("Expected JsonGenerationException, writeStartArray() is valid in no context"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException3() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - try { - generator.close(); - fail("Expected JsonGenerationException, no JSON is generated"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException4() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartArray(); - try { - generator.close(); - fail("Expected JsonGenerationException, writeEnd() is not called"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException5() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartObject(); - try { - generator.close(); - fail("Expected JsonGenerationException, writeEnd() is not called"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException6() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartObject().writeEnd(); - try { - generator.writeStartObject(); - fail("Expected JsonGenerationException, cannot generate one more JSON text"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException7() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartArray().writeEnd(); - try { - generator.writeStartArray(); - fail("Expected JsonGenerationException, cannot generate one more JSON text"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - - public void testGenerationException8() throws Exception { - StringWriter sWriter = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sWriter); - generator.writeStartObject(); - try { - generator.write(JsonValue.TRUE); - fail("Expected JsonGenerationException, cannot generate one more JSON text"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGenerationException9() throws Exception { - StringWriter sWriter = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sWriter); - generator.writeStartObject(); - try { - generator.write("name"); - fail("Expected JsonGenerationException, cannot generate one more JSON text"); - } catch (JsonGenerationException je) { - // Expected exception - } - } - - public void testGeneratorArrayDouble() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartArray(); - try { - generator.write(Double.NaN); - fail("JsonGenerator.write(Double.NaN) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - try { - generator.write(Double.POSITIVE_INFINITY); - fail("JsonGenerator.write(Double.POSITIVE_INIFINITY) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - try { - generator.write(Double.NEGATIVE_INFINITY); - fail("JsonGenerator.write(Double.NEGATIVE_INIFINITY) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - generator.writeEnd(); - generator.close(); - } - - public void testGeneratorObjectDouble() throws Exception { - StringWriter writer = new StringWriter(); - JsonGenerator generator = Json.createGenerator(writer); - generator.writeStartObject(); - try { - generator.write("foo", Double.NaN); - fail("JsonGenerator.write(String, Double.NaN) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - try { - generator.write("foo", Double.POSITIVE_INFINITY); - fail("JsonGenerator.write(String, Double.POSITIVE_INIFINITY) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - try { - generator.write("foo", Double.NEGATIVE_INFINITY); - fail("JsonGenerator.write(String, Double.NEGATIVE_INIFINITY) should produce NumberFormatException"); - } catch (NumberFormatException ne) { - // expected - } - generator.writeEnd(); - generator.close(); - } - - public void testIntGenerator() throws Exception { - Random r = new Random(System.currentTimeMillis()); - JsonGeneratorFactory gf = Json.createGeneratorFactory(null); - JsonReaderFactory rf = Json.createReaderFactory(null); - JsonBuilderFactory bf = Json.createBuilderFactory(null); - for(int i=0; i < 100000; i++) { - int num = r.nextInt(); - StringWriter sw = new StringWriter(); - JsonGenerator generator = gf.createGenerator(sw); - generator.writeStartArray().write(num).writeEnd().close(); - - JsonReader reader = rf.createReader(new StringReader(sw.toString())); - JsonArray got = reader.readArray(); - reader.close(); - - JsonArray expected = bf.createArrayBuilder().add(num).build(); - - assertEquals(expected, got); - } - } - - public void testGeneratorBuf() throws Exception { - JsonGeneratorFactory gf = Json.createGeneratorFactory(null); - JsonReaderFactory rf = Json.createReaderFactory(null); - JsonBuilderFactory bf = Json.createBuilderFactory(null); - StringBuilder sb = new StringBuilder(); - int value = 10; - for(int i=0; i < 25000; i++) { - sb.append('a'); - String name = sb.toString(); - StringWriter sw = new StringWriter(); - JsonGenerator generator = gf.createGenerator(sw); - generator.writeStartObject().write(name, value).writeEnd().close(); - - JsonReader reader = rf.createReader(new StringReader(sw.toString())); - JsonObject got = reader.readObject(); - reader.close(); - - JsonObject expected = bf.createObjectBuilder().add(name, value).build(); - - assertEquals(expected, got); - } - } - - public void testBufferPoolFeature() { - final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(1024); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - - JsonGeneratorFactory factory = Json.createGeneratorFactory(config); - JsonGenerator generator = factory.createGenerator(new StringWriter()); - generator.writeStartArray(); - generator.writeEnd(); - generator.close(); - assertTrue(bufferPool.isTakeCalled()); - assertTrue(bufferPool.isRecycleCalled()); - } - - public void testBufferSizes() { - JsonReaderFactory rf = Json.createReaderFactory(null); - JsonBuilderFactory bf = Json.createBuilderFactory(null); - for(int size=10; size < 1000; size++) { - final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(size); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - JsonGeneratorFactory gf = Json.createGeneratorFactory(config); - - StringBuilder sb = new StringBuilder(); - int value = 10; - for(int i=0; i < 1500; i++) { - sb.append('a'); - String name = sb.toString(); - StringWriter sw = new StringWriter(); - JsonGenerator generator = gf.createGenerator(sw); - generator.writeStartObject().write(name, value).writeEnd().close(); - - JsonReader reader = rf.createReader(new StringReader(sw.toString())); - JsonObject got = reader.readObject(); - reader.close(); - - JsonObject expected = bf.createObjectBuilder().add(name, value).build(); - - assertEquals(expected, got); - } - - } - } - - public void testString() throws Exception { - escapedString(""); - escapedString("abc"); - escapedString("abc\f"); - escapedString("abc\na"); - escapedString("abc\tabc"); - escapedString("abc\n\tabc"); - escapedString("abc\n\tabc\r"); - escapedString("\n\tabc\r"); - escapedString("\bab\tb\rc\\\"\ftesting1234"); - escapedString("\f\babcdef\tb\rc\\\"\ftesting1234"); - } - - void escapedString(String expected) throws Exception { - StringWriter sw = new StringWriter(); - JsonGenerator generator = Json.createGenerator(sw); - generator.writeStartArray().write(expected).writeEnd(); - generator.close(); - sw.close(); - - JsonReader jr = Json.createReader(new StringReader(sw.toString())); - JsonArray array = jr.readArray(); - String got = array.getString(0); - jr.close(); - - assertEquals(expected, got); - } - - public void testFlush() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonGenerator gen = Json.createGenerator(baos); - gen.writeStartObject().writeEnd(); - gen.flush(); - - assertEquals("{}", baos.toString("UTF-8")); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchDiffTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchDiffTest.java deleted file mode 100644 index 1a5e0c8a..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchDiffTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonMergePatchDiffTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - List examples = new ArrayList(); - JsonArray data = loadData(); - for (JsonValue jsonValue : data) { - JsonObject test = (JsonObject) jsonValue; - Object[] testData = new Object[4]; - testData[0] = test.get("original"); - testData[1] = test.get("target"); - testData[2] = test.get("expected"); - testData[3] = createExceptionClass((JsonString)test.get("exception")); - - examples.add(testData); - } - - return examples; - } - - private static Class createExceptionClass( - JsonString exceptionClassName) throws ClassNotFoundException { - if (exceptionClassName != null) { - return (Class) Class - .forName(exceptionClassName.getString()); - } - return null; - } - - private static JsonArray loadData() { - InputStream testData = JsonPatchTest.class - .getResourceAsStream("/jsonmergepatchdiff.json"); - JsonReader reader = Json.createReader(testData); - JsonArray data = (JsonArray) reader.read(); - return data; - } - - private JsonValue original; - private JsonValue target; - private JsonValue expected; - private Class expectedException; - - public JsonMergePatchDiffTest(JsonValue original, JsonValue target, - JsonValue expected, Class expectedException) { - super(); - this.original = original; - this.target = target; - this.expected = expected; - this.expectedException = expectedException; - } - @Test - public void shouldExecuteJsonMergePatchDiffOperationsToJsonDocument() { - try { - JsonValue output = Json.createMergeDiff(original, target).toJsonValue(); - assertThat(output, is(expected)); - assertThat(expectedException, nullValue()); - } catch (Exception e) { - if (expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchTest.java deleted file mode 100644 index ed8a438f..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonMergePatchTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonMergePatchTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - List examples = new ArrayList(); - JsonArray data = loadData(); - for (JsonValue jsonValue : data) { - JsonObject test = (JsonObject) jsonValue; - Object[] testData = new Object[4]; - testData[0] = test.get("patch"); - testData[1] = test.get("target"); - testData[2] = test.get("expected"); - testData[3] = createExceptionClass((JsonString)test.get("exception")); - - examples.add(testData); - } - - return examples; - } - - private static Class createExceptionClass( - JsonString exceptionClassName) throws ClassNotFoundException { - if (exceptionClassName != null) { - return (Class) Class - .forName(exceptionClassName.getString()); - } - return null; - } - - private static JsonArray loadData() { - InputStream testData = JsonPatchTest.class - .getResourceAsStream("/jsonmergepatch.json"); - JsonReader reader = Json.createReader(testData); - JsonArray data = (JsonArray) reader.read(); - return data; - } - - private JsonValue patch; - private JsonValue target; - private JsonValue expected; - private Class expectedException; - - public JsonMergePatchTest(JsonValue patch, JsonValue target, - JsonValue expected, Class expectedException) { - super(); - this.patch = patch; - this.target = target; - this.expected = expected; - this.expectedException = expectedException; - } - - @Test - public void shouldExecuteJsonMergePatchDiffOperationsToJsonDocument() { - try { - JsonValue output = Json.createMergePatch(patch).apply(target); - assertThat(output, is(expected)); - assertThat(expectedException, nullValue()); - } catch (Exception e) { - if (expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonNumberTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonNumberTest.java deleted file mode 100644 index 37b60f12..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonNumberTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import java.io.StringReader; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * @author Jitendra Kotamraju - */ -public class JsonNumberTest extends TestCase { - public JsonNumberTest(String testName) { - super(testName); - } - - public void testFloating() throws Exception { - JsonArray array1 = Json.createArrayBuilder().add(10.4).build(); - JsonReader reader = Json.createReader(new StringReader("[10.4]")); - JsonArray array2 = reader.readArray(); - - assertEquals(array1.get(0), array2.get(0)); - assertEquals(array1, array2); - } - - public void testBigDecimal() throws Exception { - JsonArray array1 = Json.createArrayBuilder().add(new BigDecimal("10.4")).build(); - JsonReader reader = Json.createReader(new StringReader("[10.4]")); - JsonArray array2 = reader.readArray(); - - assertEquals(array1.get(0), array2.get(0)); - assertEquals(array1, array2); - } - - public void testIntNumberType() throws Exception { - JsonArray array1 = Json.createArrayBuilder() - .add(Integer.MIN_VALUE) - .add(Integer.MAX_VALUE) - .add(Integer.MIN_VALUE + 1) - .add(Integer.MAX_VALUE - 1) - .add(12) - .add(12l) - .add(new BigInteger("0")) - .build(); - testNumberType(array1, true); - - StringReader sr = new StringReader("[" + - "-2147483648, " + - "2147483647, " + - "-2147483647, " + - "2147483646, " + - "12, " + - "12, " + - "0 " + - "]"); - JsonReader reader = Json.createReader(sr); - JsonArray array2 = reader.readArray(); - reader.close(); - testNumberType(array2, true); - - assertEquals(array1, array2); - } - - private void testNumberType(JsonArray array, boolean integral) { - for (JsonValue value : array) { - assertEquals(integral, ((JsonNumber) value).isIntegral()); - } - } - - public void testLongNumberType() throws Exception { - JsonArray array1 = Json.createArrayBuilder() - .add(Long.MIN_VALUE) - .add(Long.MAX_VALUE) - .add(Long.MIN_VALUE + 1) - .add(Long.MAX_VALUE - 1) - .add((long) Integer.MIN_VALUE - 1) - .add((long) Integer.MAX_VALUE + 1) - .build(); - testNumberType(array1, true); - - StringReader sr = new StringReader("[" + - "-9223372036854775808, " + - "9223372036854775807, " + - "-9223372036854775807, " + - "9223372036854775806, " + - "-2147483649, " + - "2147483648 " + - "]"); - JsonReader reader = Json.createReader(sr); - JsonArray array2 = reader.readArray(); - reader.close(); - testNumberType(array2, true); - - assertEquals(array1, array2); - } - - -// public void testBigIntegerNumberType() throws Exception { -// JsonArray array1 = new JsonBuilder() -// .startArray() -// .add(new BigInteger("-9223372036854775809")) -// .add(new BigInteger("9223372036854775808")) -// .add(new BigInteger("012345678901234567890")) -// .end() -// .build(); -// testNumberType(array1, JsonNumber.NumberType.BIG_INTEGER); -// -// StringReader sr = new StringReader("[" + -// "-9223372036854775809, " + -// "9223372036854775808, " + -// "12345678901234567890 " + -// "]"); -// JsonReader reader = new JsonReader(sr); -// JsonArray array2 = reader.readArray(); -// reader.close(); -// testNumberType(array2, JsonNumber.NumberType.BIG_INTEGER); -// -// assertEquals(array1, array2); -// } - - public void testBigDecimalNumberType() throws Exception { - JsonArray array1 = Json.createArrayBuilder() - .add(12d) - .add(12.0d) - .add(12.1d) - .add(Double.MIN_VALUE) - .add(Double.MAX_VALUE) - .build(); - testNumberType(array1, false); - - StringReader sr = new StringReader("[" + - "12.0, " + - "12.0, " + - "12.1, " + - "4.9E-324, " + - "1.7976931348623157E+308 " + - "]"); - JsonReader reader = Json.createReader(sr); - JsonArray array2 = reader.readArray(); - reader.close(); - testNumberType(array2, false); - - assertEquals(array1, array2); - } - - public void testMinMax() throws Exception { - JsonArray expected = Json.createArrayBuilder() - .add(Integer.MIN_VALUE) - .add(Integer.MAX_VALUE) - .add(Long.MIN_VALUE) - .add(Long.MAX_VALUE) - .add(Double.MIN_VALUE) - .add(Double.MAX_VALUE) - .build(); - - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.writeArray(expected); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonArray actual = reader.readArray(); - reader.close(); - - assertEquals(expected, actual); - } - - public void testLeadingZeroes() { - JsonArray array = Json.createArrayBuilder() - .add(0012.1d) - .build(); - - StringWriter sw = new StringWriter(); - JsonWriter jw = Json.createWriter(sw); - jw.write(array); - jw.close(); - - assertEquals("[12.1]", sw.toString()); - } - - public void testBigIntegerExact() { - try { - JsonArray array = Json.createArrayBuilder().add(12345.12345).build(); - array.getJsonNumber(0).bigIntegerValueExact(); - fail("Expected Arithmetic exception"); - } catch (ArithmeticException expected) { - // no-op - } - } - - public void testHashCode() { - JsonNumber jsonNumber1 = Json.createValue(1); - assertTrue(jsonNumber1.hashCode() == jsonNumber1.bigDecimalValue().hashCode()); - - JsonNumber jsonNumber2 = Json.createValue(1); - - assertTrue(jsonNumber1.equals(jsonNumber2)); - assertTrue(jsonNumber1.hashCode() == jsonNumber2.hashCode()); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonObjectTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonObjectTest.java deleted file mode 100644 index e7d61efc..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonObjectTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import java.io.StringReader; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Map; - -import jakarta.json.*; - -/** - * @author Jitendra Kotamraju - */ -public class JsonObjectTest extends TestCase { - public JsonObjectTest(String testName) { - super(testName); - } - - public void test() { - } - - public void testEmptyObjectEquals() throws Exception { - JsonObject empty1 = Json.createObjectBuilder() - .build(); - - JsonObject empty2 = Json.createObjectBuilder() - .build(); - - assertEquals(empty1, empty2); - } - - public void testPersonObjectEquals() throws Exception { - JsonObject person1 = JsonBuilderTest.buildPerson(); - JsonObject person2 = JsonReaderTest.readPerson(); - - assertEquals(person1, person2); - } - - public void testGetStringOrDefault() throws Exception { - JsonObject object = Json.createObjectBuilder() - .add("string", "value") - .add("number", 25) - .add("boolean", false) - .build(); - assertEquals("value", object.getString("string", "default")); - assertEquals("default", object.getString("missing", "default")); - assertEquals("default", object.getString("number", "default")); - } - - public void testGetIntOrDefault() throws Exception { - JsonObject object = Json.createObjectBuilder() - .add("string", "value") - .add("number", 25) - .add("boolean", false) - .build(); - assertEquals(25, object.getInt("number", 10)); - assertEquals(10, object.getInt("missing", 10)); - assertEquals(10, object.getInt("string", 10)); - } - - public void testGetBooleanOrDefault() throws Exception { - JsonObject object = Json.createObjectBuilder() - .add("string", "value") - .add("number", 25) - .add("boolean", false) - .build(); - assertFalse(object.getBoolean("boolean", true)); - assertTrue(object.getBoolean("missing", true)); - assertTrue(object.getBoolean("string", true)); - } - - static void testPerson(JsonObject person) { - assertEquals(5, person.size()); - assertEquals("John", person.getString("firstName")); - assertEquals("Smith", person.getString("lastName")); - assertEquals(25, person.getJsonNumber("age").intValue()); - assertEquals(25, person.getInt("age")); - - JsonObject address = person.getJsonObject("address"); - assertEquals(4, address.size()); - assertEquals("21 2nd Street", address.getString("streetAddress")); - assertEquals("New York", address.getString("city")); - assertEquals("NY", address.getString("state")); - assertEquals("10021", address.getString("postalCode")); - - JsonArray phoneNumber = person.getJsonArray("phoneNumber"); - assertEquals(2, phoneNumber.size()); - JsonObject home = phoneNumber.getJsonObject(0); - assertEquals(2, home.size()); - assertEquals("home", home.getString("type")); - assertEquals("212 555-1234", home.getString("number")); - assertEquals("212 555-1234", home.getString("number")); - - JsonObject fax = phoneNumber.getJsonObject(1); - assertEquals(2, fax.size()); - assertEquals("fax", fax.getString("type")); - assertEquals("646 555-4567", fax.getString("number")); - - assertEquals("\"646 555-4567\"", fax.getJsonString("number").toString()); - } - - static void testEmpty(JsonObject empty) { - assertTrue(empty.isEmpty()); - } - - public void testClassCastException() { - JsonObject obj = Json.createObjectBuilder() - .add("foo", JsonValue.FALSE).build(); - try { - obj.getJsonNumber("foo"); - fail("Expected ClassCastException for casting JsonValue.FALSE to JsonNumber"); - } catch (ClassCastException ce) { - // Expected - } - } - - public void testPut() { - JsonObject obj = Json.createObjectBuilder().add("foo", 1).build(); - try { - obj.put("bar", JsonValue.FALSE); - fail("JsonObject#put() should throw UnsupportedOperationException"); - } catch(UnsupportedOperationException e) { - // Expected - } - } - - public void testRemove() { - JsonObject obj = Json.createObjectBuilder().add("foo", 1).build(); - try { - obj.remove("foo"); - fail("JsonObject#remove() should throw UnsupportedOperationException"); - } catch(UnsupportedOperationException e) { - // Expected - } - } - - public void testObjectBuilderWithVariousValues() { - JsonObject expected = Json.createObjectBuilder() - .add("a", JsonValue.TRUE) - .add("b", JsonValue.FALSE) - .add("c", JsonValue.NULL) - .add("d", Integer.MAX_VALUE) - .add("e", Long.MAX_VALUE) - .add("f", Double.MAX_VALUE) - .add("g", Integer.MIN_VALUE) - .add("h", Long.MIN_VALUE) - .add("i", Double.MIN_VALUE) - .add("j", Json.createArrayBuilder().add("abc")) - .add("k", Json.createObjectBuilder().add("one", 1)) - .build(); - - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.writeObject(expected); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonObject actual = reader.readObject(); - reader.close(); - - assertEquals(expected, actual); - } - - public void testObjectBuilderWithMap() { - Map map = new HashMap<>(); - map.put("a", JsonValue.TRUE); - map.put("b", JsonValue.FALSE); - map.put("c", JsonValue.NULL); - map.put("d", Integer.MAX_VALUE); - map.put("e", Long.MAX_VALUE); - map.put("f", Double.MAX_VALUE); - map.put("g", Integer.MIN_VALUE); - map.put("h", Long.MIN_VALUE); - map.put("i", Double.MIN_VALUE); - map.put("j", Json.createArrayBuilder().add("abc")); - map.put("k", Json.createObjectBuilder().add("one", 1)); - - JsonObject expected = Json.createObjectBuilder(map).build(); - - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.writeObject(expected); - writer.close(); - - JsonReader reader = Json.createReader(new StringReader(sw.toString())); - JsonObject actual = reader.readObject(); - reader.close(); - - assertEquals(expected, actual); - } - - public void testObjectBuilderNpe() { - try { - JsonObject obj = Json.createObjectBuilder().add(null, 1).build(); - fail("JsonObjectBuilder#add(null, 1) should throw NullPointerException"); - } catch(NullPointerException e) { - // Expected - } - } - - public void testHashCode() { - JsonObject object1 = Json.createObjectBuilder().add("a", 1).add("b", 2).add("c", 3).build(); - assertTrue(object1.hashCode() == object1.hashCode()); //1st call compute hashCode, 2nd call returns cached value - - JsonObject object2 = Json.createObjectBuilder().add("a", 1).add("b", 2).add("c", 3).build(); - assertTrue(object1.hashCode() == object2.hashCode()); - - JsonObject object3 = Json.createObjectBuilder().build(); //org.eclipse.jsonp.JsonArrayBuilderImpl.JsonArrayImpl - JsonObject object4 = JsonValue.EMPTY_JSON_OBJECT; //jakarta.json.EmptyObject - - assertTrue(object3.equals(object4)); - assertTrue(object3.hashCode() == object4.hashCode()); //equal instances have same hashCode - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserFactoryTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserFactoryTest.java deleted file mode 100644 index f4ee9a40..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserFactoryTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.Json; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParserFactory; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; - -/** - * Tests JsonParserFactory - * - * @author Jitendra Kotamraju - */ -public class JsonParserFactoryTest extends TestCase { - - public JsonParserFactoryTest(String testName) { - super(testName); - } - - public void testParserFactory() { - JsonParserFactory parserFactory = Json.createParserFactory(null); - JsonParser parser1 = parserFactory.createParser(new StringReader("[]")); - parser1.close(); - JsonParser parser2 = parserFactory.createParser(new StringReader("[]")); - parser2.close(); - } - - public void testParserFactoryWithConfig() { - Map config = new HashMap<>(); - JsonParserFactory parserFactory = Json.createParserFactory(config); - JsonParser parser1 = parserFactory.createParser(new StringReader("[]")); - parser1.close(); - JsonParser parser2 = parserFactory.createParser(new StringReader("[]")); - parser2.close(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserSkipTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserSkipTest.java deleted file mode 100644 index 62a1d1f7..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserSkipTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import java.io.StringReader; -import jakarta.json.Json; -import jakarta.json.stream.JsonParser; -import junit.framework.TestCase; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; - -/** - * - * @author lukas - */ -public class JsonParserSkipTest extends TestCase { - - public void testSkipArrayReader() { - try (JsonParser parser = Json.createParser(new StringReader("[[],[[]]]"))) { - testSkipArray(parser); - } - } - - public void testSkipArrayStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder() - .add(Json.createArrayBuilder()) - .add(Json.createArrayBuilder() - .add(Json.createArrayBuilder())) - .build())) { - testSkipArray(parser); - } - } - - private static void testSkipArray(JsonParser parser) { - assertEquals(JsonParser.Event.START_ARRAY, parser.next()); - parser.skipArray(); - assertEquals(false, parser.hasNext()); - } - - public void testSkipArrayInObjectReader() { - try (JsonParser parser = Json.createParser(new StringReader("{\"array\":[[],[[]]],\"object\":\"value2\"}"))) { - testSkipArrayInObject(parser); - } - } - - public void testSkipArrayInObjectStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder().add("array", Json.createArrayBuilder() - .add(Json.createArrayBuilder()) - .add(Json.createArrayBuilder() - .add(Json.createArrayBuilder())) - ).add("object", "value2") - .build())) { - testSkipArrayInObject(parser); - } - } - - private static void testSkipArrayInObject(JsonParser parser) { - assertEquals(JsonParser.Event.START_OBJECT, parser.next()); - assertEquals(JsonParser.Event.KEY_NAME, parser.next()); - assertEquals(JsonParser.Event.START_ARRAY, parser.next()); - parser.skipArray(); - assertTrue(parser.hasNext()); - assertEquals(JsonParser.Event.KEY_NAME, parser.next()); - assertEquals(JsonParser.Event.VALUE_STRING, parser.next()); - assertEquals(JsonParser.Event.END_OBJECT, parser.next()); - assertFalse(parser.hasNext()); - } - - public void testSkipObjectReader() { - try (JsonParser parser = Json.createParser(new StringReader("{\"array\":[],\"objectToSkip\":{\"huge key\":\"huge value\"},\"simple\":2}"))) { - testSkipObject(parser); - } - } - - public void testSkipObjectStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder() - .add("array", Json.createArrayBuilder().build()) - .add("objectToSkip", Json.createObjectBuilder().add("huge key", "huge value")) - .add("simple", 2) - .build())) { - testSkipObject(parser); - } - } - - private static void testSkipObject(JsonParser parser) { - assertEquals(JsonParser.Event.START_OBJECT, parser.next()); - assertEquals(JsonParser.Event.KEY_NAME, parser.next()); - assertEquals(JsonParser.Event.START_ARRAY, parser.next()); - assertEquals(JsonParser.Event.END_ARRAY, parser.next()); - assertEquals(JsonParser.Event.KEY_NAME, parser.next()); - assertEquals(JsonParser.Event.START_OBJECT, parser.next()); - parser.skipObject(); - assertEquals(JsonParser.Event.KEY_NAME, parser.next()); - assertEquals(JsonParser.Event.VALUE_NUMBER, parser.next()); - assertEquals(JsonParser.Event.END_OBJECT, parser.next()); - assertEquals(false, parser.hasNext()); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserTest.java deleted file mode 100644 index 401f8f76..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParserTest.java +++ /dev/null @@ -1,827 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import junit.framework.TestCase; - -import jakarta.json.*; -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParser.Event; -import jakarta.json.stream.JsonParserFactory; -import java.math.BigDecimal; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Random; -import java.util.Scanner; -import jakarta.json.stream.JsonParsingException; - -import org.eclipse.jsonp.api.BufferPool; - -/** - * JsonParser Tests - * - * @author Jitendra Kotamraju - */ -public class JsonParserTest extends TestCase { - static final Charset UTF_32LE = Charset.forName("UTF-32LE"); - static final Charset UTF_32BE = Charset.forName("UTF-32BE"); - - public JsonParserTest(String testName) { - super(testName); - } - - public void testReader() { - JsonParser reader = Json.createParser( - new StringReader("{ \"a\" : \"b\", \"c\" : null, \"d\" : [null, \"abc\"] }")); - reader.close(); - } - - - public void testEmptyArrayReader() { - try (JsonParser parser = Json.createParser(new StringReader("[]"))) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStream() { - try (JsonParser parser = Json.createParser( - new ByteArrayInputStream(new byte[]{'[', ']'}))) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF8() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_8)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF16LE() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_16LE)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF16BE() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_16BE)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF32LE() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(UTF_32LE)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF32BE() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(UTF_32BE)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamUTF16() { - ByteArrayInputStream bin = new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_16)); - try (JsonParser parser = Json.createParser(bin)) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStreamWithConfig() { - Map config = new HashMap<>(); - try (JsonParser parser = Json.createParserFactory(config).createParser( - new ByteArrayInputStream(new byte[]{'[', ']'}))) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder().build())) { - testEmptyArray(parser); - } - } - - public void testEmptyArrayStructureWithConfig() { - Map config = new HashMap<>(); - try (JsonParser parser = Json.createParserFactory(config).createParser( - Json.createArrayBuilder().build())) { - testEmptyArray(parser); - } - } - - @SuppressWarnings("UnusedDeclaration") - static void testEmptyArray(JsonParser parser) { - while (parser.hasNext()) { - parser.next(); - } - } - - - public void testEmptyArrayReaderIterator() { - try (JsonParser parser = Json.createParser(new StringReader("[]"))) { - testEmptyArrayIterator(parser); - } - } - - public void testEmptyArrayStructureIterator() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder().build())) { - testEmptyArrayIterator(parser); - } - } - - static void testEmptyArrayIterator(JsonParser parser) { - assertEquals(true, parser.hasNext()); - assertEquals(true, parser.hasNext()); - assertEquals(Event.START_ARRAY, parser.next()); - - assertEquals(true, parser.hasNext()); - assertEquals(true, parser.hasNext()); - assertEquals(Event.END_ARRAY, parser.next()); - - assertEquals(false, parser.hasNext()); - assertEquals(false, parser.hasNext()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - } - } - - - public void testEmptyArrayIterator2Reader() { - try (JsonParser parser = Json.createParser(new StringReader("[]"))) { - testEmptyArrayIterator2(parser); - } - } - - public void testEmptyArrayIterator2Structure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder().build())) { - testEmptyArrayIterator2(parser); - } - } - - static void testEmptyArrayIterator2(JsonParser parser) { - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - } - } - - public void testEmptyArrayIterator3Reader() { - try (JsonParser parser = Json.createParser(new StringReader("[]"))) { - testEmptyArrayIterator3(parser); - } - } - - public void testEmptyArrayIterator3Structure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder().build())) { - testEmptyArrayIterator3(parser); - } - } - - static void testEmptyArrayIterator3(JsonParser parser) { - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - assertEquals(false, parser.hasNext()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - } - } - - - // Tests empty object - public void testEmptyObjectReader() { - try (JsonParser parser = Json.createParser(new StringReader("{}"))) { - testEmptyObject(parser); - } - } - - public void testEmptyObjectStream() { - try (JsonParser parser = Json.createParser( - new ByteArrayInputStream(new byte[]{'{', '}'}))) { - testEmptyObject(parser); - } - } - - public void testEmptyObjectStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder().build())) { - testEmptyObject(parser); - } - } - - public void testEmptyObjectStructureWithConfig() { - Map config = new HashMap<>(); - try (JsonParser parser = Json.createParserFactory(config).createParser( - Json.createObjectBuilder().build())) { - testEmptyObject(parser); - } - } - - @SuppressWarnings("UnusedDeclaration") - static void testEmptyObject(JsonParser parser) { - while (parser.hasNext()) { - parser.next(); - } - } - - - public void testEmptyObjectIteratorReader() { - try (JsonParser parser = Json.createParser(new StringReader("{}"))) { - testEmptyObjectIterator(parser); - } - } - - public void testEmptyObjectIteratorStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder().build())) { - testEmptyObjectIterator(parser); - } - } - - static void testEmptyObjectIterator(JsonParser parser) { - assertEquals(true, parser.hasNext()); - assertEquals(true, parser.hasNext()); - assertEquals(Event.START_OBJECT, parser.next()); - - assertEquals(true, parser.hasNext()); - assertEquals(true, parser.hasNext()); - assertEquals(Event.END_OBJECT, parser.next()); - - assertEquals(false, parser.hasNext()); - assertEquals(false, parser.hasNext()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - } - } - - - public void testEmptyObjectIterator2Reader() { - try (JsonParser parser = Json.createParser(new StringReader("{}"))) { - testEmptyObjectIterator2(parser); - } - } - - public void testEmptyObjectIterator2Structure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder().build())) { - testEmptyObjectIterator2(parser); - } - } - - static void testEmptyObjectIterator2(JsonParser parser) { - assertEquals(Event.START_OBJECT, parser.next()); - assertEquals(Event.END_OBJECT, parser.next()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - } - } - - - public void testEmptyObjectIterator3Reader() { - try (JsonParser parser = Json.createParser(new StringReader("{}"))) { - testEmptyObjectIterator3(parser); - } - } - - public void testEmptyObjectIterator3Structure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createObjectBuilder().build())) { - testEmptyObjectIterator3(parser); - } - } - - static void testEmptyObjectIterator3(JsonParser parser) { - assertEquals(Event.START_OBJECT, parser.next()); - assertEquals(Event.END_OBJECT, parser.next()); - assertEquals(false, parser.hasNext()); - try { - parser.next(); - fail("Should have thrown a NoSuchElementException"); - } catch (NoSuchElementException ne) { - // expected - } - } - - - public void testWikiIteratorReader() throws Exception { - try (JsonParser parser = Json.createParser(wikiReader())) { - testWikiIterator(parser); - } - } - - public void testWikiIteratorStructure() throws Exception { - try (JsonParser parser = Json.createParserFactory(null).createParser( - JsonBuilderTest.buildPerson())) { - testWikiIterator(parser); - } - } - - @SuppressWarnings("UnusedDeclaration") - static void testWikiIterator(JsonParser parser) throws Exception { - while (parser.hasNext()) { - parser.next(); - } - } - - public void testWikiInputStream() throws Exception { - try (JsonParser parser = Json.createParser(wikiStream())) { - testWiki(parser); - } - } - - public void testWikiInputStreamUTF16LE() throws Exception { - ByteArrayInputStream bin = new ByteArrayInputStream(wikiString() - .getBytes(StandardCharsets.UTF_16LE)); - try (JsonParser parser = Json.createParser(bin)) { - testWiki(parser); - } - } - - public void testWikiReader() throws Exception { - try (JsonParser parser = Json.createParser(wikiReader())) { - testWiki(parser); - } - } - - public void testWikiStructure() throws Exception { - try (JsonParser parser = Json.createParserFactory(null).createParser( - JsonBuilderTest.buildPerson())) { - testWiki(parser); - } - } - - static void testWiki(JsonParser parser) { - - Event event = parser.next(); - assertEquals(Event.START_OBJECT, event); - - testObjectStringValue(parser, "firstName", "John"); - testObjectStringValue(parser, "lastName", "Smith"); - - event = parser.next(); - assertEquals(Event.KEY_NAME, event); - assertEquals("age", parser.getString()); - - event = parser.next(); - assertEquals(Event.VALUE_NUMBER, event); - assertEquals(25, parser.getInt()); - assertEquals(25, parser.getLong()); - assertEquals(25, parser.getBigDecimal().intValue()); - assertTrue( parser.isIntegralNumber()); - - event = parser.next(); - assertEquals(Event.KEY_NAME, event); - assertEquals("address", parser.getString()); - - event = parser.next(); - assertEquals(Event.START_OBJECT, event); - - - testObjectStringValue(parser, "streetAddress", "21 2nd Street"); - testObjectStringValue(parser, "city", "New York"); - testObjectStringValue(parser, "state", "NY"); - testObjectStringValue(parser, "postalCode", "10021"); - - event = parser.next(); - assertEquals(Event.END_OBJECT, event); - - event = parser.next(); - assertEquals(Event.KEY_NAME, event); - assertEquals("phoneNumber", parser.getString()); - - event = parser.next(); - assertEquals(Event.START_ARRAY, event); - event = parser.next(); - assertEquals(Event.START_OBJECT, event); - testObjectStringValue(parser, "type", "home"); - testObjectStringValue(parser, "number", "212 555-1234"); - event = parser.next(); - assertEquals(Event.END_OBJECT, event); - - event = parser.next(); - assertEquals(Event.START_OBJECT, event); - testObjectStringValue(parser, "type", "fax"); - testObjectStringValue(parser, "number", "646 555-4567"); - event = parser.next(); - assertEquals(Event.END_OBJECT, event); - event = parser.next(); - assertEquals(Event.END_ARRAY, event); - - event = parser.next(); - assertEquals(Event.END_OBJECT, event); - } - - static void testObjectStringValue(JsonParser parser, String name, String value) { - Event event = parser.next(); - assertEquals(Event.KEY_NAME, event); - assertEquals(name, parser.getString()); - - event = parser.next(); - assertEquals(Event.VALUE_STRING, event); - assertEquals(value, parser.getString()); - } - - public void testNestedArrayReader() { - try (JsonParser parser = Json.createParser(new StringReader("[[],[[]]]"))) { - testNestedArray(parser); - } - } - - public void testNestedArrayStructure() { - try (JsonParser parser = Json.createParserFactory(null).createParser( - Json.createArrayBuilder() - .add(Json.createArrayBuilder()) - .add(Json.createArrayBuilder() - .add(Json.createArrayBuilder())) - .build())) { - testNestedArray(parser); - } - } - - static void testNestedArray(JsonParser parser) { - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.START_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - assertEquals(Event.END_ARRAY, parser.next()); - assertEquals(false, parser.hasNext()); - assertEquals(false, parser.hasNext()); - } - - public void testExceptionsReader() throws Exception { - try (JsonParser parser = Json.createParser(wikiReader())) { - testExceptions(parser); - } - } - - public void testExceptionsStructure() throws Exception { - try (JsonParser parser = Json.createParserFactory(null).createParser( - JsonBuilderTest.buildPerson())) { - testExceptions(parser); - } - } - - static void testExceptions(JsonParser parser) { - - Event event = parser.next(); - assertEquals(Event.START_OBJECT, event); - - try { - parser.getString(); - fail("JsonParser#getString() should have thrown exception in START_OBJECT state"); - } catch (IllegalStateException expected) { - // no-op - } - - try { - parser.isIntegralNumber(); - fail("JsonParser#getNumberType() should have thrown exception in START_OBJECT state"); - } catch (IllegalStateException expected) { - // no-op - } - - try { - parser.getInt(); - fail("JsonParser#getInt() should have thrown exception in START_OBJECT state"); - } catch (IllegalStateException expected) { - // no-op - } - - try { - parser.getLong(); - fail("JsonParser#getLong() should have thrown exception in START_OBJECT state"); - } catch (IllegalStateException expected) { - // no-op - } - - try { - parser.getBigDecimal(); - fail("JsonParser#getBigDecimal() should have thrown exception in START_OBJECT state"); - } catch (IllegalStateException expected) { - // no-op - } - } - - static String wikiString() { - String str; - try (Scanner scanner = new Scanner(wikiReader()) - .useDelimiter("\\A")) { - str = scanner.hasNext() ? scanner.next() : ""; - } - return str; - } - - static InputStream wikiStream() { - return JsonParserTest.class.getResourceAsStream("/wiki.json"); - } - - static Reader wikiReader() { - return new InputStreamReader( - JsonParserTest.class.getResourceAsStream("/wiki.json"), StandardCharsets.UTF_8); - } - - public void testIntNumber() { - JsonParserFactory factory = Json.createParserFactory(null); - - Random r = new Random(System.currentTimeMillis()); - - for(int i=0; i < 100000; i++) { - long num = i%2 == 0 ? r.nextInt() : r.nextLong(); - try (JsonParser parser = factory.createParser(new StringReader("["+num+"]"))) { - parser.next(); - parser.next(); - assertEquals("Fails for num="+num, new BigDecimal(num).intValue(), parser.getInt()); - } - } - - } - - public void testBigDecimalGetString() { - JsonParserFactory f = Json.createParserFactory(null); - JsonObject obj = Json.createObjectBuilder().add("a", BigDecimal.ONE).build(); - try (JsonParser parser = f.createParser(obj)) { - parser.next(); - parser.next(); - parser.next(); - assertEquals("Fails for BigDecimal=1", "1", parser.getString()); - } - } - - public void testIntGetString() { - JsonParserFactory f = Json.createParserFactory(null); - JsonObject obj = Json.createObjectBuilder().add("a", 5).build(); - try (JsonParser parser = f.createParser(obj)) { - parser.next(); - parser.next(); - parser.next(); - assertEquals("Fails for int=5", "5", parser.getString()); - } - } - static class MyBufferPool implements BufferPool { - private boolean takeCalled; - private boolean recycleCalled; - private final char[] buf; - - MyBufferPool(int size) { - buf = new char[size]; - } - - @Override - public char[] take() { - takeCalled = true; - return buf; - } - - @Override - public void recycle(char[] buf) { - recycleCalled = true; - } - - boolean isTakeCalled() { - return takeCalled; - } - - boolean isRecycleCalled() { - return recycleCalled; - } - } - - public void testBufferPoolFeature() { - final MyBufferPool bufferPool = new MyBufferPool(1024); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - - JsonParserFactory factory = Json.createParserFactory(config); - try (JsonParser parser = factory.createParser(new StringReader("[]"))) { - parser.next(); - parser.next(); - } - assertTrue(bufferPool.isTakeCalled()); - assertTrue(bufferPool.isRecycleCalled()); - } - - public void testBufferSizes() { - Random r = new Random(System.currentTimeMillis()); - for(int size=100; size < 1000; size++) { - final MyBufferPool bufferPool = new MyBufferPool(size); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - JsonParserFactory factory = Json.createParserFactory(config); - - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 1000; i++) { - sb.append('a'); - String name = sb.toString(); - long num = i%2 == 0 ? r.nextInt() : r.nextLong(); - String str = "{\""+name+"\":["+num+"]}"; - try (JsonParser parser = factory.createParser(new StringReader(str))) { - parser.next(); - parser.next(); - assertEquals("Fails for " + str, name, parser.getString()); - parser.next(); - parser.next(); - assertEquals("Fails for "+str, new BigDecimal(num).intValue(), parser.getInt()); - } - } - } - } - - // Tests for string starting on buffer boundary (JSONP-15) - // xxxxxxx"xxxxxxxxx" - // ^ - // | - // 4096 - public void testStringUsingStandardBuffer() throws Throwable { - JsonParserFactory factory = Json.createParserFactory(null); - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 40000; i++) { - sb.append('a'); - String name = sb.toString(); - String str = "{\""+name+"\":\""+name+"\"}"; - try (JsonParser parser = factory.createParser(new StringReader(str))) { - parser.next(); - parser.next(); - assertEquals("Fails for size=" + i, name, parser.getString()); - parser.next(); - assertEquals("Fails for size=" + i, name, parser.getString()); - } catch (Throwable e) { - throw new Throwable("Failed for size=" + i, e); - } - } - } - - // Tests for int starting on buffer boundary - // xxxxxxx"xxxxxxxxx" - // ^ - // | - // 4096 - public void testIntegerUsingStandardBuffer() throws Throwable { - Random r = new Random(System.currentTimeMillis()); - JsonParserFactory factory = Json.createParserFactory(null); - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 40000; i++) { - sb.append('a'); - String name = sb.toString(); - int num = r.nextInt(); - String str = "{\"" + name + "\":" + num + "}"; - try (JsonParser parser = factory.createParser(new StringReader(str))) { - parser.next(); - parser.next(); - assertEquals("Fails for size=" + i, name, parser.getString()); - parser.next(); - assertEquals("Fails for size=" + i, num, parser.getInt()); - } catch (Throwable e) { - throw new Throwable("Failed for size=" + i, e); - } - } - } - - public void testStringUsingBuffers() throws Throwable { - for(int size=20; size < 500; size++) { - final MyBufferPool bufferPool = new MyBufferPool(size); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - JsonParserFactory factory = Json.createParserFactory(config); - - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 1000; i++) { - sb.append('a'); - String name = sb.toString(); - String str = "{\""+name+"\":\""+name+"\"}"; - JsonLocation location; - try (JsonParser parser = factory.createParser(new StringReader(str))) { - parser.next(); - parser.next(); - assertEquals("name fails for buffer size=" + size + " name length=" + i, name, parser.getString()); - location = parser.getLocation(); - assertEquals("Stream offset fails for buffer size=" + size + " name length=" + i, - name.length() + 3, location.getStreamOffset()); - assertEquals("Column value fails for buffer size=" + size + " name length=" + i, - name.length() + 4, location.getColumnNumber()); - assertEquals("Line value fails for buffer size=" + size + " name length=" + i, - 1, location.getLineNumber()); - - parser.next(); - assertEquals("value fails for buffer size=" + size + " name length=" + i, name, parser.getString()); - location = parser.getLocation(); - assertEquals("Stream offset fails for buffer size=" + size + " name length=" + i, 2 * name.length() + 6, location.getStreamOffset()); - assertEquals("Column value fails for buffer size=" + size + " name length=" + i, - 2 * name.length() + 7, location.getColumnNumber()); - assertEquals("Line value fails for buffer size=" + size + " name length=" + i, - 1, location.getLineNumber()); - } catch (Throwable e) { - throw new Throwable("Failed for buffer size=" + size + " name length=" + i, e); - } - } - } - } - - public void testExceptionsFromHasNext() { - checkExceptionFromHasNext("{"); - checkExceptionFromHasNext("{\"key\""); - checkExceptionFromHasNext("{\"name\" : \"prop\""); - checkExceptionFromHasNext("{\"name\" : 3"); - checkExceptionFromHasNext("{\"name\" : true"); - checkExceptionFromHasNext("{\"name\" : null"); - checkExceptionFromHasNext("{\"name\" : {\"$eq\":\"cdc\"}"); - checkExceptionFromHasNext("{\"name\" : [{\"$eq\":\"cdc\"}]"); - checkExceptionFromHasNext("["); - checkExceptionFromHasNext("{\"name\" : [{\"key\" : [[{\"a\" : 1}]"); - checkExceptionFromHasNext("{\"unique\":true,\"name\":\"jUnitTestIndexNeg005\", \"fields\":[{\"order\":-1,\"path\":\"city.zip\"}"); - } - - public void testEOFFromHasNext() { - checkExceptionFromHasNext("{ \"d\" : 1 } 2 3 4"); - checkExceptionFromHasNext("[ {\"d\" : 1 }] 2 3 4"); - checkExceptionFromHasNext("1 2 3 4"); - checkExceptionFromHasNext("null 2 3 4"); - } - - public void testExceptionsFromNext() { - checkExceptionFromNext("{\"name\" : fal"); - checkExceptionFromNext("{\"name\" : nu"); - checkExceptionFromNext("{\"name\" : \"pro"); - checkExceptionFromNext("{\"key\":"); - checkExceptionFromNext("fal"); - } - - private void checkExceptionFromHasNext(String input) { - try (JsonParser parser = Json.createParser(new StringReader(input))) { - try { - while (parser.hasNext()) { - try { - parser.next(); - } catch (Throwable t1) { - fail("Exception should occur from hasNext() for '" + input + "'"); - } - } - } catch (JsonParsingException t) { - //this is OK - return; - } - } - fail(); - } - - private void checkExceptionFromNext(String input) { - try (JsonParser parser = Json.createParser(new StringReader(input))) { - while (parser.hasNext()) { - try { - parser.next(); - } catch (JsonParsingException t) { - //this is OK - return; - } - } - } - fail(); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParsingExceptionTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonParsingExceptionTest.java deleted file mode 100644 index 68dba65b..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonParsingExceptionTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.Json; -import jakarta.json.stream.JsonLocation; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParsingException; -import java.io.StringReader; - -/** - * JsonParsingException Tests - * - * @author Jitendra Kotamraju - */ -public class JsonParsingExceptionTest extends TestCase { - - public void testWrongJson() { - // testMalformedJson("", null); Allowed in 1.1 - } - - public void testWrongJson1() { - // testMalformedJson("{}{}", null); Allowed in 1.1 - } - - public void testWrongJson2() { - // testMalformedJson("{", null); Allowed in 1.1 - } - - public void testWrongJson3() { - testMalformedJson("{[]", null); - } - - public void testWrongJson4() { - testMalformedJson("{]", null); - } - - public void testWrongJson5() { - testMalformedJson("{\"a\":[]]", null); - } - - public void testWrongJson6() { - testMalformedJson("[ {}, [] }", null); - } - - public void testWrongJson61() { - testMalformedJson("[ {}, {} }", null); - } - - public void testWrongJson7() { - testMalformedJson("{ \"a\" : {}, \"b\": {} ]", null); - } - - public void testWrongJson8() { - testMalformedJson("{ \"a\" : {}, \"b\": [] ]", null); - } - - public void testWrongUnicode() { - testMalformedJson("[ \"\\uX00F\" ]", null); - testMalformedJson("[ \"\\u000Z\" ]", null); - testMalformedJson("[ \"\\u000\" ]", null); - testMalformedJson("[ \"\\u00\" ]", null); - testMalformedJson("[ \"\\u0\" ]", null); - testMalformedJson("[ \"\\u\" ]", null); - testMalformedJson("[ \"\\u\"", null); - testMalformedJson("[ \"\\", null); - } - - public void testControlChar() { - testMalformedJson("[ \"\u0000\" ]", null); - testMalformedJson("[ \"\u000c\" ]", null); - testMalformedJson("[ \"\u000f\" ]", null); - testMalformedJson("[ \"\u001F\" ]", null); - testMalformedJson("[ \"\u001f\" ]", null); - } - - public void testLocation1() { - testMalformedJson("x", new MyLocation(1, 1, 0)); - testMalformedJson("{]", new MyLocation(1, 2, 1)); - testMalformedJson("[}", new MyLocation(1, 2, 1)); - testMalformedJson("[a", new MyLocation(1, 2, 1)); - testMalformedJson("[nuLl]", new MyLocation(1, 4, 3)); - testMalformedJson("[falsE]", new MyLocation(1, 6, 5)); - // testMalformedJson("[][]", new MyLocation(1, 3, 2)); allowed in 1.1 - testMalformedJson("[1234L]", new MyLocation(1, 6, 5)); - } - - public void testLocation2() { - testMalformedJson("[null\n}", new MyLocation(2, 1, 6)); - testMalformedJson("[null\r\n}", new MyLocation(2, 1, 7)); - testMalformedJson("[null\n, null\n}", new MyLocation(3, 1, 13)); - testMalformedJson("[null\r\n, null\r\n}", new MyLocation(3, 1, 15)); - } - - private void testMalformedJson(String json, JsonLocation expected) { - try (JsonParser parser = Json.createParser(new StringReader(json))) { - while (parser.hasNext()) { - parser.next(); - } - fail("Expected to throw JsonParsingException for " + json); - } catch (JsonParsingException je) { - // Expected - if (expected != null) { - JsonLocation got = je.getLocation(); - assertEquals(expected.getLineNumber(), got.getLineNumber()); - assertEquals(expected.getColumnNumber(), got.getColumnNumber()); - assertEquals(expected.getStreamOffset(), got.getStreamOffset()); - } - } - } - - private static class MyLocation implements JsonLocation { - private final long columnNo; - private final long lineNo; - private final long streamOffset; - - MyLocation(long lineNo, long columnNo, long streamOffset) { - this.lineNo = lineNo; - this.columnNo = columnNo; - this.streamOffset = streamOffset; - } - - @Override - public long getLineNumber() { - return lineNo; - } - - @Override - public long getColumnNumber() { - return columnNo; - } - - @Override - public long getStreamOffset() { - return streamOffset; - } - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBugsTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBugsTest.java deleted file mode 100644 index 61197835..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBugsTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonException; -import jakarta.json.JsonPatch; -import jakarta.json.JsonReader; -import jakarta.json.JsonStructure; - -import java.io.StringReader; - -import org.junit.Test; - -/** - * - * @author lukas - */ -public class JsonPatchBugsTest { - - // https://github.com/javaee/jsonp/issues/58 - @Test(expected = JsonException.class) - public void applyThrowsJsonException() { - JsonArray array = Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("name", "Bob") - .build()) - .build(); - JsonPatch patch = Json.createPatchBuilder() - .replace("/0/name", "Bobek") - .replace("/1/name", "Vila Amalka") - .build(); - JsonArray result = patch.apply(array); - } - - // https://github.com/eclipse-ee4j/jsonp/issues/181 - @Test(expected = JsonException.class) - public void applyThrowsJsonException2() { - // JSON document to be patched - String targetDocument - = "{\n" - + " \"firstName\": \"John\",\n" - + " \"lastName\": \"Doe\"\n" - + "}"; - - // JSON Patch document - // Instead of "op", we have "op_", which is invalid - String patchDocument - = "[\n" - + " { \"op_\": \"replace\", \"path\": \"/firstName\", \"value\": \"Jane\" }\n" - + "]"; - - try (JsonReader objectReader = Json.createReader(new StringReader(targetDocument)); - JsonReader arrayReader = Json.createReader(new StringReader(patchDocument))) { - - JsonStructure target = objectReader.read(); - JsonPatch patch = Json.createPatch(arrayReader.readArray()); - - // Applies the patch - // It will throw a NullPointerException with no message - JsonStructure patched = patch.apply(target); - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBuilderTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBuilderTest.java deleted file mode 100644 index 4a8e3796..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchBuilderTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonPatchBuilder; - -import org.junit.Test; - -/** - * - * @author Alex Soto - * - */ -public class JsonPatchBuilderTest { - - @Test - public void shouldBuildJsonPatchExpressionUsingJsonPatchBuilder() { - JsonPatchBuilder patchBuilder = Json.createPatchBuilder(); - JsonObject result = patchBuilder.add("/email", "john@example.com") - .replace("/age", 30) - .remove("/phoneNumber") - .test("/firstName", "John") - .copy("/address/lastName", "/lastName") - .build() - .apply(buildPerson()); - assertThat(result, is(expectedBuildPerson())); - - } - - static JsonObject expectedBuildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("email", "john@example.com") - .add("age", 30) - .add("address", Json.createObjectBuilder() - .add("lastName", "Smith") - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .build(); - } - - static JsonObject buildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchDiffTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchDiffTest.java deleted file mode 100644 index 90df95ed..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchDiffTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonPatch; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPatchDiffTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - List examples = new ArrayList<>(); - JsonArray data = JsonPatchDiffTest.loadData(); - for (JsonValue jsonValue : data) { - JsonObject test = (JsonObject) jsonValue; - Object[] testData = new Object[4]; - testData[0] = test.get("original"); - testData[1] = test.get("target"); - testData[2] = test.get("expected"); - testData[3] = createExceptionClass((JsonString)test.get("exception")); - - examples.add(testData); - } - - return examples; - } - - private static Class createExceptionClass( - JsonString exceptionClassName) throws ClassNotFoundException { - if (exceptionClassName != null) { - return (Class) Class - .forName(exceptionClassName.getString()); - } - return null; - } - - private static JsonArray loadData() { - InputStream testData = JsonPatchTest.class - .getResourceAsStream("/jsonpatchdiff.json"); - - JsonArray data; - try(JsonReader reader = Json.createReader(testData)){ - data = (JsonArray) reader.read(); - } - - return data; - } - - private JsonStructure original; - private JsonStructure target; - private JsonValue expected; - private Class expectedException; - - public JsonPatchDiffTest(JsonStructure original, JsonStructure target, - JsonValue expected, Class expectedException) { - super(); - this.original = original; - this.target = target; - this.expected = expected; - this.expectedException = expectedException; - } - - @Test - public void shouldExecuteJsonPatchDiffOperationsToJsonDocument() { - try { - JsonPatch diff = Json.createDiff(this.original, this.target); - assertThat(diff, is(Json.createPatchBuilder((JsonArray) expected).build())); - assertThat(expectedException, nullValue()); - } catch (Exception e) { - if (expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchOperationTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchOperationTest.java deleted file mode 100644 index 1d03df4d..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchOperationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import jakarta.json.JsonException; -import jakarta.json.JsonPatch.Operation; -import org.junit.Assert; -import org.junit.Test; - -/** - * - * @author lukas - */ -public class JsonPatchOperationTest { - - private static final String[] opNames = {"add", "remove", "replace", "move", "copy", "test"}; - - @Test - public void fromOperationName() { - for (String op: opNames) { - Assert.assertEquals(Operation.valueOf(op.toUpperCase()), Operation.fromOperationName(op)); - } - for (String op: opNames) { - Assert.assertEquals(Operation.valueOf(op.toUpperCase()), Operation.fromOperationName(op.toUpperCase())); - } - } - - @Test(expected = JsonException.class) - public void fromInvalidOperationName() { - Operation.fromOperationName("undef"); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchTest.java deleted file mode 100644 index 065ce127..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPatchTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonPatch; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPatchTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - List examples = new ArrayList<>(); - JsonArray data = loadData(); - for (JsonValue jsonValue : data) { - JsonObject test = (JsonObject) jsonValue; - Object[] testData = new Object[4]; - testData[0] = createPatchArray(test.get("op")); - testData[1] = test.get("target"); - testData[2] = test.get("expected"); - testData[3] = createExceptionClass((JsonString)test.get("exception")); - - examples.add(testData); - } - - return examples; - } - - private static Class createExceptionClass( - JsonString exceptionClassName) throws ClassNotFoundException { - if (exceptionClassName != null) { - return (Class) Class - .forName(exceptionClassName.getString()); - } - return null; - } - - private static JsonArray createPatchArray(JsonValue object) { - return Json.createArrayBuilder().add(object).build(); - } - - private static JsonArray loadData() { - InputStream testData = JsonPatchTest.class - .getResourceAsStream("/jsonpatch.json"); - JsonReader reader = Json.createReader(testData); - return (JsonArray) reader.read(); - } - - private JsonArray patch; - private JsonStructure target; - private JsonValue expected; - private Class expectedException; - - public JsonPatchTest(JsonArray patch, JsonStructure target, - JsonValue expected, Class expectedException) { - super(); - this.patch = patch; - this.target = target; - this.expected = expected; - this.expectedException = expectedException; - } - - @Test - public void shouldExecuteJsonPatchOperationsToJsonDocument() { - try { - JsonPatch patch = Json.createPatchBuilder(this.patch).build(); - JsonStructure output = patch.apply(target); - assertThat(output, is(expected)); - assertThat(expectedException, nullValue()); - } catch (Exception e) { - if (expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerAddOperationTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerAddOperationTest.java deleted file mode 100644 index 81da0aeb..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerAddOperationTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonPointer; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPointerAddOperationTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - return Arrays.asList(new Object[][] { - {buildSimpleAddPatch(), buildAddress(), buildExpectedAddress() }, - {buildComplexAddPatch(), buildPerson(), buildExpectedPerson()}, - {buildArrayAddPatchInPosition(), buildPerson(), buildExpectedPersonConcreteArrayPosition()}, - {buildArrayAddPatchInLastPosition(), buildPerson(), buildExpectedPersonArrayLastPosition()} - }); - } - - private JsonObject pathOperation; - private JsonStructure target; - private JsonValue expectedResult; - - public JsonPointerAddOperationTest(JsonObject pathOperation, - JsonStructure target, JsonValue expectedResult) { - super(); - this.pathOperation = pathOperation; - this.target = target; - this.expectedResult = expectedResult; - } - - @Test - public void shouldAddElementsToExistingJsonDocument() { - JsonPointer pointer = Json.createPointer(pathOperation.getString("path")); - JsonObject modified = (JsonObject) pointer.add(target, pathOperation.get("value")); - assertThat(modified, is(expectedResult)); - } - - static JsonObject buildAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildComplexAddPatch() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/address/streetAddress") - .add("value", "myaddress") - .build(); - } - static JsonObject buildSimpleAddPatch() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/streetAddress") - .add("value", "myaddress") - .build(); - } - static JsonObject buildArrayAddPatchInPosition() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/phoneNumber/0") - .add("value", Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234")) - .build(); - } - static JsonObject buildArrayAddPatchInLastPosition() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/phoneNumber/-") - .add("value", Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234")) - .build(); - } - static JsonObject buildExpectedAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "myaddress") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildExpectedPersonConcreteArrayPosition() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add((Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234"))) - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildExpectedPersonArrayLastPosition() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567")) - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234"))) - .build(); - } - static JsonObject buildExpectedPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "myaddress") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerEscapeTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerEscapeTest.java deleted file mode 100644 index 0ef8c4ed..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerEscapeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import org.junit.Test; - -import jakarta.json.Json; - -import static org.junit.Assert.assertEquals; - -/** - * JSON pointer escape/unescape tests. - * - * @author Dmitry Kornilov - */ -public class JsonPointerEscapeTest { - - @Test - public void escapeTest() { - assertEquals("a~1b", Json.encodePointer("a/b")); - assertEquals("a~0b~1c", Json.encodePointer("a~b/c")); - } - - @Test - public void unescapeTest() { - assertEquals("/a/b", Json.decodePointer("/a~1b")); - assertEquals("/~1", Json.decodePointer("/~01")); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerRemoveOperationTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerRemoveOperationTest.java deleted file mode 100644 index d696606c..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerRemoveOperationTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonPointer; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPointerRemoveOperationTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - return Arrays.asList(new Object[][] { - {buildSimpleRemovePatch(), buildAddress(), buildExpectedRemovedAddress() }, - {buildComplexRemovePatch(), buildPerson(), buildExpectedPersonWithoutStreetAddress()}, - {buildArrayRemovePatchInPosition(), buildPerson(), buildPersonWithoutFirstPhone()} - }); - } - - private JsonObject pathOperation; - private JsonStructure target; - private JsonValue expectedResult; - - public JsonPointerRemoveOperationTest(JsonObject pathOperation, - JsonObject target, JsonValue expectedResult) { - super(); - this.pathOperation = pathOperation; - this.target = target; - this.expectedResult = expectedResult; - } - - @Test - public void shouldRemoveElementsToExistingJsonDocument() { - JsonPointer pointer = Json.createPointer(pathOperation.getString("path")); - JsonObject modified = (JsonObject) pointer.remove(target); - assertThat(modified, is(expectedResult)); - } - - static JsonObject buildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildComplexRemovePatch() { - return Json.createObjectBuilder() - .add("op", "remove") - .add("path", "/address/streetAddress") - .build(); - } - static JsonObject buildSimpleRemovePatch() { - return Json.createObjectBuilder() - .add("op", "remove") - .add("path", "/streetAddress") - .build(); - } - static JsonObject buildArrayRemovePatchInPosition() { - return Json.createObjectBuilder() - .add("op", "remove") - .add("path", "/phoneNumber/0") - .build(); - } - static JsonObject buildExpectedRemovedAddress() { - return Json.createObjectBuilder() - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildPersonWithoutFirstPhone() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildExpectedPersonWithoutStreetAddress() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerReplaceOperationTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerReplaceOperationTest.java deleted file mode 100644 index e4ae08bb..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerReplaceOperationTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.util.Arrays; - -import jakarta.json.Json; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonPointer; -import jakarta.json.JsonStructure; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPointerReplaceOperationTest { - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - return Arrays.asList(new Object[][] { - {buildSimpleReplacePatch(), buildAddress(), buildExpectedAddress(), null}, - {buildComplexReplacePatch(), buildPerson(), buildExpectedPerson(), null}, - {buildArrayReplacePatchInPosition(), buildPerson(), buildExpectedPersonConcreteArrayPosition(), null}, - {buildArrayAddPatchInLastPosition(), buildPerson(), null, JsonException.class}, - {buildNoneExistingReplacePatch(), buildAddress(), null, JsonException.class} - }); - } - - private JsonObject pathOperation; - private JsonStructure target; - private JsonValue expectedResult; - private Class expectedException; - - public JsonPointerReplaceOperationTest(JsonObject pathOperation, - JsonStructure target, JsonValue expectedResult, Class expectedException) { - super(); - this.pathOperation = pathOperation; - this.target = target; - this.expectedResult = expectedResult; - this.expectedException = expectedException; - } - - @Test - public void shouldReplaceElementsToExistingJsonDocument() { - try { - JsonPointer pointer = Json.createPointer(pathOperation.getString("path")); - JsonObject modified = (JsonObject) pointer.replace(target, pathOperation.get("value")); - assertThat(modified, is(expectedResult)); - assertThat(expectedException, nullValue()); - } catch(Exception e) { - if(expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } - - static JsonObject buildAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildComplexReplacePatch() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/address/streetAddress") - .add("value", "myaddress") - .build(); - } - static JsonObject buildSimpleReplacePatch() { - return Json.createObjectBuilder() - .add("op", "replace") - .add("path", "/streetAddress") - .add("value", "myaddress") - .build(); - } - static JsonObject buildNoneExistingReplacePatch() { - return Json.createObjectBuilder() - .add("op", "replace") - .add("path", "/notexists") - .add("value", "myaddress") - .build(); - } - static JsonObject buildArrayReplacePatchInPosition() { - return Json.createObjectBuilder() - .add("op", "replace") - .add("path", "/phoneNumber/0") - .add("value", Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234")) - .build(); - } - static JsonObject buildArrayAddPatchInLastPosition() { - return Json.createObjectBuilder() - .add("op", "add") - .add("path", "/phoneNumber/-") - .add("value", Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234")) - .build(); - } - static JsonObject buildExpectedAddress() { - return Json.createObjectBuilder() - .add("streetAddress", "myaddress") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021") - .build(); - } - static JsonObject buildPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildExpectedPersonConcreteArrayPosition() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "21 2nd Street") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add((Json.createObjectBuilder() - .add("type", "home") - .add("number", "200 555-1234"))) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - static JsonObject buildExpectedPerson() { - return Json.createObjectBuilder() - .add("firstName", "John") - .add("lastName", "Smith") - .add("age", 25) - .add("address", Json.createObjectBuilder() - .add("streetAddress", "myaddress") - .add("city", "New York") - .add("state", "NY") - .add("postalCode", "10021")) - .add("phoneNumber", Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("type", "home") - .add("number", "212 555-1234")) - .add(Json.createObjectBuilder() - .add("type", "fax") - .add("number", "646 555-4567"))) - .build(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerTest.java deleted file mode 100644 index 7650f70c..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.instanceOf; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.Arrays; - -import jakarta.json.Json; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonPointer; -import jakarta.json.JsonReader; -import jakarta.json.JsonValue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * - * @author Alex Soto - * - */ -@RunWith(Parameterized.class) -public class JsonPointerTest { - - private static JsonObject rfc6901Example; - - @Parameters(name = "{index}: ({0})={1}") - public static Iterable data() throws Exception { - rfc6901Example = JsonPointerTest.readRfc6901Example(); - return Arrays.asList(new Object[][] { - {Json.createPointer(""), rfc6901Example, null }, - {Json.createPointer("/foo"), rfc6901Example.getJsonArray("foo"), null}, - {Json.createPointer("/foo/0"), rfc6901Example.getJsonArray("foo").get(0), null}, - {Json.createPointer("/foo/5"), null, JsonException.class}, - {Json.createPointer("/p/1"), null, JsonException.class}, - {Json.createPointer("/"), rfc6901Example.getJsonNumber(""), null}, - {Json.createPointer("/a~1b"), rfc6901Example.getJsonNumber("a/b"), null}, - {Json.createPointer("/m~0n"), rfc6901Example.getJsonNumber("m~n"), null}, - {Json.createPointer("/c%d"), rfc6901Example.getJsonNumber("c%d"), null}, - {Json.createPointer("/e^f"), rfc6901Example.getJsonNumber("e^f"), null}, - {Json.createPointer("/g|h"), rfc6901Example.getJsonNumber("g|h"), null}, - {Json.createPointer("/i\\j"), rfc6901Example.getJsonNumber("i\\j"), null}, - {Json.createPointer("/k\"l"), rfc6901Example.getJsonNumber("k\"l"), null}, - {Json.createPointer("/ "), rfc6901Example.getJsonNumber(" "), null}, - {Json.createPointer("/notexists"), null, JsonException.class}, - {Json.createPointer("/s/t"), null, JsonException.class}, - {Json.createPointer("/o"), JsonObject.NULL, null} - }); - } - - private JsonPointer pointer; - private JsonValue expected; - private Class expectedException; - - public JsonPointerTest(JsonPointer pointer, JsonValue expected, Class expectedException) { - super(); - this.pointer = pointer; - this.expected = expected; - this.expectedException = expectedException; - } - - @Test - public void shouldEvaluateJsonPointerExpressions() { - try { - JsonValue result = pointer.getValue(rfc6901Example); - assertThat(result, is(expected)); - assertThat(expectedException, nullValue()); - } catch(Exception e) { - if(expectedException == null) { - fail(e.getMessage()); - } else { - assertThat(e, instanceOf(expectedException)); - } - } - } - - static JsonObject readRfc6901Example() throws Exception { - Reader rfc6901Reader = new InputStreamReader(JsonReaderTest.class.getResourceAsStream("/rfc6901.json")); - JsonReader reader = Json.createReader(rfc6901Reader); - JsonValue value = reader.readObject(); - reader.close(); - return (JsonObject) value; - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerToStringTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerToStringTest.java deleted file mode 100644 index 66c5d1e6..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonPointerToStringTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; - -import java.util.Arrays; - -import jakarta.json.Json; -import jakarta.json.JsonPointer; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** - * JSON pointer toString tests. - * - * @author leadpony - */ -@RunWith(Parameterized.class) -public class JsonPointerToStringTest { - - @Parameters(name = "{index}: {0}") - public static Iterable data() { - return Arrays.asList("", "/", "/one/two/3", "/a~1b", "/m~0n"); - } - - private final String expected; - - public JsonPointerToStringTest(String expected) { - this.expected = expected; - } - - @Test - public void shouldReturnOriginalEscapedString() { - JsonPointer pointer = Json.createPointer(expected); - assertThat(pointer.toString(), is(equalTo(expected))); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonReaderTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonReaderTest.java deleted file mode 100644 index 955fc630..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonReaderTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.math.BigInteger; -import java.util.HashMap; -import java.util.Map; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonNumber; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonReaderFactory; -import jakarta.json.JsonValue; - -import org.eclipse.jsonp.api.BufferPool; - -import junit.framework.TestCase; - -/** - * @author Jitendra Kotamraju - */ -public class JsonReaderTest extends TestCase { - public JsonReaderTest(String testName) { - super(testName); - } - - public void testObject() throws Exception { - JsonObject person = readPerson(); - JsonObjectTest.testPerson(person); - } - - public void testEscapedString() throws Exception { - // u00ff is escaped once, not escaped once - JsonReader reader = Json.createReader(new StringReader("[\"\\u0000\\u00ff\u00ff\"]")); - JsonArray array = reader.readArray(); - reader.close(); - String str = array.getString(0); - assertEquals("\u0000\u00ff\u00ff", str); - } - - public void testPrimitiveIntNumbers() { - String[] borderlineCases = new String[]{ - "214748364", - Integer.toString(Integer.MAX_VALUE), - Long.toString(Integer.MAX_VALUE + 1L), - "-214748364", - Integer.toString(Integer.MIN_VALUE), - Long.toString(Integer.MIN_VALUE - 1L) - }; - for (String num : borderlineCases) { - JsonReader reader = Json.createReader(new StringReader("["+num+"]")); - try { - JsonArray array = reader.readArray(); - JsonNumber value = (JsonNumber) array.get(0); - assertEquals("Fails for num="+num, new BigInteger(num).longValue(), value.longValue()); - } finally { - reader.close(); - } - } - } - - public void testPrimitiveLongNumbers() { - String[] borderlineCases = new String[]{ - "922337203685477580", - Long.toString(Long.MAX_VALUE), - new BigInteger(Long.toString(Long.MAX_VALUE)).add(BigInteger.ONE).toString(), - "-922337203685477580", - Long.toString(Long.MIN_VALUE), - new BigInteger(Long.toString(Long.MIN_VALUE)).subtract(BigInteger.ONE).toString() - }; - for (String num : borderlineCases) { - JsonReader reader = Json.createReader(new StringReader("["+num+"]")); - try { - JsonArray array = reader.readArray(); - JsonNumber value = (JsonNumber) array.get(0); - assertEquals("Fails for num="+num, new BigInteger(num), value.bigIntegerValueExact()); - } finally { - reader.close(); - } - } - } - - public void testUnknownFeature() throws Exception { - Map config = new HashMap<>(); - config.put("foo", true); - JsonReaderFactory factory = Json.createReaderFactory(config); - factory.createReader(new StringReader("{}")); - Map config1 = factory.getConfigInUse(); - if (config1.size() > 0) { - fail("Shouldn't have any config in use"); - } - } - - public void testIllegalStateExcepton() throws Exception { - JsonReader reader = Json.createReader(new StringReader("{}")); - reader.readObject(); - try { - reader.readObject(); - } catch (IllegalStateException expected) { - // no-op - } - reader.close(); - - reader = Json.createReader(new StringReader("[]")); - reader.readArray(); - try { - reader.readArray(); - } catch (IllegalStateException expected) { - // no-op - } - reader.close(); - - reader = Json.createReader(new StringReader("{}")); - reader.read(); - try { - reader.read(); - } catch (IllegalStateException expected) { - // no-op - } - reader.close(); - } - - static JsonObject readPerson() throws Exception { - Reader wikiReader = new InputStreamReader(JsonReaderTest.class.getResourceAsStream("/wiki.json")); - JsonReader reader = Json.createReader(wikiReader); - JsonValue value = reader.readObject(); - reader.close(); - return (JsonObject) value; - } - - // JSONP-23 cached empty string is not reset - public void testEmptyStringUsingStandardBuffer() throws Throwable { - JsonReaderFactory factory = Json.createReaderFactory(null); - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 40000; i++) { - sb.append('a'); - String name = sb.toString(); - String str = "[1, \"\", \""+name+"\", \"\", \""+name+"\", \"\", 100]"; - try { - JsonReader reader = factory.createReader(new StringReader(str)); - JsonArray array = reader.readArray(); - assertEquals(1, array.getInt(0)); - assertEquals("", array.getString(1)); - assertEquals(name, array.getString(2)); - assertEquals("", array.getString(3)); - assertEquals(name, array.getString(4)); - assertEquals("", array.getString(5)); - assertEquals(100, array.getInt(6)); - reader.close(); - } catch (Throwable t) { - throw new Throwable("Failed for name length="+i, t); - } - } - } - - // JSONP-23 cached empty string is not reset - public void testEmptyStringUsingBuffers() throws Throwable { - for(int size=20; size < 500; size++) { - final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(size); - Map config = new HashMap() {{ - put(BufferPool.class.getName(), bufferPool); - }}; - JsonReaderFactory factory = Json.createReaderFactory(config); - - StringBuilder sb = new StringBuilder(); - for(int i=0; i < 1000; i++) { - sb.append('a'); - String name = sb.toString(); - String str = "[1, \"\", \""+name+"\", \"\", \""+name+"\", \"\", 100]"; - try { - JsonReader reader = factory.createReader(new StringReader(str)); - JsonArray array = reader.readArray(); - assertEquals(1, array.getInt(0)); - assertEquals("", array.getString(1)); - assertEquals(name, array.getString(2)); - assertEquals("", array.getString(3)); - assertEquals(name, array.getString(4)); - assertEquals("", array.getString(5)); - assertEquals(100, array.getInt(6)); - reader.close(); - } catch (Throwable t) { - throw new Throwable("Failed for buffer size="+size+" name length="+i, t); - } - } - } - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonSamplesParsingTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonSamplesParsingTest.java deleted file mode 100644 index 8bbe5f87..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonSamplesParsingTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.Json; -import jakarta.json.JsonException; -import jakarta.json.stream.JsonParser; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; - -/** - * JsonParser tests for sample files - * - * @author Jitendra Kotamraju - */ -public class JsonSamplesParsingTest extends TestCase { - - public void testSampleFiles() { - String[] fileNames = { - "facebook.json", "facebook1.json", "facebook2.json", - "twitter.json" - }; - for(String fileName: fileNames) { - try { - testSampleFile(fileName); - } catch(Exception e) { - throw new JsonException("Exception while parsing "+fileName, e); - } - } - } - - private void testSampleFile(String fileName) { - Reader reader = new InputStreamReader( - JsonSamplesParsingTest.class.getResourceAsStream("/"+fileName), StandardCharsets.UTF_8); - JsonParser parser = null; - try { - parser = Json.createParser(reader); - while(parser.hasNext()) { - parser.next(); - } - } finally { - if (parser != null) { - parser.close(); - } - } - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonStringTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonStringTest.java deleted file mode 100644 index 4279ef42..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonStringTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import java.io.StringReader; - -/** - * @author Jitendra Kotamraju - */ -public class JsonStringTest extends TestCase { - public JsonStringTest(String testName) { - super(testName); - } - - // tests JsonString#toString() - public void testToString() throws Exception { - escapedString(""); - escapedString("abc"); - escapedString("abc\f"); - escapedString("abc\na"); - escapedString("abc\tabc"); - escapedString("abc\n\tabc"); - escapedString("abc\n\tabc\r"); - escapedString("\n\tabc\r"); - escapedString("\bab\tb\rc\\\"\ftesting1234"); - escapedString("\f\babcdef\tb\rc\\\"\ftesting1234"); - escapedString("\u0000\u00ff"); - escapedString("abc\"\\/abc"); - } - - public void testHashCode() { - String string1 = new String("a"); - JsonString jsonString1 = Json.createValue(string1); - assertTrue(jsonString1.hashCode() == jsonString1.getString().hashCode()); - - String string2 = new String("a"); - JsonString jsonString2 = Json.createValue(string2); - - assertTrue(jsonString1.equals(jsonString2)); - assertTrue(jsonString1.hashCode() == jsonString2.hashCode()); - } - - void escapedString(String str) throws Exception { - JsonArray exp = Json.createArrayBuilder().add(str).build(); - String parseStr = "["+exp.get(0).toString()+"]"; - JsonReader jr = Json.createReader(new StringReader(parseStr)); - JsonArray got = jr.readArray(); - assertEquals(exp, got); - jr.close(); - } - -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonValueTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonValueTest.java deleted file mode 100644 index 1f7b7093..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonValueTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collections; -import jakarta.json.JsonObject; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; -import org.junit.Assert; -import org.junit.Test; - -/** - * - * @author Lukas Jungmann - */ -public class JsonValueTest { - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetJsonObjectIdx() { - JsonValue.EMPTY_JSON_ARRAY.getJsonObject(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetJsonArrayIdx() { - JsonValue.EMPTY_JSON_ARRAY.getJsonArray(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetJsonNumberIdx() { - JsonValue.EMPTY_JSON_ARRAY.getJsonNumber(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetJsonStringIdx() { - JsonValue.EMPTY_JSON_ARRAY.getJsonString(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetStringIdx() { - JsonValue.EMPTY_JSON_ARRAY.getString(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetIntIdx() { - JsonValue.EMPTY_JSON_ARRAY.getInt(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayGetBooleanIdx() { - JsonValue.EMPTY_JSON_ARRAY.getBoolean(0); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void arrayIsNull() { - JsonValue.EMPTY_JSON_ARRAY.isNull(0); - } - - @Test - public void arrayMethods() { - Assert.assertEquals(JsonValue.ValueType.ARRAY, JsonValue.EMPTY_JSON_ARRAY.getValueType()); - Assert.assertEquals(Collections.emptyList(), JsonValue.EMPTY_JSON_ARRAY.getValuesAs(JsonObject.class)); - Assert.assertEquals(Collections.emptyList(), JsonValue.EMPTY_JSON_ARRAY.getValuesAs(JsonString::getString)); - Assert.assertEquals(true, JsonValue.EMPTY_JSON_ARRAY.getBoolean(0, true)); - Assert.assertEquals(42, JsonValue.EMPTY_JSON_ARRAY.getInt(0, 42)); - Assert.assertEquals("Sasek", JsonValue.EMPTY_JSON_ARRAY.getString(0, "Sasek")); - } - - @Test(expected = UnsupportedOperationException.class) - public void arrayIsImmutable() { - JsonValue.EMPTY_JSON_ARRAY.add(JsonValue.EMPTY_JSON_OBJECT); - } - - @Test(expected = NullPointerException.class) - public void objectGetString() { - JsonValue.EMPTY_JSON_OBJECT.getString("normalni string"); - } - - @Test(expected = NullPointerException.class) - public void objectGetInt() { - JsonValue.EMPTY_JSON_OBJECT.getInt("hledej cislo"); - } - - @Test(expected = NullPointerException.class) - public void objectGetBoolean() { - JsonValue.EMPTY_JSON_OBJECT.getBoolean("booo"); - } - - @Test(expected = NullPointerException.class) - public void objectIsNull() { - JsonValue.EMPTY_JSON_OBJECT.isNull("???"); - } - - @Test - public void objectMethods() { - Assert.assertNull(JsonValue.EMPTY_JSON_OBJECT.getJsonArray("pole")); - Assert.assertNull(JsonValue.EMPTY_JSON_OBJECT.getJsonObject("objekt")); - Assert.assertNull(JsonValue.EMPTY_JSON_OBJECT.getJsonNumber("cislo")); - Assert.assertNull(JsonValue.EMPTY_JSON_OBJECT.getJsonString("divnej string")); - - Assert.assertEquals("ja jo", JsonValue.EMPTY_JSON_OBJECT.getString("nejsem tu", "ja jo")); - Assert.assertEquals(false, JsonValue.EMPTY_JSON_OBJECT.getBoolean("najdes mne", false)); - Assert.assertEquals(98, JsonValue.EMPTY_JSON_OBJECT.getInt("spatnej dotaz", 98)); - } - - - @Test(expected = UnsupportedOperationException.class) - public void objectImmutable() { - JsonValue.EMPTY_JSON_OBJECT.put("klauni", JsonValue.EMPTY_JSON_ARRAY); - } - - @Test - public void serialization() { - byte[] data = serialize(JsonValue.TRUE); - JsonValue value = deserialize(JsonValue.class, data); - Assert.assertEquals(JsonValue.TRUE, value); - - data = serialize(JsonValue.FALSE); - value = deserialize(JsonValue.class, data); - Assert.assertEquals(JsonValue.FALSE, value); - - data = serialize(JsonValue.NULL); - value = deserialize(JsonValue.class, data); - Assert.assertEquals(JsonValue.NULL, value); - - data = serialize(JsonValue.EMPTY_JSON_ARRAY); - value = deserialize(JsonValue.class, data); - Assert.assertEquals(JsonValue.EMPTY_JSON_ARRAY, value); - - data = serialize(JsonValue.EMPTY_JSON_OBJECT); - value = deserialize(JsonValue.class, data); - Assert.assertEquals(JsonValue.EMPTY_JSON_OBJECT, value); - } - - private byte[] serialize(Object o) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { - oos.writeObject(o); - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - return baos.toByteArray(); - } - - private T deserialize(Class type, byte[] data) { - ByteArrayInputStream bais = new ByteArrayInputStream(data); - try (ObjectInputStream ois = new ObjectInputStream(bais)) { - return (T) ois.readObject(); - } catch (IOException | ClassNotFoundException e) { - throw new RuntimeException(e); - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/JsonWriterTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/JsonWriterTest.java deleted file mode 100644 index 6e2aa86c..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/JsonWriterTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import jakarta.json.*; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.StringWriter; - -import junit.framework.TestCase; - -/** - * @author Jitendra Kotamraju - */ -public class JsonWriterTest extends TestCase { - public JsonWriterTest(String testName) { - super(testName); - } - - public void testObject() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.writeObject(Json.createObjectBuilder().build()); - jsonWriter.close(); - writer.close(); - - assertEquals("{}", writer.toString()); - } - - public void testEmptyObject() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write(JsonValue.EMPTY_JSON_OBJECT); - jsonWriter.close(); - writer.close(); - - assertEquals("{}", writer.toString()); - } - - public void testArray() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.writeArray(Json.createArrayBuilder().build()); - jsonWriter.close(); - writer.close(); - - assertEquals("[]", writer.toString()); - } - - public void testEmptyArray() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write(JsonValue.EMPTY_JSON_ARRAY); - jsonWriter.close(); - writer.close(); - - assertEquals("[]", writer.toString()); - } - - public void testNumber() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.writeArray(Json.createArrayBuilder().add(10).build()); - jsonWriter.close(); - writer.close(); - - assertEquals("[10]", writer.toString()); - } - - public void testDoubleNumber() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.writeArray(Json.createArrayBuilder().add(10.5).build()); - jsonWriter.close(); - writer.close(); - - assertEquals("[10.5]", writer.toString()); - } - - public void testArrayString() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.writeArray(Json.createArrayBuilder().add("string").build()); - jsonWriter.close(); - writer.close(); - - assertEquals("[\"string\"]", writer.toString()); - } - - public void testObjectAsValue() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write((JsonValue) (Json.createObjectBuilder().build())); - jsonWriter.close(); - writer.close(); - - assertEquals("{}", writer.toString()); - } - - public void testNullValue() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write(JsonValue.NULL); - jsonWriter.close(); - writer.close(); - - assertEquals("null", writer.toString()); - } - - public void testTrueValue() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write(JsonValue.TRUE); - jsonWriter.close(); - writer.close(); - - assertEquals("true", writer.toString()); - } - - public void testFalseValue() throws Exception { - StringWriter writer = new StringWriter(); - JsonWriter jsonWriter = Json.createWriter(writer); - jsonWriter.write(JsonValue.FALSE); - jsonWriter.close(); - writer.close(); - - assertEquals("false", writer.toString()); - } - - public void testIllegalStateExcepton() throws Exception { - JsonObject obj = Json.createObjectBuilder().build(); - JsonArray array = Json.createArrayBuilder().build(); - - JsonWriter writer = Json.createWriter(new StringWriter()); - writer.writeObject(obj); - try { - writer.writeObject(obj); - } catch (IllegalStateException expected) { - // no-op - } - writer.close(); - - writer = Json.createWriter(new StringWriter()); - writer.writeArray(array); - try { - writer.writeArray(array); - } catch (IllegalStateException expected) { - // no-op - } - writer.close(); - - writer = Json.createWriter(new StringWriter()); - writer.write(array); - try { - writer.writeArray(array); - } catch (IllegalStateException expected) { - // no-op - } - writer.close(); - } - - public void testNoCloseWriteObjectToStream() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter writer = Json.createWriter(baos); - writer.write(Json.createObjectBuilder().build()); - // not calling writer.close() intentionally - assertEquals("{}", baos.toString("UTF-8")); - } - - public void testNoCloseWriteObjectToWriter() throws Exception { - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.write(Json.createObjectBuilder().build()); - // not calling writer.close() intentionally - assertEquals("{}", sw.toString()); - } - - public void testNoCloseWriteArrayToStream() throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter writer = Json.createWriter(baos); - writer.write(Json.createArrayBuilder().build()); - // not calling writer.close() intentionally - assertEquals("[]", baos.toString("UTF-8")); - } - - public void testNoCloseWriteArrayToWriter() throws Exception { - StringWriter sw = new StringWriter(); - JsonWriter writer = Json.createWriter(sw); - writer.write(Json.createArrayBuilder().build()); - // not calling writer.close() intentionally - assertEquals("[]", sw.toString()); - } - - public void testClose() throws Exception { - MyByteStream baos = new MyByteStream(); - JsonWriter writer = Json.createWriter(baos); - writer.write(Json.createObjectBuilder().build()); - writer.close(); - assertEquals("{}", baos.toString("UTF-8")); - assertTrue(baos.isClosed()); - } - - private static final class MyByteStream extends ByteArrayOutputStream { - boolean closed; - - boolean isClosed() { - return closed; - } - - public void close() throws IOException { - super.close(); - closed = true; - } - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/RFC7159Test.java b/impl/src/test/java/org/eclipse/jsonp/tests/RFC7159Test.java deleted file mode 100644 index a5ee6975..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/RFC7159Test.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import org.junit.Test; -import org.junit.BeforeClass; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import jakarta.json.*; -import jakarta.json.stream.JsonGenerator; -import java.io.StringWriter; -import java.io.StringReader; - -/** - * @author Kin-man Chung - */ -public class RFC7159Test { - - @Test - public void testCreatValues() { - JsonArrayBuilder builder = Json.createArrayBuilder(); - JsonArray array = builder.add(Json.createValue("someString")) - .add(Json.createValue(100)) - .add(Json.createValue(12345.6789)) - .build(); - builder = Json.createArrayBuilder(); - JsonArray expected = builder.add("someString") - .add(100) - .add(12345.6789) - .build(); - assertEquals(expected, array); - } - - @Test - public void testReadValues() { - JsonReader reader = Json.createReader(new StringReader("\"someString\"")); - JsonArrayBuilder builder = Json.createArrayBuilder(); - builder.add(reader.readValue()); - reader = Json.createReader(new StringReader("100")); - builder.add(reader.readValue()); - reader = Json.createReader(new StringReader("12345.6789")); - builder.add(reader.readValue()); - JsonArray array = builder.build(); - builder = Json.createArrayBuilder(); - JsonArray expected = builder.add("someString") - .add(100) - .add(12345.6789) - .build(); - assertEquals(expected, array); - } - - @Test - public void testWriteValues() { - StringWriter stringWriter = new StringWriter(); - JsonWriter writer = Json.createWriter(stringWriter); - writer.write(Json.createValue("someString")); - assertEquals("\"someString\"", stringWriter.toString()); - - stringWriter = new StringWriter(); - writer = Json.createWriter(stringWriter); - writer.write(Json.createValue(100)); - assertEquals("100", stringWriter.toString()); - - stringWriter = new StringWriter(); - writer = Json.createWriter(stringWriter); - writer.write(Json.createValue(12345.6789)); - assertEquals("12345.6789", stringWriter.toString()); - } - - @Test - public void testGeneratorValues() { - StringWriter stringWriter = new StringWriter(); - JsonGenerator generator = Json.createGenerator(stringWriter); - generator.write("someString").close(); - assertEquals("\"someString\"", stringWriter.toString()); - - stringWriter = new StringWriter(); - generator = Json.createGenerator(stringWriter); - generator.write(100).close(); - assertEquals("100", stringWriter.toString()); - - stringWriter = new StringWriter(); - generator = Json.createGenerator(stringWriter); - generator.write(12345.6789).close(); - assertEquals("12345.6789", stringWriter.toString()); - } -} diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/ToJsonTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/ToJsonTest.java deleted file mode 100644 index 38bda77a..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/ToJsonTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import org.eclipse.jsonp.JsonUtil; -import org.junit.Assert; -import org.junit.Test; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonValue; - -import static org.junit.Assert.assertEquals; -/** - * @author Kin-man Chung - */ -public class ToJsonTest { - - @Test - public void testToJson() { - assertEquals(Json.createValue("someString"), JsonUtil.toJson("'someString'")); - assertEquals(Json.createValue("some'thing"), JsonUtil.toJson("'some\\'thing'")); - assertEquals(Json.createValue("some\"thing"), JsonUtil.toJson("'some\\\"thing'")); - JsonArrayBuilder builder = Json.createArrayBuilder(); - JsonArray array = builder - .add(Json.createObjectBuilder() - .add("name", "John") - .add("age", 35) - .add("educations", Json.createArrayBuilder() - .add("Gunn High") - .add("UC Berkeley"))) - .add(Json.createObjectBuilder() - .add("name", "Jane") - .add("educations", Json.createArrayBuilder() - .add("Oxford"))) - .build(); - JsonValue expected = JsonUtil.toJson( - "[ { 'name': 'John', " + - "'age': 35, " + - "'educations': ['Gunn High', 'UC Berkeley'] }, " + - " { 'name': 'Jane', " + - "'educations': ['Oxford']}]"); - assertEquals(expected, array); - } -} - diff --git a/impl/src/test/java/org/eclipse/jsonp/tests/TwitterSearchTest.java b/impl/src/test/java/org/eclipse/jsonp/tests/TwitterSearchTest.java deleted file mode 100644 index 84d90089..00000000 --- a/impl/src/test/java/org/eclipse/jsonp/tests/TwitterSearchTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.tests; - -import junit.framework.TestCase; - -import jakarta.json.*; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParser.Event; -import java.io.*; -import java.net.URL; - -/** - * JsonParser Tests using twitter search API - * - * @author Jitendra Kotamraju - */ -public class TwitterSearchTest extends TestCase { - - public void test() { - // dummy test so that junit doesn't complain - } - - public void xtestStreamTwitter() throws Exception { - URL url = new URL("http://search.twitter.com/search.json?q=%23java&rpp=100"); - InputStream is = url.openStream(); - JsonParser parser = Json.createParser(is); - - while(parser.hasNext()) { - Event e = parser.next(); - if (e == Event.KEY_NAME) { - if (parser.getString().equals("from_user")) { - parser.next(); - System.out.print(parser.getString()); - System.out.print(": "); - } else if (parser.getString().equals("text")) { - parser.next(); - System.out.println(parser.getString()); - System.out.println("---------"); - } - } - } - parser.close(); - } - - public void xtestObjectTwitter() throws Exception { - URL url = new URL("http://search.twitter.com/search.json?q=%23java&rpp=100"); - InputStream is = url.openStream(); - JsonReader rdr = Json.createReader(is); - JsonObject obj = rdr.readObject(); - JsonArray results = obj.getJsonArray("results"); - for(JsonObject result : results.getValuesAs(JsonObject.class)) { - System.out.print(result.get("from_user")); - System.out.print(": "); - System.out.println(result.get("text")); - System.out.println("-----------"); - } - rdr.close(); - } - -} diff --git a/impl/src/test/resources/facebook.json b/impl/src/test/resources/facebook.json deleted file mode 100644 index 1a829092..00000000 --- a/impl/src/test/resources/facebook.json +++ /dev/null @@ -1,668 +0,0 @@ -{ - "data": [ - { - "id": "123_1", - "from": { - "name": "Name 1", - "id": "1" - }, - "message": "Dummy message Name 1", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for iPhone", - "namespace": "fbiphone", - "id": "12345" - }, - "created_time": "2013-07-26T22:33:09+0000", - "updated_time": "2013-07-26T22:33:09+0000" - }, - { - "id": "123_2", - "from": { - "category": "Author", - "name": "Name 2", - "id": "2" - }, - "message": "Dummy message Name 2", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/9879asd/987645" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:33:03+0000", - "updated_time": "2013-07-26T22:33:03+0000" - }, - { - "id": "123_3", - "from": { - "category": "Community", - "name": "Group 1", - "id": "3" - }, - "message": "Dummy message Group 1", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/68548" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:33:00+0000", - "updated_time": "2013-07-26T22:33:00+0000" - }, - { - "id": "123_4", - "from": { - "category": "Bank/financial institution", - "name": "Group 2", - "id": "4" - }, - "message": "Dummy message Group 2", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/1234" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Seesmic", - "id": "34567" - }, - "created_time": "2013-07-26T22:32:58+0000", - "updated_time": "2013-07-26T22:32:58+0000" - }, - { - "id": "123_5", - "from": { - "name": "Person 5", - "id": "5" - }, - "message": "Dummy message Person 5", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:32:55+0000", - "updated_time": "2013-07-26T22:32:55+0000" - }, - { - "id": "123_6", - "from": { - "name": "Person 6", - "id": "6" - }, - "message": "Dummy message Person 6", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:32:46+0000", - "updated_time": "2013-07-26T22:32:46+0000" - }, - { - "id": "123_7", - "from": { - "category": "Community", - "name": "\u0e2a\u0e19Group 7", - "id": "7" - }, - "message": "Dummy message Group 7", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/7" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "DoubleQ", - "namespace": "doubleqapp", - "id": "98765" - }, - "created_time": "2013-07-26T22:32:41+0000", - "updated_time": "2013-07-26T22:32:41+0000" - }, - { - "id": "123_8", - "from": { - "name": "Person 8", - "id": "8" - }, - "message": "Dummy message Person 8", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:32:36+0000", - "updated_time": "2013-07-26T22:32:36+0000" - }, - { - "id": "123_9", - "from": { - "category": "Bank/financial institution", - "name": "Group 9", - "id": "9" - }, - "message": "Dummy message Group 9", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/9" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Status Shuffle", - "namespace": "status-shuffle", - "id": "87654" - }, - "created_time": "2013-07-26T22:32:30+0000", - "updated_time": "2013-07-26T22:32:30+0000" - }, - { - "id": "123_10", - "from": { - "name": "Person 10", - "id": "10" - }, - "message": "Dummy message Person 10", - "picture": "https://picture.url/123/10.jpg", - "link": "https://custom.url/123/10", - "name": "Dummy page name - Person 10", - "caption": "www.page.com", - "description": "Some random description", - "icon": "https://icon.url/123/10.ico", - "privacy": { - "value": "" - }, - "type": "link", - "created_time": "2013-07-26T22:32:14+0000", - "updated_time": "2013-07-26T22:32:14+0000" - }, - { - "id": "123_11", - "from": { - "category": "Community", - "name": "Group 11", - "id": "11" - }, - "message": "Dummy message Group 11", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/11" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "twitterfeed", - "id": "654987" - }, - "created_time": "2013-07-26T22:32:13+0000", - "updated_time": "2013-07-26T22:32:13+0000" - }, - { - "id": "123_12", - "from": { - "category": "Entertainer", - "name": "Person 12", - "id": "12" - }, - "message": "Dummy message Person 12", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/12" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:32:10+0000", - "updated_time": "2013-07-26T22:32:10+0000" - }, - { - "id": "123_13", - "from": { - "category": "Health/beauty", - "name": "Group 13", - "id": "13" - }, - "message": "Dummy message Group 13", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/13" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "twitterfeed", - "id": "654987" - }, - "created_time": "2013-07-26T22:32:07+0000", - "updated_time": "2013-07-26T22:32:07+0000" - }, - { - "id": "123_14", - "from": { - "name": "Person 14", - "id": "14" - }, - "message": "Dummy message Person 14", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:31:53+0000", - "updated_time": "2013-07-26T22:31:53+0000" - }, - { - "id": "123_15", - "from": { - "category": "Community", - "name": "Group 15", - "id": "15" - }, - "message": "Dummy message Group 15", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/15" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:31:40+0000", - "updated_time": "2013-07-26T22:31:40+0000" - }, - { - "id": "123_16", - "from": { - "name": "Person 16", - "id": "16" - }, - "message": "Dummy message Person 16", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Nokia", - "id": "34567" - }, - "created_time": "2013-07-26T22:31:39+0000", - "updated_time": "2013-07-26T22:31:39+0000" - }, - { - "id": "123_17", - "from": { - "name": "Person 17", - "id": "17" - }, - "to": { - "data": [ - { - "name": "Person 16", - "id": "16" - } - ] - }, - "with_tags": { - "data": [ - { - "name": "Person 16", - "id": "16" - } - ] - }, - "message": "Dummy message Person 16", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for iPhone", - "namespace": "fbiphone", - "id": "123456" - }, - "created_time": "2013-07-26T22:31:38+0000", - "updated_time": "2013-07-26T22:31:38+0000" - }, - { - "id": "123_18", - "from": { - "category": "Bank/financial institution", - "name": "Group 18", - "id": "18" - }, - "message": "Dummy message Group 18", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/18" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Status Shuffle", - "namespace": "status-shuffle", - "id": "876543" - }, - "created_time": "2013-07-26T22:31:37+0000", - "updated_time": "2013-07-26T22:31:37+0000" - }, - { - "id": "123_19", - "from": { - "category": "Community", - "name": "Group 19", - "id": "19" - }, - "message": "Dummy message Group 19", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/19" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "23456" - }, - "created_time": "2013-07-26T22:31:36+0000", - "updated_time": "2013-07-26T22:31:36+0000" - }, - { - "id": "123_20", - "from": { - "name": "Person 20", - "id": "20" - }, - "message": "Dummy message Person 20", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:31:36+0000", - "updated_time": "2013-07-26T22:31:36+0000" - }, - { - "id": "123_21", - "from": { - "category": "Website", - "name": "Page 21", - "id": "21" - }, - "message": "Dummy message Page 21", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/21" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "dlvr.it", - "namespace": "dlvr_it", - "id": "456321" - }, - "created_time": "2013-07-26T22:31:34+0000", - "updated_time": "2013-07-26T22:31:34+0000" - }, - { - "id": "123_22", - "from": { - "name": "Person 22", - "id": "22" - }, - "to": { - "data": [ - { - "name": "Person 99", - "id": "99" - }, - { - "name": "Person 98", - "id": "98" - }, - { - "name": "Person 97", - "id": "97" - }, - { - "name": "Person 96", - "id": "96" - }, - { - "name": "Person 95", - "id": "95" - }, - { - "name": "Person 94", - "id": "94" - }, - { - "name": "Person 93", - "id": "93" - }, - { - "name": "Person 92", - "id": "92" - } - ] - }, - "message": "Dummy message Person 22", - "message_tags": { - "50": [ - { - "id": "99", - "name": "Person 99", - "type": "user", - "offset": 50, - "length": 13 - } - ], - "64": [ - { - "id": "98", - "name": "Person 98", - "type": "user", - "offset": 64, - "length": 25 - } - ], - "90": [ - { - "id": "97", - "name": "Person 97", - "type": "user", - "offset": 90, - "length": 11 - } - ], - "102": [ - { - "id": "96", - "name": "Person 96", - "type": "user", - "offset": 102, - "length": 14 - } - ], - "117": [ - { - "id": "95", - "name": "Person 95", - "type": "user", - "offset": 117, - "length": 17 - } - ], - "135": [ - { - "id": "94", - "name": "Person 94", - "type": "user", - "offset": 135, - "length": 13 - } - ], - "149": [ - { - "id": "93", - "name": "Person 93", - "type": "user", - "offset": 149, - "length": 21 - } - ], - "171": [ - { - "id": "92", - "name": "Person 92", - "type": "user", - "offset": 171, - "length": 11 - } - ] - }, - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:31:33+0000", - "updated_time": "2013-07-26T22:31:33+0000" - }, - { - "id": "123_23", - "from": { - "name": "Person 23", - "id": "23" - }, - "message": "Dummy message Person 23", - "picture": "https://custom.url/123/23.jpg", - "link": "https://custom.url/123/23", - "name": "Person 23 Name", - "caption": " ", - "description": " ", - "icon": "https://custom.url/123/23.gif", - "privacy": { - "value": "" - }, - "type": "link", - "application": { - "name": "RSS Graffiti", - "namespace": "rssgraffiti", - "id": "357951" - }, - "created_time": "2013-07-26T22:31:29+0000", - "updated_time": "2013-07-26T22:31:29+0000" - }, - { - "id": "123_24", - "from": { - "name": "Person 24", - "id": "24" - }, - "message": "Dummy message person 24", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "123456" - }, - "created_time": "2013-07-26T22:31:29+0000", - "updated_time": "2013-07-26T22:31:29+0000" - }, - { - "id": "123_25", - "from": { - "name": "Person 25", - "id": "25" - }, - "message": "Dummy message Person 25", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:31:22+0000", - "updated_time": "2013-07-26T22:31:22+0000" - } - ], - "paging": { - "previous": "https://custom.url/previous", - "next": "https://custom.url/next" - } -} \ No newline at end of file diff --git a/impl/src/test/resources/facebook1.json b/impl/src/test/resources/facebook1.json deleted file mode 100644 index 50166527..00000000 --- a/impl/src/test/resources/facebook1.json +++ /dev/null @@ -1,911 +0,0 @@ -{ - "data": [ - { - "id": "123_1", - "from": { - "category": "Bank/financial institution", - "name": "Group 1", - "id": "1" - }, - "message": "Dummy message Group 1", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/1" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Seesmic", - "id": "23456" - }, - "created_time": "2013-07-26T22:45:54+0000", - "updated_time": "2013-07-26T22:45:54+0000" - }, - { - "id": "123_2", - "from": { - "name": "Person 2", - "id": "2" - }, - "message": "Dummy message Person 2", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:52+0000", - "updated_time": "2013-07-26T22:45:52+0000" - }, - { - "id": "123_3", - "from": { - "category": "Outdoor gear/sporting goods", - "category_list": [ - { - "id": "2231", - "name": "Outdoor Gear/Sporting Goods" - } - ], - "name": "Store 3", - "id": "3" - }, - "message": "https://shop.url/123/3", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/3" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:51+0000", - "updated_time": "2013-07-26T22:45:51+0000" - }, - { - "id": "123_4", - "from": { - "name": "Person 4", - "id": "4" - }, - "message": "Dummy message Person 4", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:45:50+0000", - "updated_time": "2013-07-26T22:45:50+0000" - }, - { - "id": "123_5", - "from": { - "name": "Person 5", - "id": "5" - }, - "to": { - "data": [ - { - "name": "Person 2", - "id": "2" - }, - { - "name": "Person 99", - "id": "99" - }, - { - "name": "Person 98", - "id": "98" - } - ] - }, - "message": "Dummy message Person 5", - "message_tags": { - "38": [ - { - "id": "2", - "name": "Person 2", - "type": "user", - "offset": 38, - "length": 13 - } - ], - "53": [ - { - "id": "99", - "name": "Person 99", - "type": "user", - "offset": 53, - "length": 17 - } - ], - "73": [ - { - "id": "98", - "name": "Person 98", - "type": "user", - "offset": 73, - "length": 18 - } - ] - }, - "story": "Dummy story Person 5", - "story_tags": { - "0": [ - { - "id": "97", - "name": "Person 97", - "offset": 0, - "length": 15, - "type": "user" - } - ], - "23": [ - { - "id": "96", - "name": "Person 96", - "offset": 23, - "length": 18, - "type": "user" - } - ] - }, - "picture": "https://custom.url/123/5.jpg", - "link": "https://profile.url/123/5", - "name": "Person 5 Photos", - "properties": [ - { - "name": "By", - "text": "Person 5", - "href": "https://profile.url/123/5" - } - ], - "icon": "https://custom.url/123/5.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "123", - "application": { - "name": "Photos", - "id": "1234" - }, - "created_time": "2013-07-26T22:45:45+0000", - "updated_time": "2013-07-26T22:45:45+0000" - }, - { - "id": "123_6", - "from": { - "category": "Public figure", - "name": "Person 6", - "id": "6" - }, - "message": "Dummy message Person 6", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/6" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:44+0000", - "updated_time": "2013-07-26T22:45:44+0000" - }, - { - "id": "123_7", - "from": { - "name": "Person 7", - "id": "7" - }, - "to": { - "data": [ - { - "name": "Person 89", - "id": "89" - } - ] - }, - "message": "Dummy message Person 7", - "message_tags": { - "16": [ - { - "id": "987", - "name": "Person 987", - "type": "user", - "offset": 16, - "length": 18 - } - ] - }, - "picture": "https://custom.url/123/7.jpg", - "link": "https://custom.url/123/7", - "source": "https://source.url/123/7", - "name": "Link name person 7", - "description": "Description Person 7", - "icon": "https://custom.url/123/7.gif", - "privacy": { - "value": "" - }, - "type": "video", - "created_time": "2013-07-26T22:45:44+0000", - "updated_time": "2013-07-26T22:45:44+0000" - }, - { - "id": "123_8", - "from": { - "name": "Person 8", - "id": "8" - }, - "to": { - "data": [ - { - "name": "Person 1", - "id": "1" - }, - { - "name": "Person 2", - "id": "2" - }, - { - "name": "Person 3", - "id": "3" - }, - { - "name": "Person 4", - "id": "4" - }, - { - "name": "Person 5", - "id": "5" - }, - { - "name": "Person 99", - "id": "99" - }, - { - "name": "Person 98", - "id": "98" - }, - { - "name": "Person 69", - "id": "69" - } - ] - }, - "message": "Dummy message Person 8", - "message_tags": { - "77": [ - { - "id": "1", - "name": "Person 1", - "type": "user", - "offset": 77, - "length": 26 - } - ], - "104": [ - { - "id": "2", - "name": "Person 2", - "type": "user", - "offset": 104, - "length": 11 - } - ], - "116": [ - { - "id": "3", - "name": "Person 3", - "type": "user", - "offset": 116, - "length": 13 - } - ], - "130": [ - { - "id": "4", - "name": "Person 4", - "type": "user", - "offset": 130, - "length": 22 - } - ], - "153": [ - { - "id": "5", - "name": "Person 5", - "type": "user", - "offset": 153, - "length": 20 - } - ], - "174": [ - { - "id": "99", - "name": "Person 99", - "type": "user", - "offset": 174, - "length": 12 - } - ], - "187": [ - { - "id": "98", - "name": "Person 98", - "type": "user", - "offset": 187, - "length": 16 - } - ], - "204": [ - { - "id": "69", - "name": "Person 69", - "type": "user", - "offset": 204, - "length": 21 - } - ] - }, - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:41+0000", - "updated_time": "2013-07-26T22:45:41+0000" - }, - { - "id": "123_9", - "from": { - "name": "Person 9", - "id": "9" - }, - "message": "Dummy message Person 9", - "story": "Story Person 9", - "story_tags": { - "0": [ - { - "id": "8", - "name": "Person 8", - "offset": 0, - "length": 10, - "type": "user" - } - ] - }, - "picture": "https://custom.url/123/9.jpg", - "link": "https://custom.url/123/9", - "icon": "https://custom.url/123/9.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_8", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "34567" - }, - "created_time": "2013-07-26T22:45:33+0000", - "updated_time": "2013-07-26T22:45:33+0000" - }, - { - "id": "123_9", - "from": { - "name": "Person 9", - "id": "9" - }, - "message": "Dummy message Person 9", - "story": "Story Person 9", - "story_tags": { - "0": [ - { - "id": "6", - "name": "Person 6", - "offset": 0, - "length": 13, - "type": "user" - } - ], - "21": [ - { - "id": "7", - "name": "Person 7", - "offset": 21, - "length": 25, - "type": "user" - } - ] - }, - "picture": "https://custom.url/123/9.jpg", - "link": "https://custom.url/123/9", - "name": "Link Person 9", - "caption": "Caption Person 9", - "properties": [ - { - "name": "By", - "text": "Person 9", - "href": "https://custom.url/123/9" - } - ], - "icon": "https://custom.url/123/9.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_9", - "application": { - "name": "Links", - "id": "951753" - }, - "created_time": "2013-07-26T22:45:33+0000", - "updated_time": "2013-07-26T22:45:33+0000" - }, - { - "id": "123_10", - "from": { - "name": "Person 10", - "id": "10" - }, - "message": "Dummy message Person 10", - "story": "Story Person 10", - "story_tags": { - "0": [ - { - "id": "3", - "name": "Person 3", - "offset": 0, - "length": 27, - "type": "user" - } - ], - "35": [ - { - "id": "79", - "name": "Page 79", - "offset": 35, - "length": 4, - "type": "page" - } - ] - }, - "picture": "https://custom.url/123/10.jpg", - "link": "https://link.url/123/10", - "name": "Timeline Photos", - "caption": "Caption link Person 10", - "properties": [ - { - "name": "By", - "text": "Page 79", - "href": "https://custom.url/123/79" - } - ], - "icon": "https://custom.url/123/10.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_10", - "application": { - "name": "Photos", - "id": "3456" - }, - "created_time": "2013-07-26T22:45:31+0000", - "updated_time": "2013-07-26T22:45:31+0000" - }, - { - "id": "123_11", - "from": { - "name": "Person 11", - "id": "11" - }, - "message": "Dummy message Person 11", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for iPhone", - "namespace": "fbiphone", - "id": "23456" - }, - "created_time": "2013-07-26T22:45:25+0000", - "updated_time": "2013-07-26T22:45:25+0000" - }, - { - "id": "123_12", - "from": { - "name": "Person 12", - "id": "12" - }, - "message": "Dummy message Person 12", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "3456" - }, - "created_time": "2013-07-26T22:45:20+0000", - "updated_time": "2013-07-26T22:45:20+0000" - }, - { - "id": "123_13", - "from": { - "name": "Person 13", - "id": "13" - }, - "message": "Dummy message person 13", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:18+0000", - "updated_time": "2013-07-26T22:45:18+0000" - }, - { - "id": "123_14", - "from": { - "name": "Person 14", - "id": "14" - }, - "message": "Dummy message Person 14", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:17+0000", - "updated_time": "2013-07-26T22:45:17+0000" - }, - { - "id": "123_15", - "from": { - "name": "Person 15", - "id": "15" - }, - "message": "Dummy message Person 15", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:16+0000", - "updated_time": "2013-07-26T22:45:16+0000" - }, - { - "id": "123_16", - "from": { - "name": "Person 16", - "id": "16" - }, - "message": "Dummy message Person 16", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "3456" - }, - "created_time": "2013-07-26T22:45:15+0000", - "updated_time": "2013-07-26T22:45:15+0000" - }, - { - "id": "123_17", - "from": { - "name": "Person 17", - "id": "17" - }, - "message": "Dummy message Person 17", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:45:12+0000", - "updated_time": "2013-07-26T22:45:12+0000" - }, - { - "id": "123_18", - "from": { - "name": "Person 18", - "id": "18" - }, - "message": "Dummy message Person 18", - "picture": "https://custom.url/123/18.jpg", - "link": "https://link.url/123/18", - "icon": "https://custom.url/123/18.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_18", - "created_time": "2013-07-26T22:45:11+0000", - "updated_time": "2013-07-26T22:45:11+0000" - }, - { - "id": "123_19", - "from": { - "name": "Person 19", - "id": "19" - }, - "message": "Dummy message Person 19", - "story": "Person 19 Story", - "story_tags": { - "0": [ - { - "id": "19", - "name": "Person 19", - "offset": 0, - "length": 13, - "type": "user" - } - ], - "21": [ - { - "id": "75", - "name": "Person 75", - "offset": 21, - "length": 31, - "type": "page" - } - ] - }, - "picture": "https://custom.url/123/19.jpg", - "link": "https://link.url/123/19", - "name": "Person 19 Photos", - "caption": "Caption Person 19", - "properties": [ - { - "name": "By", - "text": "Group 89", - "href": "https://custom.url/123/19" - } - ], - "icon": "https://custom.url/123/19.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_19", - "application": { - "name": "Photos", - "id": "12375" - }, - "created_time": "2013-07-26T22:45:07+0000", - "updated_time": "2013-07-26T22:45:07+0000" - }, - { - "id": "123_20", - "from": { - "name": "Person 20", - "id": "20" - }, - "message": "Dummy message Person 20", - "story": "Person 20 shared a photo.", - "story_tags": { - "0": [ - { - "id": "20", - "name": "Person 20", - "offset": 0, - "length": 21, - "type": "user" - } - ] - }, - "picture": "https://custom.url/123/20.jpg", - "link": "https://link.url/123/23", - "name": "Person 20's Photos", - "properties": [ - { - "name": "By", - "text": "Person 20", - "href": "https://custom.url/123/20" - } - ], - "icon": "https://custom.url/123/20.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_20", - "application": { - "name": "Photos", - "id": "45678" - }, - "created_time": "2013-07-26T22:45:00+0000", - "updated_time": "2013-07-26T22:45:00+0000" - }, - { - "id": "123_21", - "from": { - "name": "Person 21", - "id": "21" - }, - "message": "Dummy message Person 21", - "story": "Person 21 shared something.", - "story_tags": { - "0": [ - { - "id": "21", - "name": "Person 21", - "offset": 0, - "length": 18, - "type": "user" - } - ], - "26": [ - { - "id": "67", - "name": "Group 67", - "offset": 26, - "length": 30, - "type": "page" - } - ] - }, - "picture": "https://custom.url/123/21.jpg", - "link": "https://link.url/123/21", - "name": "Timeline Photos", - "caption": "Person 21 Caption", - "properties": [ - { - "name": "By", - "text": "Group 75", - "href": "https://custom.url/123/75" - } - ], - "icon": "https://custom.url/123/21.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_21", - "application": { - "name": "Photos", - "id": "123456" - }, - "created_time": "2013-07-26T22:44:58+0000", - "updated_time": "2013-07-26T22:44:58+0000" - }, - { - "id": "123_22", - "from": { - "name": "Person 22", - "id": "22" - }, - "message": "Dummy message Person 22", - "story": "Person 22 shared photo.", - "story_tags": { - "0": [ - { - "id": "22", - "name": "Person 22", - "offset": 0, - "length": 21, - "type": "user" - } - ], - "29": [ - { - "id": "88", - "name": "Person 88", - "offset": 29, - "length": 12, - "type": "page" - } - ] - }, - "picture": "https://custom.url/123/22.jpg", - "link": "https://link.url/123/22", - "name": "Timeline Photos", - "caption": "Person 22 caption", - "properties": [ - { - "name": "By", - "text": "Person 45", - "href": "https://custom.url/123/45" - } - ], - "icon": "https://custom.url/123/22.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_22", - "application": { - "name": "Photos", - "id": "123456" - }, - "created_time": "2013-07-26T22:44:58+0000", - "updated_time": "2013-07-26T22:44:58+0000" - }, - { - "id": "123_23", - "from": { - "category": "Teacher", - "name": "Person 23", - "id": "23" - }, - "message": "Dummy message Person 23", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/23" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:44:57+0000", - "updated_time": "2013-07-26T22:44:57+0000" - }, - { - "id": "24_10151496285490925", - "from": { - "name": "Person 24", - "id": "24" - }, - "message": "Dummy message Person 24", - "story": "Person 24 shared photo.", - "story_tags": { - "0": [ - { - "id": "24", - "name": "Person 24", - "offset": 0, - "length": 30, - "type": "user" - } - ], - "38": [ - { - "id": "86", - "name": "Person 86", - "offset": 38, - "length": 14, - "type": "user" - } - ] - }, - "picture": "https://custom.url/123/24.jpg", - "link": "https://link.url/123/23", - "name": "Person 86 Photos", - "caption": "Person 24 Caption", - "properties": [ - { - "name": "By", - "text": "Person 86", - "href": "https://custom.url/123/86" - } - ], - "icon": "https://custom.url/123/24.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_24", - "application": { - "name": "Links", - "id": "654321" - }, - "created_time": "2013-07-26T22:44:50+0000", - "updated_time": "2013-07-26T22:44:50+0000" - } - ], - "paging": { - "previous": "https://custom.url/previous", - "next": "https://custom.url/next" - } -} \ No newline at end of file diff --git a/impl/src/test/resources/facebook2.json b/impl/src/test/resources/facebook2.json deleted file mode 100644 index b57b1edf..00000000 --- a/impl/src/test/resources/facebook2.json +++ /dev/null @@ -1,555 +0,0 @@ -{ - "data": [ - { - "id": "123_1", - "from": { - "name": "Person 1", - "id": "1" - }, - "message": "Dummy message Person 1", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:57:09+0000", - "updated_time": "2013-07-26T22:57:09+0000" - }, - { - "id": "123_2", - "from": { - "name": "Person 2", - "id": "2" - }, - "message": "Dummy message Person 2", - "picture": "https://custom.url/123/2.jpg", - "link": "https://link.url/123/2", - "source": "https://source.url/123/2", - "name": "Person 2", - "icon": "https://custom.url/123/2.gif", - "privacy": { - "value": "" - }, - "type": "video", - "application": { - "name": "Share_bookmarklet", - "id": "234567" - }, - "created_time": "2013-07-26T22:57:08+0000", - "updated_time": "2013-07-26T22:57:08+0000" - }, - { - "id": "123_3", - "from": { - "category": "Community", - "name": "Group 3", - "id": "3" - }, - "message": "Dummy message Group 3", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/3" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "456789" - }, - "created_time": "2013-07-26T22:57:05+0000", - "updated_time": "2013-07-26T22:57:05+0000" - }, - { - "id": "123_4", - "from": { - "name": "Person 4", - "id": "4" - }, - "message": "Dummy message Person 4", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "456789" - }, - "created_time": "2013-07-26T22:57:00+0000", - "updated_time": "2013-07-26T22:57:00+0000" - }, - { - "id": "123_5", - "from": { - "name": "Person 5", - "id": "5" - }, - "message": "Dummy message Person 5", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:56:58+0000", - "updated_time": "2013-07-26T22:56:58+0000" - }, - { - "id": "123_6", - "from": { - "name": "Person 6", - "id": "6" - }, - "message": "Dummy message Person 6", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for iPhone", - "namespace": "fbiphone", - "id": "23456" - }, - "created_time": "2013-07-26T22:56:54+0000", - "updated_time": "2013-07-26T22:56:54+0000" - }, - { - "id": "123_7", - "from": { - "name": "Person 7", - "id": "7" - }, - "message": "Dummy message Person 7", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:56:47+0000", - "updated_time": "2013-07-26T22:56:47+0000" - }, - { - "id": "123_8", - "from": { - "name": "Person 8", - "id": "8" - }, - "message": "Dummy message Person 8", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:56:45+0000", - "updated_time": "2013-07-26T22:56:45+0000" - }, - { - "id": "123_9", - "from": { - "name": "Person 9", - "id": "9" - }, - "message": "Dummy message Person 9", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "456789" - }, - "created_time": "2013-07-26T22:56:44+0000", - "updated_time": "2013-07-26T22:56:44+0000" - }, - { - "id": "123_10", - "from": { - "name": "Person 10", - "id": "10" - }, - "message": "Dummy message Person 10", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "456789" - }, - "created_time": "2013-07-26T22:56:36+0000", - "updated_time": "2013-07-26T22:56:36+0000" - }, - { - "id": "123_11", - "from": { - "name": "Person 11", - "id": "11" - }, - "message": "Dummy message Person 11", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:56:32+0000", - "updated_time": "2013-07-26T22:56:32+0000" - }, - { - "id": "123_12", - "from": { - "name": "Person 12", - "id": "12" - }, - "message": "Dummy message Person 12", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:56:27+0000", - "updated_time": "2013-07-26T22:56:27+0000" - }, - { - "id": "123_13", - "from": { - "category": "Bank/financial institution", - "name": "Group 13", - "id": "13" - }, - "message": "Dummy message Group 13", - "actions": [ - { - "name": "Comment", - "link": "https://link.url/123/23" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "PostCron", - "namespace": "postcron", - "id": "159357" - }, - "created_time": "2013-07-26T22:56:26+0000", - "updated_time": "2013-07-26T22:56:26+0000" - }, - { - "id": "123_14", - "from": { - "name": "Person 14", - "id": "14" - }, - "to": { - "data": [ - { - "name": "Person 99", - "id": "99" - }, - { - "name": "Person 98", - "id": "98" - } - ] - }, - "message": "Dummy message Person 14", - "message_tags": { - "0": [ - { - "id": "99", - "name": "Person 99", - "type": "user", - "offset": 0, - "length": 21 - } - ], - "159": [ - { - "id": "98", - "name": "Person 98", - "type": "user", - "offset": 159, - "length": 26 - } - ] - }, - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:56:16+0000", - "updated_time": "2013-07-26T22:56:16+0000" - }, - { - "id": "123_15", - "from": { - "name": "Person 15", - "id": "15" - }, - "message": "Dummy message Person 15", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:56:15+0000", - "updated_time": "2013-07-26T22:56:15+0000" - }, - { - "id": "123_16", - "from": { - "category": "Just for fun", - "name": "Group 16", - "id": "16" - }, - "message": "Dummy message Group 16", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/16" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:56:14+0000", - "updated_time": "2013-07-26T22:56:14+0000", - "likes": { - "data": [ - { - "id": "97", - "name": "Person 97" - } - ], - "paging": { - "cursors": { - "after": "MTAwMDAzMDQzNDM5MDQ5", - "before": "MTAwMDAzMDQzNDM5MDQ5" - } - } - } - }, - { - "id": "123_17", - "from": { - "category": "Community", - "name": "Group 17", - "id": "17" - }, - "message": "Dummy message Group 17", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/17" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Pages Manager for Android", - "namespace": "fbpagemgr_android", - "id": "951753" - }, - "created_time": "2013-07-26T22:56:13+0000", - "updated_time": "2013-07-26T22:56:13+0000" - }, - { - "id": "123_18", - "from": { - "name": "Person 18", - "id": "18" - }, - "message": "Dummy message Person 18", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Facebook for iPad", - "namespace": "fbipad_", - "id": "456789" - }, - "created_time": "2013-07-26T22:56:07+0000", - "updated_time": "2013-07-26T22:56:07+0000" - }, - { - "id": "123_19", - "from": { - "name": "Person 19", - "id": "19" - }, - "message": "Dummy message Person 19", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:56:04+0000", - "updated_time": "2013-07-26T22:56:04+0000" - }, - { - "id": "123_20", - "from": { - "name": "Person 20", - "id": "20" - }, - "message": "Dummy message Person 20", - "story": "Person 20 shared photo.", - "story_tags": { - "0": [ - { - "id": "20", - "name": "Person 20", - "offset": 0, - "length": 11, - "type": "user" - } - ], - "19": [ - { - "id": "95", - "name": "Group 95", - "offset": 19, - "length": 27, - "type": "page" - } - ] - }, - "picture": "https://custom.url/123/20.jpg", - "link": "https://link.url/123/20", - "name": "Timeline Photos", - "caption": "Person 20 link caption", - "properties": [ - { - "name": "By", - "text": "Group 95", - "href": "https://custom.url/123/95" - } - ], - "icon": "https://custom.url/123/20.gif", - "privacy": { - "value": "" - }, - "type": "photo", - "object_id": "456_20", - "application": { - "name": "Facebook for Android", - "namespace": "fbandroid", - "id": "456789" - }, - "created_time": "2013-07-26T22:56:04+0000", - "updated_time": "2013-07-26T22:56:04+0000" - }, - { - "id": "123_21", - "from": { - "name": "Person 21", - "id": "21" - }, - "message": "Dummy message Person 21", - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:55:56+0000", - "updated_time": "2013-07-26T22:55:56+0000" - }, - { - "id": "123_22", - "from": { - "name": "Person 22", - "id": "22" - }, - "message": "Dummy message Person 22", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "948731" - }, - "created_time": "2013-07-26T22:55:38+0000", - "updated_time": "2013-07-26T22:55:38+0000" - }, - { - "id": "123_23", - "from": { - "name": "Person 23", - "id": "23" - }, - "message": "Dummy message Person 23", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:55:37+0000", - "updated_time": "2013-07-26T22:55:37+0000" - }, - { - "id": "123_24", - "from": { - "name": "Person 24", - "id": "24" - }, - "message": "Dummy message Person 24", - "privacy": { - "value": "" - }, - "type": "status", - "application": { - "name": "Mobile", - "id": "123456" - }, - "created_time": "2013-07-26T22:55:34+0000", - "updated_time": "2013-07-26T22:55:34+0000" - }, - { - "id": "123_25", - "from": { - "category": "Community", - "name": "Group 25", - "id": "25" - }, - "message": "Dummy message Group 25", - "actions": [ - { - "name": "Comment", - "link": "https://custom.url/123/25" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "created_time": "2013-07-26T22:55:32+0000", - "updated_time": "2013-07-26T22:55:32+0000" - } - ], - "paging": { - "previous": "https://custom.url/previous", - "next": "https://custom.url/next" - } -} \ No newline at end of file diff --git a/impl/src/test/resources/jsonmergepatch.json b/impl/src/test/resources/jsonmergepatch.json deleted file mode 100644 index 3b90e5f5..00000000 --- a/impl/src/test/resources/jsonmergepatch.json +++ /dev/null @@ -1,103 +0,0 @@ -[ - { - "target": {}, - "patch": {"a": {"b":"c"}}, - "expected": {"a":{"b":"c"}} - }, - { - "target": {}, - "patch": {"a":{"bb":{"ccc":null}}}, - "expected": {"a":{"bb":{}}} - }, - { - "target": {"a":"foo"}, - "patch": "bar", - "expected": "bar" - }, - { - "target": {"a":"foo"}, - "patch": null, - "expected": null - }, - { - "target": {"a": {"b":"c"}}, - "patch": {"a": {"b":"d", "c":null}}, - "expected": {"a": {"b":"d"}} - }, - { - "target": { "c": "d" }, - "patch": { "a": "b" }, - "expected": { "a": "b", "c": "d" } - }, - { - "target": { "a": { "d": 2 } }, - "patch": { "a": { "d": 1 } }, - "expected": { "a": { "d": 1 } } - }, - { - "target": { "a": "b", "c": "d" }, - "patch": { "c": null }, - "expected": { "a": "b" } - }, - { - "target": { "a": { "b": "c", "d": null} }, - "patch": { "a": { "d": null} }, - "expected": { "a": { "b": "c" } } - }, - { - "target": { - "a": { "b": "c" }, - "d": "e" - }, - "patch": { - "a": 1000010002020389.8787987983 - }, - "expected": { - "a": 1000010002020389.8787987983, - "d": "e" - } - }, - { - "target": { "a": "b" }, - "patch": { "c": [ null ] }, - "expected": { "a": "b", "c": [ null ] } - }, - { - "target": { "a": { "b": null, "d": 3}, "e": -1 }, - "patch": { "a": { "b": "c", "d": null } }, - "expected": { "a": { "b": "c" }, "e": -1 } - }, - { - "target": [1,2], - "patch": { "a": "b", "c": null }, - "expected": { "a": "b"} - }, - { - "target": { - "title": "Goodbye!", - "author": { - "givenName": "John", - "familyName": "Doe" - }, - "tags": [ "example", "sample" ], - "content": "This will be unchanged" - }, - "patch": { - "title": "Hello!", - "phoneNumber": "+01-123-456-7890", - "author": { - "familyName": null - }, - "tags": [ "example" ] - }, - "expected": { - "title": "Hello!", - "author": { - "givenName": "John" - }, - "tags": [ "example" ], - "content": "This will be unchanged", - "phoneNumber": "+01-123-456-7890" - } - } -] \ No newline at end of file diff --git a/impl/src/test/resources/jsonmergepatchdiff.json b/impl/src/test/resources/jsonmergepatchdiff.json deleted file mode 100644 index ac6c91de..00000000 --- a/impl/src/test/resources/jsonmergepatchdiff.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "original": { - "title": "Goodbye!", - "author": { - "givenName": "John", - "familyName": "Doe" - }, - "tags": [ "example", "sample" ], - "content": "This will be unchanged" - }, - "expected": { - "title": "Hello!", - "phoneNumber": "+01-123-456-7890", - "author": { - "familyName": null - }, - "tags": [ "example" ] - }, - "target": { - "title": "Hello!", - "author": { - "givenName": "John" - }, - "tags": [ "example" ], - "content": "This will be unchanged", - "phoneNumber": "+01-123-456-7890" - } - }, - { - "original": {}, - "expected": {"a": {"b":"c"}}, - "target": {"a":{"b":"c"}} - }, - { - "original": {"a":"foo"}, - "expected": "bar", - "target": "bar" - }, - { - "original": {"a":"foo"}, - "expected": null, - "target": null - }, - { - "original": { "c": "d" }, - "expected": { "a": "b" }, - "target": { "a": "b", "c": "d" } - }, - { - "original": { "a": { "d": 2 } }, - "expected": { "a": { "d": 1 } }, - "target": { "a": { "d": 1 } } - }, - { - "original": { "a": "b", "c": "d" }, - "expected": { "c": null }, - "target": { "a": "b" } - } -] \ No newline at end of file diff --git a/impl/src/test/resources/jsonpatch.json b/impl/src/test/resources/jsonpatch.json deleted file mode 100644 index 4db47943..00000000 --- a/impl/src/test/resources/jsonpatch.json +++ /dev/null @@ -1,219 +0,0 @@ -[ - { - "op": { "op": "test", "path": "/a/1", "value": "hello" }, - "target": { "a": [ null, "hello", "world" ] }, - "expected": { "a": [ null, "hello", "world" ] } - }, - { - "op": { "op": "test", "path": "/x", "value": {} }, - "target": [ 1, 2 ], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "test", "path": "", "value": true }, - "target": [ 1, 2 ], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "test", "path": "/x", "value": -30.000 }, - "target": { "x": -29.020 }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "replace", "path": "", "value": false }, - "target": { "x": { "a": "b", "y": {} } }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "replace", "path": "/x/y", "value": "hello" }, - "target": { "x": { "a": "b", "y": {} } }, - "expected": { "x": { "a": "b", "y": "hello" } } - }, - { - "op": { "op": "replace", "path": "/0/2", "value": "x" }, - "target": [ [ "a", "b", "c"], "d", "e" ], - "expected": [ [ "a", "b", "x" ], "d", "e" ] - }, - { - "op": { "op": "replace", "path": "/x/0", "value": null }, - "target": { "x": [ "y", "z" ], "foo": "bar" }, - "expected": { "x": [ null, "z" ], "foo": "bar" } - }, - { - "op": { "op": "replace", "path": "/x/y", "value": 42 }, - "target": { "x": {} }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "remove", "path": "/x/y" }, - "target": { "x": { "a": "b", "y": {} } }, - "expected": { "x": { "a": "b" } } - }, - { - "op": { "op": "remove", "path": "/0/2" }, - "target": [ [ "a", "b", "c"], "d", "e" ], - "expected": [ [ "a", "b" ], "d", "e" ] - }, - { - "op": { "op": "remove", "path": "/x/0" }, - "target": { "x": [ "y", "z" ], "foo": "bar" }, - "expected": { "x": [ "z" ], "foo": "bar" } - }, - { - "op": { "op": "remove", "path": "/x/y" }, - "target": { "x": {} }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "move", "from": "/x/a", "path": "/x/b" }, - "target": { "x": { "a": "helo" } }, - "expected": { "x": { "b": "helo" } } - }, - { - "op": { "op": "move", "from": "/x/a", "path": "/x/a" }, - "target": { "x": { "a": "helo" } }, - "expected": { "x": { "a": "helo" } } - }, - { - "op": { "op": "move", "from": "/0", "path": "/0/x" }, - "target": [ "victim", {}, {} ], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "move", "from": "/0", "path": "/-" }, - "target": [ 0, 1, 2 ], - "expected": [ 1, 2, 0 ] - }, - { - "op": { "op": "move", "from": "/a", "path": "/b/2" }, - "target": { "a": "helo", "b": [ 1, 2, 3, 4 ] }, - "expected": { "b": [ 1, 2, "helo", 3, 4 ] } - }, - { - "op": { "op": "move", "from": "/a", "path": "/a/b" }, - "target": {}, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "move", "from": "/a", "path": "/b/c" }, - "target": { "a": "b" }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "move", "from": "/x/a", "path": "/x/c" }, - "target": { "x": { "b": "helo" } }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "copy", "from": "/a", "path": "/b" }, - "target": { "a": 1 }, - "expected": { "a": 1, "b": 1 } - }, - { - "op": { "op": "copy", "from": "/a", "path": "/b" }, - "target": { "a": 1, "b": false }, - "expected": { "a": 1, "b": 1 } - }, - { - "op": { "op": "copy", "from": "/0", "path": "/-" }, - "target": [ 1, 2, 3, 4 ], - "expected": [ 1, 2, 3, 4, 1 ] - }, - { - "op": { "op": "copy", "from": "/0", "path": "/0" }, - "target": [ true ], - "expected": [ true, true ] - }, - { - "op": { "op": "copy", "from": "/a", "path": "/b" }, - "target": {}, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "copy", "from": "/a", "path": "/b/c" }, - "target": { "a": 1 }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/a/b/c", "value": 1 }, - "target": { "a": "b" }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/~1", "value": 1 }, - "target": [], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/3", "value": 1 }, - "target": [ 1, 2 ], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/-2", "value": 1 }, - "target": [ 1, 2 ], - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/foo/f", "value": "bar" }, - "target": { "foo": "bar" }, - "exception": "jakarta.json.JsonException" - }, - { - "op": { "op": "add", "path": "/a", "value": "b" }, - "target": {}, - "expected": { "a": "b" } - }, - { - "op": { "op": "add", "path": "/a", "value": 1 }, - "target": { "a": "b" }, - "expected": { "a": 1 } - }, - { - "op": { "op": "add", "path": "/array/-", "value": 1 }, - "target": { "array": [ 2, null, {}, 1 ] }, - "expected": { "array": [ 2, null, {}, 1, 1 ] } - }, - { - "op": { "op": "add", "path": "/array/2", "value": "hello" }, - "target": { "array": [ 2, null, {}, 1] }, - "expected": { "array": [ 2, null, "hello", {}, 1 ] } - }, - { - "op": { "op": "add", "path": "/obj/inner/b", "value": [ 1, 2 ] }, - "target": { - "obj": { - "inner": { - "a": "hello" - } - } - }, - "expected": { - "obj": { - "inner": { - "a": "hello", - "b": [ 1, 2 ] - } - } - } - }, - { - "op": { "op": "add", "path": "/obj/inner/b", "value": [ 1, 2 ] }, - "target": { - "obj": { - "inner": { - "a": "hello", - "b": "world" - } - } - }, - "expected": { - "obj": { - "inner": { - "a": "hello", - "b": [ 1, 2 ] - } - } - } - } -] diff --git a/impl/src/test/resources/jsonpatchdiff.json b/impl/src/test/resources/jsonpatchdiff.json deleted file mode 100644 index d4aa8fed..00000000 --- a/impl/src/test/resources/jsonpatchdiff.json +++ /dev/null @@ -1,169 +0,0 @@ -[ - { - "original": {"a":"b"}, - "target": {"a":"b"}, - "expected": [] - }, - { - "original": [ 1, 2, 3 ], - "target": [ 1, 2, 3, 4, 5 ], - "expected": [ - {"op":"add","path":"/3","value":4}, - {"op":"add","path":"/4","value":5} - ] - }, - { - "original": [1,2,3,4,5], - "target": [1,3,4], - "expected": [ - { "op": "remove", "path": "/4"}, - { "op": "remove", "path": "/1"} - ] - }, - { - "original": [1,2,3,4,5,6], - "target": [1,7,3,4,8,5], - "expected": [ - { "op": "remove", "path": "/5"}, - { "op": "replace", "path": "/1", "value": 7}, - { "op": "add", "path": "/4", "value": 8} - ] - }, - { - "original": [ 1, 2, 3 ], - "target": [ 1 ], - "expected": [ - { "op": "remove", "path": "/2" }, - { "op": "remove", "path": "/1" } - ] - }, - { - "original": { "a": "b", "c": "d" }, - "target": { "a": "b" }, - "expected": [ - { "op": "remove", "path": "/c" } - ] - }, - { - "original": { "a": 1 }, - "target": { "a": 1, "c": 2, "b": 3, "d": 4 }, - "expected": [ - { "op": "add", "path": "/c", "value": 2 }, - { "op": "add", "path": "/b", "value": 3 }, - { "op": "add", "path": "/d", "value": 4 } - ] - }, - { - "original": { "a": null }, - "target": { "a": 6 }, - "expected": [ - { "op": "replace", "path": "/a", "value": 6 } - ] - }, - { - "original": [ 1, 2, 3 ], - "target": { "hello": "world" }, - "expected": [ - { "op": "replace", "path": "", "value": { "hello": "world" } } - ] - }, - { - "original": { - "a": "b", - "c": { - "d": "e" - } - }, - "target": { - "a": "b", - "c": { - "d": 1, - "e": "f" - } - }, - "expected": [ - { "op": "replace", "path": "/c/d", "value": 1 }, - { "op": "add", "path": "/c/e", "value": "f" } - ] - }, - { - "original": { - "a": [ 1, 2, 3 ] - }, - "target": { - "a": [ "b", 2, 3, 4 ] - }, - "expected": [ - { "op": "replace", "path": "/a/0", "value":"b" }, - { "op": "add", "path": "/a/3", "value":4 } - ] - }, - { - "original": [ { "a": "b" }, "foo", { "bar": null } ], - "target": [ { "a": "b", "c": "d" }, "foo", { "bar": "baz" } ], - "expected": [ - { "op": "replace", "path": "/2/bar", "value": "baz" }, - { "op": "add", "path": "/0/c", "value": "d" } - ] - }, - { - "original": [ 1, [ 2, 3 ], 4 ], - "target": [ "x", [ 2, 3, "y" ], 4 ], - "expected": [ - { "op": "add", "path": "/1/2", "value": "y" }, - { "op": "replace", "path": "/0", "value": "x" } - ] - }, - { - "original": { "a": "b" }, - "target": { "c": "b" }, - "expected": [ - { "op": "remove", "path": "/a"}, - { "op": "add", "path": "/c", "value": "b"} - ] - }, - { - "original": {"a": "c"}, - "target": {"a": "c", "d": "c"}, - "expected": [ - { "op": "add", "path": "/d", "value": "c" } - ] - }, - { - "original": [-1, 0, 1, 3, 4], - "target": [5, 0], - "expected": [ - { "path" : "/4", "op" : "remove"}, - { "path" : "/3", "op" : "remove"}, - { "path" : "/2", "op" : "remove"}, - { "value" : 5, "path" : "/0", "op" : "replace" } - ] - }, - { - "original": [0], - "target": [0, 1, 2, 3, 4], - "expected": [ - { "path" : "/1", "value" : 1, "op" : "add" }, - { "path" : "/2", "value" : 2, "op" : "add" }, - { "value" : 3, "path" : "/3", "op" : "add" }, - { "op" : "add", "path" : "/4", "value" : 4 } - ] - }, - { - "original": [0, 2, 4], - "target": [0, 1, 2, 3, 4], - "expected": [ - { "path" : "/1", "value" : 1, "op" : "add" }, - { "value" : 3, "op" : "add", "path" : "/3" } - ] - }, - { - "original": {"a/b": "c", "e/f": "i"}, - "target": {"a/b": "d", "f/g": "i"}, - "expected": [ - { "op": "replace", "path": "/a~1b", "value": "d" }, - { "op": "remove", "path":"/e~1f" }, - { "op": "add", "path":"/f~1g", "value":"i" } - ] - } -] diff --git a/impl/src/test/resources/rfc6901.json b/impl/src/test/resources/rfc6901.json deleted file mode 100644 index 170147b7..00000000 --- a/impl/src/test/resources/rfc6901.json +++ /dev/null @@ -1,20 +0,0 @@ - { - "foo": ["bar", "baz"], - "": 0, - "a/b": 1, - "c%d": 2, - "e^f": 3, - "g|h": 4, - "i\\j": 5, - "k\"l": 6, - " ": 7, - "m~n": 8, - "o" : null, - "p": { - "q":"r" - }, - "s": [ { - "t":"u" - } - ] - } \ No newline at end of file diff --git a/impl/src/test/resources/twitter.json b/impl/src/test/resources/twitter.json deleted file mode 100644 index 677f2b91..00000000 --- a/impl/src/test/resources/twitter.json +++ /dev/null @@ -1,2 +0,0 @@ -{"statuses":[{"metadata":{"result_type":"recent","iso_language_code":"de"},"created_at":"Fri Jul 26 19:31:26 +0000 2013","id":360844831439855616,"id_str":"360844831439855616","text":"Hiring ••► Pre-Sales Consultant ☛ http://t.co/fjlOd8PhcQ #Java #JUnit #Python #PHP #XML #XSLT #SOAP #REST #SAML #Node","source":"SocialOomph","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":93646439,"id_str":"93646439","name":"Paul Pleus","screen_name":"IER_Recruiting","location":"Worldwide","description":"International Executive Recruiting – IER, Xing, Linkedin, Recruiting, Recruiter, Headhunter Personalberater, Job, Jobs, Stellenangebot, Manager","url":"http://t.co/GtcxFsUyI3","entities":{"url":{"urls":[{"url":"http://t.co/GtcxFsUyI3","expanded_url":"http://www.ier-network.com","display_url":"ier-network.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":17822,"friends_count":15829,"listed_count":119,"created_at":"Mon Nov 30 15:02:59 +0000 2009","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":26733,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"0099B9","profile_background_image_url":"http://a0.twimg.com/profile_background_images/216930247/pleus_final_logo_KUGEL.jpg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/216930247/pleus_final_logo_KUGEL.jpg","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/1270812893/Final_198x146_normal.jpg","profile_image_url_https":"https://si0.twimg.com/profile_images/1270812893/Final_198x146_normal.jpg","profile_link_color":"0099B9","profile_sidebar_border_color":"5ED4DC","profile_sidebar_fill_color":"95E8EC","profile_text_color":"3C3940","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Java","indices":[57,62]},{"text":"JUnit","indices":[63,69]},{"text":"Python","indices":[70,77]},{"text":"PHP","indices":[78,82]},{"text":"XML","indices":[83,87]},{"text":"XSLT","indices":[88,93]},{"text":"SOAP","indices":[94,99]},{"text":"REST","indices":[100,105]},{"text":"SAML","indices":[106,111]},{"text":"Node","indices":[112,117]}],"symbols":[],"urls":[{"url":"http://t.co/fjlOd8PhcQ","expanded_url":"http://bit.ly/19I4P7E","display_url":"bit.ly/19I4P7E","indices":[34,56]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"de"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:30:39 +0000 2013","id":360844632520798209,"id_str":"360844632520798209","text":"Death toll reaches 15 for #Indonesian asylum seeker boat that capsized off the coast of west #Java http://t.co/4rGk0LO9F8","source":"TweetDeck","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":90407341,"id_str":"90407341","name":"CSIS Southeast Asia","screen_name":"SoutheastAsiaDC","location":"Washington, DC","description":"The Sumitro Chair for Southeast Asia Studies @CSIS is the premier forum for sustained elevated policy dialogue on Southeast Asia and US interests in the region.","url":"http://t.co/1bcQU6sG1V","entities":{"url":{"urls":[{"url":"http://t.co/1bcQU6sG1V","expanded_url":"http://bit.ly/csis-seap","display_url":"bit.ly/csis-seap","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":8127,"friends_count":523,"listed_count":427,"created_at":"Mon Nov 16 14:51:00 +0000 2009","favourites_count":16,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":12019,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"B2DFDA","profile_background_image_url":"http://a0.twimg.com/profile_background_images/669153955/be1298700d512cfdd3734a677a587095.gif","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/669153955/be1298700d512cfdd3734a677a587095.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/2648645038/e06eb649efb4030845d4cbf47d41651b_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/2648645038/e06eb649efb4030845d4cbf47d41651b_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/90407341/1371826204","profile_link_color":"93A644","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"FFFFFF","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Indonesian","indices":[26,37]},{"text":"Java","indices":[93,98]}],"symbols":[],"urls":[{"url":"http://t.co/4rGk0LO9F8","expanded_url":"http://fxn.ws/1c7VZ2F","display_url":"fxn.ws/1c7VZ2F","indices":[99,121]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:30:15 +0000 2013","id":360844531593261057,"id_str":"360844531593261057","text":"Senior Java Developer w/ #Java #Software skills Addison @p2people http://t.co/Fc9UlSdyWj","source":"p2people","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":551581457,"id_str":"551581457","name":"p2p WebMobileIT","screen_name":"p2pWebMobileIt","location":"Stevenage | Hertfordshire","description":"Web, Mobile & IT micro #outsourcing and #freelance jobs at p2people","url":"http://t.co/OxLhyJdlxw","entities":{"url":{"urls":[{"url":"http://t.co/OxLhyJdlxw","expanded_url":"http://www.p2people.co.uk","display_url":"p2people.co.uk","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":712,"friends_count":3,"listed_count":44,"created_at":"Thu Apr 12 05:07:17 +0000 2012","favourites_count":0,"utc_offset":3600,"time_zone":"London","geo_enabled":false,"verified":false,"statuses_count":88202,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/2099631495/p2people_logo_48x48_normal.png","profile_image_url_https":"https://si0.twimg.com/profile_images/2099631495/p2people_logo_48x48_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Java","indices":[25,30]},{"text":"Software","indices":[31,40]}],"symbols":[],"urls":[{"url":"http://t.co/Fc9UlSdyWj","expanded_url":"http://bit.ly/175ch6w","display_url":"bit.ly/175ch6w","indices":[66,88]}],"user_mentions":[{"screen_name":"p2people","name":"p2people","id":22741835,"id_str":"22741835","indices":[56,65]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:30:00 +0000 2013","id":360844471761502209,"id_str":"360844471761502209","text":"Took 658ms to processing 200 tweets #JAVA #APPENGINE #1374867000804","source":"You Can't Be Wrong","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1186398894,"id_str":"1186398894","name":"You Can't Be Wrong","screen_name":"YouCantBeWrong","location":"@tegaralaga's mind","description":"User generated content text game based on Twitter. For more information send your email to tegaralaga(at)live(dot)com","url":"http://t.co/Jto68Xkf","entities":{"url":{"urls":[{"url":"http://t.co/Jto68Xkf","expanded_url":"http://google.co.id/","display_url":"google.co.id","indices":[0,20]}]},"description":{"urls":[]}},"protected":false,"followers_count":8,"friends_count":1,"listed_count":1,"created_at":"Sat Feb 16 14:30:21 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":22815,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/3261474447/f3cabcc48d277be37e45ac7b1038d73e_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3261474447/f3cabcc48d277be37e45ac7b1038d73e_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/1186398894/1361117710","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"JAVA","indices":[36,41]},{"text":"APPENGINE","indices":[42,52]}],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:29:22 +0000 2013","id":360844310297591811,"id_str":"360844310297591811","text":"RT @ECBader: Some interesting open source #Java projects from #Esri http://t.co/1pvAEzkV9r. Geometry API is worth checking out! https://t.c…","source":"Twitter for iPhone","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":11640022,"id_str":"11640022","name":"Philip Heede","screen_name":"pheede","location":"Redlands, CA","description":"Transplanted Dane using GIS at Esri w/.NET/XAML/Geoprocessing/Python/ArcObjects/Network Analyst/.. Disclaimer: all opinions, comments are my own, blah blah..","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":355,"friends_count":267,"listed_count":22,"created_at":"Sat Dec 29 20:25:10 +0000 2007","favourites_count":114,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":1711,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/335064929/n701240139_383204_9480_normal.jpg","profile_image_url_https":"https://si0.twimg.com/profile_images/335064929/n701240139_383204_9480_normal.jpg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 15:40:13 +0000 2013","id":360786645261352961,"id_str":"360786645261352961","text":"Some interesting open source #Java projects from #Esri http://t.co/1pvAEzkV9r. Geometry API is worth checking out! https://t.co/yEXKNTClKZ","source":"TweetDeck","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":26422164,"id_str":"26422164","name":"Eric Bader","screen_name":"ECBader","location":"Southern California","description":"Geographer, Musician, Christ-follower, Java dude, Nebraska Cornhusker, Esri Product Management Team - ArcGIS.","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":614,"friends_count":473,"listed_count":37,"created_at":"Wed Mar 25 03:44:15 +0000 2009","favourites_count":27,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":2700,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"1A1B1F","profile_background_image_url":"http://a0.twimg.com/images/themes/theme9/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme9/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/2586630286/dct7znna7xosntblt7jb_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/2586630286/dct7znna7xosntblt7jb_normal.jpeg","profile_link_color":"2FC2EF","profile_sidebar_border_color":"181A1E","profile_sidebar_fill_color":"252429","profile_text_color":"666666","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":2,"favorite_count":0,"entities":{"hashtags":[{"text":"Java","indices":[29,34]},{"text":"Esri","indices":[49,54]}],"symbols":[],"urls":[{"url":"http://t.co/1pvAEzkV9r","expanded_url":"http://esri.github.io/#Java","display_url":"esri.github.io/#Java","indices":[55,77]},{"url":"https://t.co/yEXKNTClKZ","expanded_url":"https://github.com/Esri/geometry-api-java","display_url":"github.com/Esri/geometry-…","indices":[115,138]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},"retweet_count":2,"favorite_count":0,"entities":{"hashtags":[{"text":"Java","indices":[42,47]},{"text":"Esri","indices":[62,67]}],"symbols":[],"urls":[{"url":"http://t.co/1pvAEzkV9r","expanded_url":"http://esri.github.io/#Java","display_url":"esri.github.io/#Java","indices":[68,90]}],"user_mentions":[{"screen_name":"ECBader","name":"Eric Bader","id":26422164,"id_str":"26422164","indices":[3,11]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:29:17 +0000 2013","id":360844289841971200,"id_str":"360844289841971200","text":"Looking for a new IT challenge? Take a look at our job openings http://t.co/MhnnR101cT #atlassian #java #oracle #mobile #infra #jobs","source":"TweetDeck","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":296655269,"id_str":"296655269","name":"Koen Gillard","screen_name":"KoenGillard","location":"","description":"Sr Java/Oracle Consultant at @Contribute4J. Certified Scrum Master. Big Atlassian enthusiast. Father of 2 great sons. Other interests music/soccer/cycling/...","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":151,"friends_count":341,"listed_count":4,"created_at":"Wed May 11 05:23:43 +0000 2011","favourites_count":874,"utc_offset":7200,"time_zone":"Brussels","geo_enabled":false,"verified":false,"statuses_count":549,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"ACDED6","profile_background_image_url":"http://a0.twimg.com/images/themes/theme18/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme18/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/3690118960/3bf92c8b7f1398f35e635f0d08bde368_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3690118960/3bf92c8b7f1398f35e635f0d08bde368_normal.jpeg","profile_link_color":"038543","profile_sidebar_border_color":"EEEEEE","profile_sidebar_fill_color":"F6F6F6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"atlassian","indices":[87,97]},{"text":"java","indices":[98,103]},{"text":"oracle","indices":[104,111]},{"text":"mobile","indices":[112,119]},{"text":"infra","indices":[120,126]},{"text":"jobs","indices":[127,132]}],"symbols":[],"urls":[{"url":"http://t.co/MhnnR101cT","expanded_url":"http://jobs.contribute.be","display_url":"jobs.contribute.be","indices":[64,86]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"in"},"created_at":"Fri Jul 26 19:27:56 +0000 2013","id":360843950518566914,"id_str":"360843950518566914","text":"RT @SKSMediaMalay: Rip-off or investor's dream? You decide...http://t.co/bxk76YXRJM #Bandar #Lampung #java #Sumatra #Banten #Riau #Padang //","source":"RoundTeam","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1596343046,"id_str":"1596343046","name":"Rooms_In_Lowestoft","screen_name":"RoomsLowestoft","location":"Lowestoft, Suffolk, UK","description":"#Rooms #Room to #rent #let in #Lowestoft, #Suffolk, #UK E: lowestoft@niche.me.uk \r\n\r\n#norfolk #greatyarmouth #saxmundham #ipswich #aldeburgh #leiston #tfbuk","url":"https://t.co/aeCwVfy3l0","entities":{"url":{"urls":[{"url":"https://t.co/aeCwVfy3l0","expanded_url":"https://twitter.com/RoomsLowestoft","display_url":"twitter.com/RoomsLowestoft","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":963,"friends_count":1742,"listed_count":14,"created_at":"Mon Jul 15 17:23:58 +0000 2013","favourites_count":182,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":9095,"lang":"en-gb","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/profile_background_images/378800000024425110/a2acf9f2d9bf8f8c90cb24910a71c037.jpeg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/378800000024425110/a2acf9f2d9bf8f8c90cb24910a71c037.jpeg","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/378800000138549193/b276cf4d94b9c96e5b61c92f9864615f_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/378800000138549193/b276cf4d94b9c96e5b61c92f9864615f_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/1596343046/1373917379","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"metadata":{"result_type":"recent","iso_language_code":"in"},"created_at":"Fri Jul 26 19:20:50 +0000 2013","id":360842165292773376,"id_str":"360842165292773376","text":"Rip-off or investor's dream? You decide...http://t.co/bxk76YXRJM #Bandar #Lampung #java #Sumatra #Banten #Riau #Padang //","source":"HootSuite","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1449573356,"id_str":"1449573356","name":"SKS Media Malaysia","screen_name":"SKSMediaMalay","location":"Kuala Lumpur","description":"Pemasaran syarikat perkhidmatan.\r\n\r\n#teamfollowback #tfb #tfbjp #autofollow #followback","url":"https://t.co/nfmdo6g6HC","entities":{"url":{"urls":[{"url":"https://t.co/nfmdo6g6HC","expanded_url":"https://twitter.com/SKSMediaMalay","display_url":"twitter.com/SKSMediaMalay","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":1048,"friends_count":877,"listed_count":27,"created_at":"Wed May 22 18:07:31 +0000 2013","favourites_count":166,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":8006,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/profile_background_images/874883247/77db35ff9cff8c42d2ef4c2bcd22df35.jpeg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/874883247/77db35ff9cff8c42d2ef4c2bcd22df35.jpeg","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/3695357949/77db35ff9cff8c42d2ef4c2bcd22df35_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3695357949/77db35ff9cff8c42d2ef4c2bcd22df35_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":1,"favorite_count":0,"entities":{"hashtags":[{"text":"Bandar","indices":[65,72]},{"text":"Lampung","indices":[73,81]},{"text":"java","indices":[82,87]},{"text":"Sumatra","indices":[88,96]},{"text":"Banten","indices":[97,104]},{"text":"Riau","indices":[105,110]},{"text":"Padang","indices":[111,118]}],"symbols":[],"urls":[{"url":"http://t.co/bxk76YXRJM","expanded_url":"http://tinyurl.com/dxxrao5","display_url":"tinyurl.com/dxxrao5","indices":[42,64]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"in"},"retweet_count":1,"favorite_count":0,"entities":{"hashtags":[{"text":"Bandar","indices":[84,91]},{"text":"Lampung","indices":[92,100]},{"text":"java","indices":[101,106]},{"text":"Sumatra","indices":[107,115]},{"text":"Banten","indices":[116,123]},{"text":"Riau","indices":[124,129]},{"text":"Padang","indices":[130,137]}],"symbols":[],"urls":[{"url":"http://t.co/bxk76YXRJM","expanded_url":"http://tinyurl.com/dxxrao5","display_url":"tinyurl.com/dxxrao5","indices":[61,83]}],"user_mentions":[{"screen_name":"SKSMediaMalay","name":"SKS Media Malaysia","id":1449573356,"id_str":"1449573356","indices":[3,17]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"in"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:25:27 +0000 2013","id":360843324011184128,"id_str":"360843324011184128","text":"#Java #Developer #BackEnd position open in #Dallas TX. #BED #BE #JavaDev Apply Online Today! - http://t.co/oVDyhoR65M","source":"HootSuite","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":52097984,"id_str":"52097984","name":"InSource Group","screen_name":"InSourcegroup","location":"Dallas, Texas","description":"Technical Resource & Contract Staffing Provider with offices in Dallas, Fort Worth, and Houston.","url":"http://t.co/IyUTPyeCMm","entities":{"url":{"urls":[{"url":"http://t.co/IyUTPyeCMm","expanded_url":"http://www.insourcegroup.com","display_url":"insourcegroup.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":1712,"friends_count":1899,"listed_count":63,"created_at":"Mon Jun 29 16:03:36 +0000 2009","favourites_count":81,"utc_offset":-18000,"time_zone":"Central Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":43289,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http://a0.twimg.com/profile_background_images/57804915/nvoffice.br.jpg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/57804915/nvoffice.br.jpg","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/1109935707/insource-fb_normal.gif","profile_image_url_https":"https://si0.twimg.com/profile_images/1109935707/insource-fb_normal.gif","profile_banner_url":"https://pbs.twimg.com/profile_banners/52097984/1369854759","profile_link_color":"0083FF","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"7ABAE6","profile_text_color":"000000","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Java","indices":[0,5]},{"text":"Developer","indices":[6,16]},{"text":"BackEnd","indices":[17,25]},{"text":"Dallas","indices":[43,50]},{"text":"BED","indices":[55,59]},{"text":"BE","indices":[60,63]},{"text":"JavaDev","indices":[64,72]}],"symbols":[],"urls":[{"url":"http://t.co/oVDyhoR65M","expanded_url":"http://ow.ly/nkcSS","display_url":"ow.ly/nkcSS","indices":[95,117]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:22:18 +0000 2013","id":360842533410045954,"id_str":"360842533410045954","text":"3,2,1... Stir and energy will be served! #coffee #addict #givemecaffine #java http://t.co/OjGso3pbPt","source":"Instagram","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":17855557,"id_str":"17855557","name":"Heather Cereghino","screen_name":"HeatherCinOC","location":"Orange County, CA","description":"Social media-lite, creative writing (beach + laptop = bliss), Event Planner, PR, cook in the making, love the outdoors, traveling & shoes. PS. I love shoes!","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":4114,"friends_count":4410,"listed_count":232,"created_at":"Thu Dec 04 01:19:51 +0000 2008","favourites_count":218,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":12505,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"B2DFDA","profile_background_image_url":"http://a0.twimg.com/images/themes/theme13/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme13/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/3673021821/693873aafc52e32076ff85d68302ff78_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3673021821/693873aafc52e32076ff85d68302ff78_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/17855557/1370094052","profile_link_color":"93A644","profile_sidebar_border_color":"EEEEEE","profile_sidebar_fill_color":"FFFFFF","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"coffee","indices":[41,48]},{"text":"addict","indices":[49,56]},{"text":"givemecaffine","indices":[57,71]},{"text":"java","indices":[72,77]}],"symbols":[],"urls":[{"url":"http://t.co/OjGso3pbPt","expanded_url":"http://instagram.com/p/cPZ9yEqwlf/","display_url":"instagram.com/p/cPZ9yEqwlf/","indices":[78,100]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"in"},"created_at":"Fri Jul 26 19:20:50 +0000 2013","id":360842165292773376,"id_str":"360842165292773376","text":"Rip-off or investor's dream? You decide...http://t.co/bxk76YXRJM #Bandar #Lampung #java #Sumatra #Banten #Riau #Padang //","source":"HootSuite","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1449573356,"id_str":"1449573356","name":"SKS Media Malaysia","screen_name":"SKSMediaMalay","location":"Kuala Lumpur","description":"Pemasaran syarikat perkhidmatan.\r\n\r\n#teamfollowback #tfb #tfbjp #autofollow #followback","url":"https://t.co/nfmdo6g6HC","entities":{"url":{"urls":[{"url":"https://t.co/nfmdo6g6HC","expanded_url":"https://twitter.com/SKSMediaMalay","display_url":"twitter.com/SKSMediaMalay","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":1048,"friends_count":877,"listed_count":27,"created_at":"Wed May 22 18:07:31 +0000 2013","favourites_count":166,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":8006,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/profile_background_images/874883247/77db35ff9cff8c42d2ef4c2bcd22df35.jpeg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/874883247/77db35ff9cff8c42d2ef4c2bcd22df35.jpeg","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/3695357949/77db35ff9cff8c42d2ef4c2bcd22df35_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3695357949/77db35ff9cff8c42d2ef4c2bcd22df35_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":1,"favorite_count":0,"entities":{"hashtags":[{"text":"Bandar","indices":[65,72]},{"text":"Lampung","indices":[73,81]},{"text":"java","indices":[82,87]},{"text":"Sumatra","indices":[88,96]},{"text":"Banten","indices":[97,104]},{"text":"Riau","indices":[105,110]},{"text":"Padang","indices":[111,118]}],"symbols":[],"urls":[{"url":"http://t.co/bxk76YXRJM","expanded_url":"http://tinyurl.com/dxxrao5","display_url":"tinyurl.com/dxxrao5","indices":[42,64]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"in"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:20:08 +0000 2013","id":360841988431556609,"id_str":"360841988431556609","text":"Took 8397ms to processing 200 tweets #JAVA #APPENGINE #1374866408704","source":"You Can't Be Wrong","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1186398894,"id_str":"1186398894","name":"You Can't Be Wrong","screen_name":"YouCantBeWrong","location":"@tegaralaga's mind","description":"User generated content text game based on Twitter. For more information send your email to tegaralaga(at)live(dot)com","url":"http://t.co/Jto68Xkf","entities":{"url":{"urls":[{"url":"http://t.co/Jto68Xkf","expanded_url":"http://google.co.id/","display_url":"google.co.id","indices":[0,20]}]},"description":{"urls":[]}},"protected":false,"followers_count":8,"friends_count":1,"listed_count":1,"created_at":"Sat Feb 16 14:30:21 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":22815,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/3261474447/f3cabcc48d277be37e45ac7b1038d73e_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3261474447/f3cabcc48d277be37e45ac7b1038d73e_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/1186398894/1361117710","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"JAVA","indices":[37,42]},{"text":"APPENGINE","indices":[43,53]}],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:18:09 +0000 2013","id":360841487262547968,"id_str":"360841487262547968","text":"Can’t decide between more #java or #c++","source":"Tweetbot for iOS","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":29063267,"id_str":"29063267","name":"Steven Truesdell","screen_name":"TrueSteve","location":"Denver, CO","description":"Snowboarder. Photographer. Web Designer. Journalist. Music lover. Soon to be Firefighter & EMT","url":"http://t.co/fCPFLstB49","entities":{"url":{"urls":[{"url":"http://t.co/fCPFLstB49","expanded_url":"http://www.steventruesdell.com","display_url":"steventruesdell.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":88,"friends_count":144,"listed_count":3,"created_at":"Sun Apr 05 21:02:17 +0000 2009","favourites_count":0,"utc_offset":-21600,"time_zone":"Mountain Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":1792,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"1A1B1F","profile_background_image_url":"http://a0.twimg.com/images/themes/theme9/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme9/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/3637401835/e96f6955cd6bfd3d7bf78002ebdbd0de_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/3637401835/e96f6955cd6bfd3d7bf78002ebdbd0de_normal.jpeg","profile_link_color":"2FC2EF","profile_sidebar_border_color":"181A1E","profile_sidebar_fill_color":"252429","profile_text_color":"666666","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":{"id":"2571b7720cd62ad3","url":"https://api.twitter.com/1.1/geo/id/2571b7720cd62ad3.json","place_type":"city","name":"Highlands Ranch","full_name":"Highlands Ranch, CO","country_code":"US","country":"United States","bounding_box":{"type":"Polygon","coordinates":[[[-105.05306,39.510546],[-104.899484,39.510546],[-104.899484,39.566782],[-105.05306,39.566782]]]},"attributes":{}},"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"java","indices":[26,31]},{"text":"c","indices":[35,37]}],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"pt"},"created_at":"Fri Jul 26 19:17:48 +0000 2013","id":360841400004251648,"id_str":"360841400004251648","text":"RT @maribalbe: No Brasil? Piada! RT @rogerio_gentil: Desenvolvedores em #PHP e #Java ganham até R$ 9 mil http://t.co/Cj6dotO8Be // #souDev","source":"TweetDeck","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":188855964,"id_str":"188855964","name":"Rodrigo Baron","screen_name":"b4r0n__","location":"Medianeira","description":"Full-stack Rails Developer. Addicts script codes and Internet App Dev. Startup Co-Founder: http://t.co/Vvj2Un84yC","url":"http://t.co/WEJSgUafv6","entities":{"url":{"urls":[{"url":"http://t.co/WEJSgUafv6","expanded_url":"http://about.me/baron.rodrigo","display_url":"about.me/baron.rodrigo","indices":[0,22]}]},"description":{"urls":[{"url":"http://t.co/Vvj2Un84yC","expanded_url":"http://www.saifer.com.br","display_url":"saifer.com.br","indices":[91,113]}]}},"protected":false,"followers_count":121,"friends_count":183,"listed_count":1,"created_at":"Thu Sep 09 19:15:20 +0000 2010","favourites_count":105,"utc_offset":-10800,"time_zone":"Brasilia","geo_enabled":true,"verified":false,"statuses_count":3777,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http://a0.twimg.com/images/themes/theme14/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme14/bg.gif","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/378800000105833766/cfe4372a0fce180e09813ab02f909a4d_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/378800000105833766/cfe4372a0fce180e09813ab02f909a4d_normal.jpeg","profile_link_color":"006DCC","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EFEFEF","profile_text_color":"333333","profile_use_background_image":false,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"metadata":{"result_type":"recent","iso_language_code":"pt"},"created_at":"Fri Jul 26 14:37:46 +0000 2013","id":360770928357027840,"id_str":"360770928357027840","text":"No Brasil? Piada! RT @rogerio_gentil: Desenvolvedores em #PHP e #Java ganham até R$ 9 mil http://t.co/Cj6dotO8Be // #souDev","source":"TweetDeck","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":41602902,"id_str":"41602902","name":"Marília Balbé","screen_name":"maribalbe","location":"Florianópolis, Brazil","description":"Certified Scrum Master. MCTS Microsoft Project 2010, Managing Projects. MTAC. Gaúcha. Feeling. Liderança. Agilidade. Follow me!","url":"http://t.co/v7BRmRMPEn","entities":{"url":{"urls":[{"url":"http://t.co/v7BRmRMPEn","expanded_url":"http://mariliabalbe.com","display_url":"mariliabalbe.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":2065,"friends_count":1464,"listed_count":81,"created_at":"Thu May 21 15:05:11 +0000 2009","favourites_count":51,"utc_offset":-10800,"time_zone":"Brasilia","geo_enabled":true,"verified":false,"statuses_count":26222,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"9AE4E8","profile_background_image_url":"http://a0.twimg.com/images/themes/theme16/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme16/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/2914714002/d2b0d4771ad8c92841a8d6a37d24c920_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/2914714002/d2b0d4771ad8c92841a8d6a37d24c920_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"BDDCAD","profile_sidebar_fill_color":"DDFFCC","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":21,"favorite_count":1,"entities":{"hashtags":[{"text":"PHP","indices":[57,61]},{"text":"Java","indices":[64,69]},{"text":"souDev","indices":[116,123]}],"symbols":[],"urls":[{"url":"http://t.co/Cj6dotO8Be","expanded_url":"http://lnkd.in/zsQhdg","display_url":"lnkd.in/zsQhdg","indices":[90,112]}],"user_mentions":[{"screen_name":"rogerio_gentil","name":"Rogerio J. Gentil","id":71697548,"id_str":"71697548","indices":[21,36]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"pt"},"retweet_count":21,"favorite_count":0,"entities":{"hashtags":[{"text":"PHP","indices":[72,76]},{"text":"Java","indices":[79,84]},{"text":"souDev","indices":[131,138]}],"symbols":[],"urls":[{"url":"http://t.co/Cj6dotO8Be","expanded_url":"http://lnkd.in/zsQhdg","display_url":"lnkd.in/zsQhdg","indices":[105,127]}],"user_mentions":[{"screen_name":"maribalbe","name":"Marília Balbé","id":41602902,"id_str":"41602902","indices":[3,13]},{"screen_name":"rogerio_gentil","name":"Rogerio J. Gentil","id":71697548,"id_str":"71697548","indices":[36,51]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"pt"},{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 19:16:15 +0000 2013","id":360841008411447296,"id_str":"360841008411447296","text":"RT @danielleandy: Finding a way to have our morning coffee together! #bestneighbors #technology #java #screenshot… http://t.co/ZakQ5Ip16C","source":"Twitter for iPhone","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":169605040,"id_str":"169605040","name":"Bucko","screen_name":"jonathonbuckley","location":"Los Angeles","description":"","url":"http://t.co/Vsgepye3eK","entities":{"url":{"urls":[{"url":"http://t.co/Vsgepye3eK","expanded_url":"http://jonathonbuckley.com","display_url":"jonathonbuckley.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":2059,"friends_count":116,"listed_count":86,"created_at":"Thu Jul 22 18:56:12 +0000 2010","favourites_count":5,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":436,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"1A1B1F","profile_background_image_url":"http://a0.twimg.com/images/themes/theme9/bg.gif","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme9/bg.gif","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/1097180716/8X10_6255_no_pink_small_normal.jpg","profile_image_url_https":"https://si0.twimg.com/profile_images/1097180716/8X10_6255_no_pink_small_normal.jpg","profile_link_color":"2FC2EF","profile_sidebar_border_color":"181A1E","profile_sidebar_fill_color":"252429","profile_text_color":"666666","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Jul 26 16:44:25 +0000 2013","id":360802801032499200,"id_str":"360802801032499200","text":"Finding a way to have our morning coffee together! #bestneighbors #technology #java #screenshot… http://t.co/ZakQ5Ip16C","source":"Instagram","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":259458041,"id_str":"259458041","name":"Danielle Anderson","screen_name":"danielleandy","location":"Los Angeles ","description":"","url":"http://t.co/JiAcLT2Wfg","entities":{"url":{"urls":[{"url":"http://t.co/JiAcLT2Wfg","expanded_url":"http://www.danielleandy.com","display_url":"danielleandy.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":209,"friends_count":127,"listed_count":3,"created_at":"Tue Mar 01 23:31:29 +0000 2011","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":1451,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/378800000130553531/82c57daecf779a8d61f17a53a44d31d3_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/378800000130553531/82c57daecf779a8d61f17a53a44d31d3_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/259458041/1373653784","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":1,"favorite_count":0,"entities":{"hashtags":[{"text":"bestneighbors","indices":[51,65]},{"text":"technology","indices":[66,77]},{"text":"java","indices":[79,84]},{"text":"screenshot","indices":[85,96]}],"symbols":[],"urls":[{"url":"http://t.co/ZakQ5Ip16C","expanded_url":"http://instagram.com/p/cPHow7KIcS/","display_url":"instagram.com/p/cPHow7KIcS/","indices":[98,120]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},"retweet_count":1,"favorite_count":0,"entities":{"hashtags":[{"text":"bestneighbors","indices":[69,83]},{"text":"technology","indices":[84,95]},{"text":"java","indices":[97,102]},{"text":"screenshot","indices":[103,114]}],"symbols":[],"urls":[{"url":"http://t.co/ZakQ5Ip16C","expanded_url":"http://instagram.com/p/cPHow7KIcS/","display_url":"instagram.com/p/cPHow7KIcS/","indices":[116,138]}],"user_mentions":[{"screen_name":"danielleandy","name":"Danielle Anderson","id":259458041,"id_str":"259458041","indices":[3,16]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"result_type":"recent","iso_language_code":"in"},"created_at":"Fri Jul 26 19:11:01 +0000 2013","id":360839690812784641,"id_str":"360839690812784641","text":"Rip-off or investor's dream? You decide...http://t.co/yLzRPs1Qly #Bandar #Lampung #java #Sumatra #Banten #Riau #Padang //","source":"HootSuite","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":854562582,"id_str":"854562582","name":"SKS Media Londres","screen_name":"SKSMediaLondres","location":"","description":"Nous sommes aussi #teamfollowback #followback @sksfollowback","url":"http://t.co/g6dzOOabDQ","entities":{"url":{"urls":[{"url":"http://t.co/g6dzOOabDQ","expanded_url":"http://www.niche-advertising.co.uk","display_url":"niche-advertising.co.uk","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":1972,"friends_count":1380,"listed_count":100,"created_at":"Sun Sep 30 11:39:09 +0000 2012","favourites_count":439,"utc_offset":7200,"time_zone":"Amsterdam","geo_enabled":false,"verified":false,"statuses_count":144790,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/profile_background_images/673161806/9c3894fdf100336e2f53e97bffeace6c.jpeg","profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/673161806/9c3894fdf100336e2f53e97bffeace6c.jpeg","profile_background_tile":true,"profile_image_url":"http://a0.twimg.com/profile_images/2665504502/86c0fc8adfb2d7f13e687f7dbfddf876_normal.jpeg","profile_image_url_https":"https://si0.twimg.com/profile_images/2665504502/86c0fc8adfb2d7f13e687f7dbfddf876_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Bandar","indices":[65,72]},{"text":"Lampung","indices":[73,81]},{"text":"java","indices":[82,87]},{"text":"Sumatra","indices":[88,96]},{"text":"Banten","indices":[97,104]},{"text":"Riau","indices":[105,110]},{"text":"Padang","indices":[111,118]}],"symbols":[],"urls":[{"url":"http://t.co/yLzRPs1Qly","expanded_url":"http://tinyurl.com/dxxrao5","display_url":"tinyurl.com/dxxrao5","indices":[42,64]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"in"}],"search_metadata":{"completed_in":0.033,"max_id":360844831439855616,"max_id_str":"360844831439855616","next_results":"?max_id=360839690812784640&q=%23java&include_entities=1","query":"%23java","refresh_url":"?since_id=360844831439855616&q=%23java&include_entities=1","count":15,"since_id":0,"since_id_str":"0"}} - diff --git a/impl/src/test/resources/wiki.json b/impl/src/test/resources/wiki.json deleted file mode 100644 index 17bb1932..00000000 --- a/impl/src/test/resources/wiki.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "firstName": "John", - "lastName": "Smith", - "age": 25, - "address": { - "streetAddress": "21 2nd Street", - "city": "New York", - "state": "NY", - "postalCode": "10021" - }, - "phoneNumber": [ - { - "type": "home", - "number": "212 555-1234" - }, - { - "type": "fax", - "number": "646 555-4567" - } - ] -} diff --git a/jaxrs/pom.xml b/jaxrs/pom.xml deleted file mode 100644 index b29df8d2..00000000 --- a/jaxrs/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - 4.0.0 - - - org.eclipse.jsonp - json - 2.0.2-SNAPSHOT - ../pom.xml - - - org.eclipse.jsonp - jsonp-jaxrs - jar - 2.0.2-SNAPSHOT - Jakarta JSON Processing Media for Jakarta RESTful Web Services - Jakarta RESTful Web Services MessageBodyReader and MessageBodyWriter to support JsonValue API of Jakarta JSON Processing - - - - jakarta.json - jakarta.json-api - provided - - - jakarta.ws.rs - jakarta.ws.rs-api - provided - - - jakarta.xml.bind - jakarta.xml.bind-api - provided - - - jakarta.annotation - jakarta.annotation-api - provided - - - - - - - org.apache.felix - maven-bundle-plugin - - - bundle-manifest - process-classes - - manifest - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - - diff --git a/jaxrs/src/main/java/module-info.java b/jaxrs/src/main/java/module-info.java deleted file mode 100644 index 02eb5d30..00000000 --- a/jaxrs/src/main/java/module-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -module org.eclipse.jsonp.jaxrs { - - requires jakarta.json; - requires jakarta.annotation; - requires jakarta.ws.rs; - - exports org.eclipse.jsonp.jaxrs; - -} diff --git a/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyReader.java b/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyReader.java deleted file mode 100644 index 758b644d..00000000 --- a/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyReader.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.jaxrs; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import jakarta.json.Json; -import jakarta.json.JsonReader; -import jakarta.json.JsonReaderFactory; -import jakarta.json.JsonValue; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.WebApplicationException; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.ext.MessageBodyReader; -import jakarta.ws.rs.ext.Provider; - -/** - * Jakarta RESTful Web Services MessageBodyReader for JsonValue. - * This allows JsonValue to be a parameter of a resource method. - * - * @author Jitendra Kotamraju - * @author Blaise Doughan - * @author Michal Gajdos - */ -@Provider -@Consumes({"application/json", "text/json", "*/*"}) -public class JsonValueBodyReader implements MessageBodyReader { - private final JsonReaderFactory rf = Json.createReaderFactory(null); - - private static final String JSON = "json"; - private static final String PLUS_JSON = "+json"; - - @Override - public boolean isReadable(Class aClass, Type type, - Annotation[] annotations, MediaType mediaType) { - return JsonValue.class.isAssignableFrom(aClass) && supportsMediaType(mediaType); - } - - /** - * @return true for all media types of the pattern */json and - * */*+json. - */ - private static boolean supportsMediaType(final MediaType mediaType) { - return mediaType.getSubtype().equals(JSON) || mediaType.getSubtype().endsWith(PLUS_JSON); - } - - @Override - public JsonValue readFrom(Class jsonValueClass, - Type type, Annotation[] annotations, MediaType mediaType, - MultivaluedMap stringStringMultivaluedMap, - InputStream inputStream) throws IOException, WebApplicationException { - try (JsonReader reader = rf.createReader(inputStream)) { - return reader.readValue(); - } - } -} diff --git a/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyWriter.java b/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyWriter.java deleted file mode 100644 index 3fbaf5c1..00000000 --- a/jaxrs/src/main/java/org/eclipse/jsonp/jaxrs/JsonValueBodyWriter.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.jaxrs; - -import java.io.IOException; -import java.io.OutputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; -import jakarta.annotation.PostConstruct; -import jakarta.json.Json; -import jakarta.json.JsonValue; -import jakarta.json.JsonWriter; -import jakarta.json.JsonWriterFactory; -import jakarta.json.stream.JsonGenerator; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.WebApplicationException; -import jakarta.ws.rs.core.Configuration; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.ext.MessageBodyWriter; -import jakarta.ws.rs.ext.Provider; - -/** - * Jakarta RESTful Web Services MessageBodyWriter for JsonValue. - * This allows JsonValue to be return type of a resource method. - * - * @author Jitendra Kotamraju - * @author Blaise Doughan - * @author Michal Gajdos - */ -@Provider -@Produces({"application/json", "text/json", "*/*"}) -public class JsonValueBodyWriter implements MessageBodyWriter { - private static final String JSON = "json"; - private static final String PLUS_JSON = "+json"; - - private JsonWriterFactory wf = Json.createWriterFactory(null); - - @Context - private Configuration config; - - @PostConstruct - private void init() { - Map props = new HashMap<>(); - if (config != null && config.getProperties().containsKey(JsonGenerator.PRETTY_PRINTING)) { - props.put(JsonGenerator.PRETTY_PRINTING, true); - } - wf = Json.createWriterFactory(props); - } - - @Override - public boolean isWriteable(Class aClass, - Type type, Annotation[] annotations, MediaType mediaType) { - return JsonValue.class.isAssignableFrom(aClass) && supportsMediaType(mediaType); - } - - /** - * @return true for all media types of the pattern */json and - * */*+json. - */ - private static boolean supportsMediaType(final MediaType mediaType) { - return mediaType.getSubtype().equals(JSON) || mediaType.getSubtype().endsWith(PLUS_JSON); - } - - @Override - public long getSize(JsonValue jsonValue, Class aClass, - Type type, Annotation[] annotations, MediaType mediaType) { - - return -1; - } - - @Override - public void writeTo(JsonValue jsonValue, Class aClass, Type type, - Annotation[] annotations, MediaType mediaType, - MultivaluedMap stringObjectMultivaluedMap, - OutputStream outputStream) throws IOException, WebApplicationException { - try (JsonWriter writer = wf.createWriter(outputStream)) { - writer.write(jsonValue); - } - } -} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 4a2131c4..00000000 --- a/pom.xml +++ /dev/null @@ -1,502 +0,0 @@ - - - - - 4.0.0 - - - org.eclipse.ee4j - project - 1.0.6 - - - org.eclipse.jsonp - json - pom - 2.0.2-SNAPSHOT - Jakarta JSON Processing - Jakarta JSON Processing defines a Java(R) based framework for parsing, generating, transforming, and querying JSON documents. - https://github.com/eclipse-ee4j/jsonp - - - scm:git:git://github.com/eclipse-ee4j/jsonp.git - scm:git:git@github.com:eclipse-ee4j/jsonp.git - https://github.com/eclipse-ee4j/jsonp - HEAD - - - - - Eclipse Public License 2.0 - https://projects.eclipse.org/license/epl-2.0 - repo - - - GNU General Public License, version 2 with the GNU Classpath Exception - https://projects.eclipse.org/license/secondary-gpl-2.0-cp - repo - - - - - - m0mus - Dmitry Kornilov - Oracle - - project lead - - - - lukasj - Lukas Jungmann - Oracle - - dev lead - - - - - - jakarta.json - org.eclipse.jsonp - 2.0 - 2.1 - 2.1.0 - ${project.version} - 2.1.0 - false - ${maven.multiModuleProjectDirectory} - ${project.root.location}/etc/config - ${config.dir}/copyright-exclude - ${config.dir}/copyright.txt - false - true - false - ${config.dir}/exclude.xml - false - Low - 4.2.2 - - 2.0.1 - - 2.0.0 - 3.0.1 - 3.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-maven - - enforce - - - - - [11,) - - - [3.6.0,) - - - - - - - - org.commonjava.maven.plugins - directory-maven-plugin - - - find-project-root - validate - - highest-basedir - - - project.root.location - - - - - - org.codehaus.mojo - buildnumber-maven-plugin - - true - false - 7 - - - - validate - - create - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 9 - - -Xlint:all - - - - - base-compile - - compile - - - 8 - - module-info.java - - - - - - - - - org.glassfish.copyright - glassfish-copyright-maven-plugin - - ${copyright.templatefile} - ${copyright.exclude} - - ${copyright.scmonly} - - ${copyright.update} - - ${copyright.ignoreyear} - false - - - - - check - - verify - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-legal-resource - generate-resources - - add-resource - - - - - ${legal.doc.source} - - NOTICE.md - LICENSE.md - - META-INF - - - - - - - - org.apache.maven.plugins - maven-source-plugin - - - - false - true - - - ${project.version} - ${buildNumber} - - - - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-release-plugin - - forked-path - false - ${release.arguments} - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - org.commonjava.maven.plugins - directory-maven-plugin - 0.3.1 - - - org.codehaus.mojo - buildnumber-maven-plugin - 1.4 - - - com.github.spotbugs - spotbugs-maven-plugin - ${spotbugs.version} - - - org.glassfish.build - spec-version-maven-plugin - 2.1 - - - org.glassfish.copyright - glassfish-copyright-maven-plugin - 2.4 - - - org.apache.felix - maven-bundle-plugin - 5.1.2 - - true - - <_noextraheaders>true - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-dependency-plugin - 3.1.2 - - - org.apache.maven.plugins - maven-resources-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-antrun-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.9.1 - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - - - org.apache.maven.plugins - maven-assembly-plugin - 3.3.0 - - - - - - - - - jakarta.ws.rs - jakarta.ws.rs-api - ${jakarta.ws.rs-api.version} - - - jakarta.annotation - jakarta.annotation-api - ${jakarta.annotation-api.version} - - - jakarta.json - jakarta.json-api - ${jakarta.json-api.version} - - - org.eclipse.jsonp - jsonp - ${project.version} - - - org.eclipse.jsonp - jakarta.json - ${project.version} - - - org.eclipse.jsonp - jsonp-jaxrs - ${project.version} - - - jakarta.xml.bind - jakarta.xml.bind-api - ${jakarta.xml.bind-api.version} - - - junit - junit - 4.13.2 - - - org.hamcrest - hamcrest-core - 1.3 - test - - - - - - impl - jaxrs - bundles - - - - - all - - - - - jakarta.servlet - jakarta.servlet-api - 5.0.0 - - - com.sun.xml.bind - jaxb-impl - 3.0.0 - - - - - - providers - demos - - - - - - - org.apache.maven.plugins - maven-war-plugin - 3.3.1 - - false - - - - org.codehaus.mojo - wagon-maven-plugin - 2.0.2 - - - org.codehaus.mojo - exec-maven-plugin - 3.0.0 - - - - - - - - - - - com.github.spotbugs - spotbugs-maven-plugin - - ${spotbugs.skip} - ${spotbugs.threshold} - true - - ${spotbugs.exclude} - - true - - - - - - diff --git a/providers/customprovider/pom.xml b/providers/customprovider/pom.xml deleted file mode 100644 index fd7e816a..00000000 --- a/providers/customprovider/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - providers - 2.0.2-SNAPSHOT - ../pom.xml - - - war - http://maven.apache.org - customprovider - - customprovider - - - customprovider - - diff --git a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestGenerator.java b/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestGenerator.java deleted file mode 100644 index 4c7fb80b..00000000 --- a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestGenerator.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.customprovider; - -import jakarta.json.JsonException; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonGenerator; -import java.io.IOException; -import java.io.Writer; -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * @author Jitendra Kotamraju - */ -public class TestGenerator implements JsonGenerator { - private final Writer writer; - - public TestGenerator(Writer writer) { - this.writer = writer; - } - - @Override - public void flush() { - } - - @Override - public JsonGenerator writeStartObject() { - return null; - } - - @Override - public JsonGenerator writeStartObject(String name) { - return null; - } - - @Override - public JsonGenerator write(String name, String fieldValue) { - return null; - } - - @Override - public JsonGenerator write(String name, int value) { - return null; - } - - @Override - public JsonGenerator write(String name, long value) { - return null; - } - - @Override - public JsonGenerator write(String name, double value) { - return null; - } - - @Override - public JsonGenerator write(String name, BigInteger value) { - return null; - } - - @Override - public JsonGenerator write(String name, BigDecimal value) { - return null; - } - - @Override - public JsonGenerator write(String name, boolean value) { - return null; - } - - @Override - public JsonGenerator writeNull(String name) { - return null; - } - - @Override - public JsonGenerator write(JsonValue value) { - return null; - } - - @Override - public JsonGenerator writeStartArray() { - try { - writer.write("["); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - return this; - } - - @Override - public JsonGenerator writeStartArray(String name) { - return null; - } - - @Override - public JsonGenerator write(String name, JsonValue value) { - return null; - } - - @Override - public JsonGenerator write(String value) { - return null; - } - - - @Override - public JsonGenerator write(int value) { - return null; - } - - @Override - public JsonGenerator write(long value) { - return null; - } - - @Override - public JsonGenerator write(double value) { - return null; - } - - @Override - public JsonGenerator write(BigInteger value) { - return null; - } - - @Override - public JsonGenerator write(BigDecimal value) { - return null; - } - - @Override - public JsonGenerator write(boolean value) { - return null; - } - - @Override - public JsonGenerator writeNull() { - return null; - } - - @Override - public JsonGenerator writeEnd() { - try { - writer.write("]"); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - return this; - } - - @Override - public void close() { - try { - writer.close(); - } catch(IOException ioe) { - throw new JsonException("I/O error", ioe); - } - } - - @Override - public JsonGenerator writeKey(String name) { - return null; - } - -} diff --git a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestProvider.java b/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestProvider.java deleted file mode 100644 index b0c24d23..00000000 --- a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestProvider.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.customprovider; - -import jakarta.json.*; -import jakarta.json.spi.JsonProvider; -import jakarta.json.stream.JsonGenerator; -import jakarta.json.stream.JsonGeneratorFactory; -import jakarta.json.stream.JsonParser; -import jakarta.json.stream.JsonParserFactory; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.util.Map; - -/** - * @author Jitendra Kotamraju - */ -public class TestProvider extends JsonProvider { - - @Override - public JsonGenerator createGenerator(Writer writer) { - return new TestGenerator(writer); - } - - @Override - public JsonGenerator createGenerator(OutputStream out) { - return null; - } - - @Override - public JsonGeneratorFactory createGeneratorFactory(Map config) { - return null; - } - - @Override - public JsonReader createReader(Reader reader) { - return null; - } - - @Override - public JsonReader createReader(InputStream in) { - return null; - } - - @Override - public JsonWriter createWriter(Writer writer) { - return null; - } - - @Override - public JsonWriter createWriter(OutputStream out) { - return null; - } - - @Override - public JsonWriterFactory createWriterFactory(Map config) { - return null; - } - - @Override - public JsonReaderFactory createReaderFactory(Map config) { - return null; - } - - @Override - public JsonObjectBuilder createObjectBuilder() { - return null; - } - - @Override - public JsonArrayBuilder createArrayBuilder() { - return null; - } - - @Override - public JsonBuilderFactory createBuilderFactory(Map config) { - return null; - } - - @Override - public JsonParser createParser(Reader reader) { - return null; - } - - @Override - public JsonParser createParser(InputStream in) { - return null; - } - - @Override - public JsonParserFactory createParserFactory(Map config) { - return null; - } - - -} diff --git a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestServlet.java b/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestServlet.java deleted file mode 100644 index dca14512..00000000 --- a/providers/customprovider/src/main/java/org/eclipse/jsonp/customprovider/TestServlet.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.customprovider; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; - -import jakarta.servlet.ServletException; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import jakarta.json.Json; -import jakarta.json.stream.JsonGenerator; - -/** - * @author Jitendra Kotamraju - */ -@WebServlet("/json") -public class TestServlet extends HttpServlet { - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { - try { - res.setStatus(200); - res.setContentType("application/json"); - OutputStream os = res.getOutputStream(); - JsonGenerator generator = Json.createGenerator(new OutputStreamWriter(os)); - if (!(generator instanceof TestGenerator)) { - throw new RuntimeException("MyGenerator is not picked up"); - } - generator.writeStartArray().writeEnd(); - generator.close(); - os.close(); - } catch (IOException ioe) { - throw new ServletException(ioe); - } - } - -} diff --git a/providers/customprovider/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider b/providers/customprovider/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider deleted file mode 100644 index f0c02033..00000000 --- a/providers/customprovider/src/main/resources/META-INF/services/jakarta.json.spi.JsonProvider +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.jsonp.customprovider.TestProvider diff --git a/providers/defaultprovider/pom.xml b/providers/defaultprovider/pom.xml deleted file mode 100644 index f49a4847..00000000 --- a/providers/defaultprovider/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - providers - 2.0.2-SNAPSHOT - ../pom.xml - - - war - http://maven.apache.org - defaultprovider - - defaultprovider - - - defaultprovider - - diff --git a/providers/defaultprovider/src/main/java/org/eclipse/jsonp/defaultprovider/TestServlet.java b/providers/defaultprovider/src/main/java/org/eclipse/jsonp/defaultprovider/TestServlet.java deleted file mode 100644 index a85bb6f6..00000000 --- a/providers/defaultprovider/src/main/java/org/eclipse/jsonp/defaultprovider/TestServlet.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.eclipse.jsonp.defaultprovider; - -import jakarta.servlet.annotation.*; -import jakarta.servlet.http.*; -import jakarta.servlet.*; -import java.io.IOException; -import jakarta.json.*; -import jakarta.json.stream.*; -import java.io.*; - -/** - * @author Jitendra Kotamraju - */ -@WebServlet("/json") -public class TestServlet extends HttpServlet { - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { - try { - res.setStatus(200); - res.setContentType("application/json"); - OutputStream os = res.getOutputStream(); - JsonGenerator generator = Json.createGenerator(os); - generator.writeStartArray().writeEnd(); - generator.close(); - } catch(IOException ioe) { - throw new ServletException(ioe); - } - } - -} diff --git a/providers/pom.xml b/providers/pom.xml deleted file mode 100644 index 7446d9b9..00000000 --- a/providers/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - 4.0.0 - - - org.eclipse.jsonp - json - 2.0.2-SNAPSHOT - ../pom.xml - - - pom - http://maven.apache.org - org.eclipse.jsonp - providers - - - - jakarta.servlet - jakarta.servlet-api - provided - - - jakarta.json - jakarta.json-api - provided - - - - - - org.apache.maven.plugins - maven-war-plugin - - - customprovider - - - customprovider - defaultprovider - -