From d3d328085e9b4e3fa32f86eb19139872d42e428c Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:17:08 +0800 Subject: [PATCH 1/8] =?UTF-8?q?chore:=20=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codeql-analysis.yml | 43 - .github/workflows/pipeline.yml | 228 - CODE_OF_CONDUCT.md | 76 - CONTRIBUTING.md | 22 - Examples.md | 433 -- SECURITY.md | 5 - build.gradle | 55 - docs/CONTRIBUTING.md | 22 - docs/FILES.md | 62 - docs/NOTES.md | 87 - docs/RELEASES.md | 55 - docs/SECURITY.md | 5 - gradle/wrapper/gradle-wrapper.jar | Bin 58695 -> 0 bytes gradle/wrapper/gradle-wrapper.properties | 5 - gradlew | 183 - gradlew.bat | 103 - images/JsonJava.png | Bin 15697 -> 0 bytes src/test/java/org/json/junit/CDLTest.java | 322 -- .../java/org/json/junit/CookieListTest.java | 190 - src/test/java/org/json/junit/CookieTest.java | 242 -- src/test/java/org/json/junit/EnumTest.java | 433 -- src/test/java/org/json/junit/HTTPTest.java | 200 - .../java/org/json/junit/JSONArrayTest.java | 1511 ------- src/test/java/org/json/junit/JSONMLTest.java | 1015 ----- .../org/json/junit/JSONObjectLocaleTest.java | 60 - .../org/json/junit/JSONObjectNumberTest.java | 146 - .../java/org/json/junit/JSONObjectTest.java | 3864 ----------------- .../junit/JSONParserConfigurationTest.java | 313 -- .../java/org/json/junit/JSONPointerTest.java | 399 -- .../java/org/json/junit/JSONStringTest.java | 401 -- .../java/org/json/junit/JSONStringerTest.java | 357 -- .../java/org/json/junit/JSONTokenerTest.java | 328 -- .../java/org/json/junit/PropertyTest.java | 102 - .../json/junit/StringBuilderWriterTest.java | 60 - src/test/java/org/json/junit/Util.java | 201 - .../org/json/junit/XMLConfigurationTest.java | 1187 ----- src/test/java/org/json/junit/XMLTest.java | 1434 ------ .../org/json/junit/data/BrokenToString.java | 13 - .../org/json/junit/data/ExceptionalBean.java | 66 - .../java/org/json/junit/data/Fraction.java | 180 - .../java/org/json/junit/data/GenericBean.java | 79 - .../org/json/junit/data/GenericBeanInt.java | 69 - src/test/java/org/json/junit/data/MyBean.java | 16 - .../org/json/junit/data/MyBeanCustomName.java | 20 - .../junit/data/MyBeanCustomNameInterface.java | 11 - .../junit/data/MyBeanCustomNameSubClass.java | 32 - .../org/json/junit/data/MyBigNumberBean.java | 11 - src/test/java/org/json/junit/data/MyEnum.java | 10 - .../java/org/json/junit/data/MyEnumClass.java | 22 - .../java/org/json/junit/data/MyEnumField.java | 28 - .../org/json/junit/data/MyJsonString.java | 14 - .../org/json/junit/data/MyLocaleBean.java | 12 - .../java/org/json/junit/data/MyNumber.java | 97 - .../json/junit/data/MyNumberContainer.java | 13 - .../org/json/junit/data/MyPublicClass.java | 10 - .../org/json/junit/data/RecursiveBean.java | 23 - .../json/junit/data/RecursiveBeanEquals.java | 33 - .../java/org/json/junit/data/Singleton.java | 91 - .../org/json/junit/data/SingletonEnum.java | 62 - .../junit/data/StringsResourceBundle.java | 19 - .../java/org/json/junit/data/WeirdList.java | 68 - src/test/resources/Issue537.json | 189 - src/test/resources/Issue537.xml | 169 - src/test/resources/Issue593.json | 704 --- src/test/resources/Issue593.xml | 691 --- .../resources/Issue654WellFormedArray.json | 822 ---- .../resources/Issue654WellFormedObject.json | 822 ---- ...rayExpectedTestCaseForToJsonArrayTest.json | 91 - .../resources/XmlTestCaseTestToJsonArray.xml | 27 - src/test/resources/compliantJsonArray.json | 317 -- src/test/resources/jsonpointer-testdoc.json | 28 - 71 files changed, 19008 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/pipeline.yml delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Examples.md delete mode 100644 SECURITY.md delete mode 100644 build.gradle delete mode 100644 docs/CONTRIBUTING.md delete mode 100644 docs/FILES.md delete mode 100644 docs/NOTES.md delete mode 100644 docs/RELEASES.md delete mode 100644 docs/SECURITY.md delete mode 100644 gradle/wrapper/gradle-wrapper.jar delete mode 100644 gradle/wrapper/gradle-wrapper.properties delete mode 100755 gradlew delete mode 100644 gradlew.bat delete mode 100644 images/JsonJava.png delete mode 100644 src/test/java/org/json/junit/CDLTest.java delete mode 100644 src/test/java/org/json/junit/CookieListTest.java delete mode 100644 src/test/java/org/json/junit/CookieTest.java delete mode 100644 src/test/java/org/json/junit/EnumTest.java delete mode 100644 src/test/java/org/json/junit/HTTPTest.java delete mode 100644 src/test/java/org/json/junit/JSONArrayTest.java delete mode 100644 src/test/java/org/json/junit/JSONMLTest.java delete mode 100755 src/test/java/org/json/junit/JSONObjectLocaleTest.java delete mode 100644 src/test/java/org/json/junit/JSONObjectNumberTest.java delete mode 100644 src/test/java/org/json/junit/JSONObjectTest.java delete mode 100644 src/test/java/org/json/junit/JSONParserConfigurationTest.java delete mode 100644 src/test/java/org/json/junit/JSONPointerTest.java delete mode 100644 src/test/java/org/json/junit/JSONStringTest.java delete mode 100644 src/test/java/org/json/junit/JSONStringerTest.java delete mode 100644 src/test/java/org/json/junit/JSONTokenerTest.java delete mode 100644 src/test/java/org/json/junit/PropertyTest.java delete mode 100644 src/test/java/org/json/junit/StringBuilderWriterTest.java delete mode 100644 src/test/java/org/json/junit/Util.java delete mode 100755 src/test/java/org/json/junit/XMLConfigurationTest.java delete mode 100644 src/test/java/org/json/junit/XMLTest.java delete mode 100644 src/test/java/org/json/junit/data/BrokenToString.java delete mode 100644 src/test/java/org/json/junit/data/ExceptionalBean.java delete mode 100644 src/test/java/org/json/junit/data/Fraction.java delete mode 100644 src/test/java/org/json/junit/data/GenericBean.java delete mode 100644 src/test/java/org/json/junit/data/GenericBeanInt.java delete mode 100644 src/test/java/org/json/junit/data/MyBean.java delete mode 100644 src/test/java/org/json/junit/data/MyBeanCustomName.java delete mode 100644 src/test/java/org/json/junit/data/MyBeanCustomNameInterface.java delete mode 100644 src/test/java/org/json/junit/data/MyBeanCustomNameSubClass.java delete mode 100644 src/test/java/org/json/junit/data/MyBigNumberBean.java delete mode 100644 src/test/java/org/json/junit/data/MyEnum.java delete mode 100644 src/test/java/org/json/junit/data/MyEnumClass.java delete mode 100644 src/test/java/org/json/junit/data/MyEnumField.java delete mode 100644 src/test/java/org/json/junit/data/MyJsonString.java delete mode 100755 src/test/java/org/json/junit/data/MyLocaleBean.java delete mode 100644 src/test/java/org/json/junit/data/MyNumber.java delete mode 100644 src/test/java/org/json/junit/data/MyNumberContainer.java delete mode 100644 src/test/java/org/json/junit/data/MyPublicClass.java delete mode 100644 src/test/java/org/json/junit/data/RecursiveBean.java delete mode 100644 src/test/java/org/json/junit/data/RecursiveBeanEquals.java delete mode 100644 src/test/java/org/json/junit/data/Singleton.java delete mode 100644 src/test/java/org/json/junit/data/SingletonEnum.java delete mode 100644 src/test/java/org/json/junit/data/StringsResourceBundle.java delete mode 100644 src/test/java/org/json/junit/data/WeirdList.java delete mode 100644 src/test/resources/Issue537.json delete mode 100644 src/test/resources/Issue537.xml delete mode 100644 src/test/resources/Issue593.json delete mode 100644 src/test/resources/Issue593.xml delete mode 100644 src/test/resources/Issue654WellFormedArray.json delete mode 100644 src/test/resources/Issue654WellFormedObject.json delete mode 100644 src/test/resources/JSONArrayExpectedTestCaseForToJsonArrayTest.json delete mode 100644 src/test/resources/XmlTestCaseTestToJsonArray.xml delete mode 100644 src/test/resources/compliantJsonArray.json delete mode 100644 src/test/resources/jsonpointer-testdoc.json diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index df4bf7981..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '18 18 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - run: "mvn clean compile -Dmaven.test.skip=true -Dmaven.site.skip=true -Dmaven.javadoc.skip=true" - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml deleted file mode 100644 index bb4cf0723..000000000 --- a/.github/workflows/pipeline.yml +++ /dev/null @@ -1,228 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://docs.github.com/en/actions/learn-github-actions or https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions - -name: Java CI with Maven - -on: - push: - # branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - # old-school build and jar method. No tests run or compiled. - build-1_6: - name: Java 1.6 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup java - uses: actions/setup-java@v1 - with: - java-version: 1.6 - - name: Compile Java 1.6 - run: | - mkdir -p target/classes - javac -version - javac -source 1.6 -target 1.6 -d target/classes/ src/main/java/org/json/*.java - - name: Create java 1.6 JAR - run: | - jar cvf target/org.json.jar -C target/classes . - - name: Upload JAR 1.6 - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Create java 1.6 JAR - path: target/*.jar - - build-8: - runs-on: ubuntu-latest - strategy: - fail-fast: false - max-parallel: 1 - matrix: - # build against supported Java LTS versions: - java: [ 8 ] - name: Java ${{ matrix.java }} - steps: - - uses: actions/checkout@v3 - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Compile Java ${{ matrix.java }} - run: mvn clean compile -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true -D maven.javadoc.skip=true - - name: Run Tests ${{ matrix.java }} - run: | - mvn test -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Build Test Report ${{ matrix.java }} - if: ${{ always() }} - run: | - mvn surefire-report:report-only -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - mvn site -D generateReports=false -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Upload Test Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Results ${{ matrix.java }} - path: target/surefire-reports/ - - name: Upload Test Report ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Report ${{ matrix.java }} - path: target/site/ - - name: Package Jar ${{ matrix.java }} - run: mvn clean package -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true - - name: Upload Package Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Package Jar ${{ matrix.java }} - path: target/*.jar - - build-11: - runs-on: ubuntu-latest - strategy: - fail-fast: false - max-parallel: 1 - matrix: - # build against supported Java LTS versions: - java: [ 11 ] - name: Java ${{ matrix.java }} - steps: - - uses: actions/checkout@v3 - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Compile Java ${{ matrix.java }} - run: mvn clean compile -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true -D maven.javadoc.skip=true - - name: Run Tests ${{ matrix.java }} - run: | - mvn test -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Build Test Report ${{ matrix.java }} - if: ${{ always() }} - run: | - mvn surefire-report:report-only -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - mvn site -D generateReports=false -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Upload Test Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Results ${{ matrix.java }} - path: target/surefire-reports/ - - name: Upload Test Report ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Report ${{ matrix.java }} - path: target/site/ - - name: Package Jar ${{ matrix.java }} - run: mvn clean package -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true - - name: Upload Package Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Package Jar ${{ matrix.java }} - path: target/*.jar - - build-17: - runs-on: ubuntu-latest - strategy: - fail-fast: false - max-parallel: 1 - matrix: - # build against supported Java LTS versions: - java: [ 17 ] - name: Java ${{ matrix.java }} - steps: - - uses: actions/checkout@v3 - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Compile Java ${{ matrix.java }} - run: mvn clean compile -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true -D maven.javadoc.skip=true - - name: Run Tests ${{ matrix.java }} - run: | - mvn test -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Build Test Report ${{ matrix.java }} - if: ${{ always() }} - run: | - mvn surefire-report:report-only -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - mvn site -D generateReports=false -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Upload Test Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Results ${{ matrix.java }} - path: target/surefire-reports/ - - name: Upload Test Report ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Report ${{ matrix.java }} - path: target/site/ - - name: Package Jar ${{ matrix.java }} - run: mvn clean package -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true - - name: Upload Package Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Package Jar ${{ matrix.java }} - path: target/*.jar - - build-21: - runs-on: ubuntu-latest - strategy: - fail-fast: false - max-parallel: 1 - matrix: - # build against supported Java LTS versions: - java: [ 21 ] - name: Java ${{ matrix.java }} - steps: - - uses: actions/checkout@v3 - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - cache: 'maven' - - name: Compile Java ${{ matrix.java }} - run: mvn clean compile -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true -D maven.javadoc.skip=true - - name: Run Tests ${{ matrix.java }} - run: | - mvn test -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Build Test Report ${{ matrix.java }} - if: ${{ always() }} - run: | - mvn surefire-report:report-only -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - mvn site -D generateReports=false -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} - - name: Upload Test Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Results ${{ matrix.java }} - path: target/surefire-reports/ - - name: Upload Test Report ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Test Report ${{ matrix.java }} - path: target/site/ - - name: Package Jar ${{ matrix.java }} - run: mvn clean package -D maven.compiler.source=${{ matrix.java }} -D maven.compiler.target=${{ matrix.java }} -D maven.test.skip=true -D maven.site.skip=true - - name: Upload Package Results ${{ matrix.java }} - if: ${{ always() }} - uses: actions/upload-artifact@v3 - with: - name: Package Jar ${{ matrix.java }} - path: target/*.jar diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index ecd775579..000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at jsonjava060@gmail.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 8102dcf63..000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,22 +0,0 @@ -# Contribution Guidelines - -Feel free to work on any open issue, you don't need to ask permission first. This year, the hacktoberfest label will be added to any PR and associated issue during the month of October. - -If you discover an issue you would like to work on, you can add a new issue to the list. If it meets our criteria, it will be available to work on (if not, it will be closed after review). - -# Who is allowed to submit pull requests for this project? - -Anyone can submit pull requests for code, tests, or documentation. - -# How do you decide which pull requests to accept? - -* Does it call out a bug that needs to be fixed? If so, it goes to the top of the list. -* Does it fix a major user inconvenience? These are given high priority as well. -* Does it align with the specs? If not, it will probably not be accepted. It turns out there are gray areas in the specs. If this is in a gray area, it will likely be given the benefit of the doubt. -* Does it break the existing behavior of the lib? If so, it will not be accepted, unless it fixes an egregious bug. This is happening less frequently now. - -# For more guidance, see these links: - -[README.md (includes build instructions)](https://github.com/stleary/JSON-java#readme) - -[FAQ - all your questions answered](https://github.com/stleary/JSON-java/wiki/FAQ) diff --git a/Examples.md b/Examples.md deleted file mode 100644 index fb010d5dc..000000000 --- a/Examples.md +++ /dev/null @@ -1,433 +0,0 @@ -

Examples

-

Imports used in the examples:

- -```java -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -``` - -

This document's intention is to explain to new-comers the basics of this project

- - -

Part 1: Creating a JSON document

- -

Using JSONArray

- -```java -private static void JSONExampleArray1() { - //We create a JSONObject from a String containing an array using JSONArray - //Firstly, we declare an Array in a String - - String arrayStr = - "["+"true,"+"false,"+ "\"true\","+ "\"false\","+"\"hello\","+"23.45e-4,"+ - "\"23.45\","+"42,"+"\"43\","+"["+"\"world\""+"],"+ - "{"+ - "\"key1\":\"value1\","+ - "\"key2\":\"value2\","+ - "\"key3\":\"value3\","+ - "\"key4\":\"value4\""+ - "},"+ - "0,"+"\"-1\""+ - "]"; - - //Then, we initializate the JSONArray thanks to its constructor - - JSONArray array = new JSONArray(arrayStr); - System.out.println("Values array: "+ array); - - //We convert that array into a JSONObject, but first, we need the labels, so we need another JSONArray with the labels. - //Here we will use an auxiliary function to get one for the example. - - JSONArray list = listNumberArray(array.length()); - System.out.println("Label Array: "+ list.toString()); - //Now, we construct the JSONObject using both the value array and the label array. - JSONObject object = array.toJSONObject(list); - System.out.println("Final JSONOBject: " + object); -} - -//This method creates an JSONArray of labels in which those are generated by their positions - -private static JSONArray listNumberArray(int max){ - JSONArray res = new JSONArray(); - for (int i=0; iUsing JSONStringer - -```java -private static void JSONExampleStringer() { - - //We initializate the JSONStringer - - JSONStringer jsonStringer = new JSONStringer(); - - //Now we start the process of adding elements with .object() - - jsonStringer.object(); - - //We can now add elements as keys and values with .values () and .key() - - jsonStringer.key("trueValue").value(true); - jsonStringer.key("falseValue").value(false); - jsonStringer.key("nullValue").value(null); - jsonStringer.key("stringValue").value("hello world!"); - jsonStringer.key("complexStringValue").value("h\be\tllo w\u1234orld!"); - jsonStringer.key("intValue").value(42); - jsonStringer.key("doubleValue").value(-23.45e67); - - //We end this prcedure with .ednObject - - jsonStringer.endObject(); - - //Once we have a JSONStringer, we convert it to JSONObject generating a String and using JSONObject's contructor. - - String str = jsonStringer.toString(); - JSONObject jsonObject = new JSONObject(str); - - System.out.println("Final JSONOBject: " + jsonObject); -} -``` -

Using JSONObject

- -```java -private static void JSONExampleObject1() { - - //We can create a JSONObject from a String with the class builder - - String string = "{\"0\":\"value\",\"1\":5,\"2\":-2.345E68,\"3\":true}"; - JSONObject example = new JSONObject(string); - System.out.println("Final JSONObject: " + example); - -} -``` -```java -private static void JSONExampleObject2() { - - //We can also create a JSONObject directly without messing around with any of the other functions. - - JSONObject example = new JSONObject(); - - - //Now we add the keys and values in a similar way as the Stringer method - example.put("key", "value"); - - //As you can see, the first entry is the key and the second would be its associeted value. - - example.put("key2", 5); - example.put("key3", -23.45e67); - example.put("trueValue", true); - - //We can't add null values thougth - - //example.put("nullValue", null); //This is not possible - - System.out.println("Final JSONOBject: " + example); -} -``` -```java -private static void JSONExampleObject3() { - - //We can also create a JSONObject with a Java Map - //YoU will need a Map whose keys are Strings. The values can be whatever you want - - Map map = new HashMap(); - - map.put("key1", 1.0); - map.put("key2", -23.45e67); - - //We create the JSONObject with the map with its class builder - - JSONObject example = new JSONObject(map); - System.out.println("Final JSONOBject: " + example); -} -``` -

Using JSONWriter

- -```java -private static void JSONExamplWriter() { - - //This method works in a very similar way to Object and Stringer in the construction of the JSON. - //The difference is that it needs a Java object called "Appendable" like StringBuilder - - StringBuilder write = new StringBuilder(); - JSONWriter jsonWriter = new JSONWriter(write); - - //We behave now the same way as Stringer - - jsonWriter.object(); - - jsonWriter.key("trueValue").value(true); - jsonWriter.key("falseValue").value(false); - jsonWriter.key("nullValue").value(null); - jsonWriter.key("stringValue").value("hello world!"); - jsonWriter.key("complexStringValue").value("h\be\tllo w\u1234orld!"); - jsonWriter.key("intValue").value(42); - jsonWriter.key("doubleValue").value(-23.45e67); - - jsonWriter.endObject(); - - //The resoult should be in the "write" object - - System.out.println("JSON: " + write.toString()); - - //The difference is that we don't get a JSONObject in this one. - - -} -``` -```java -private static void JSONExampleTokener() { - - //A partir de una String podemos crear un JSONTokener, que lo podemos usar alternativamente para JSONArray,JSONObject - - String string = "this is not a valid JSON string"; - JSONTokener token = new JSONTokener(string); - - //Now you can use the token in JSONObject and Array the same way as a String - - JSONObject object = new JSONObject(token); - JSONArray array = new JSONArray(token); - -} -``` -

Part 2: Conversion methods

-

We don't need to have a JSON document to work. This project also admits conversions from other type of files.

-

Secondly, we can also convert from JSON to those type of files.

- -

Extra: Conversion to JSONArray

- -```java -private static void JSONObjectToArray() { - //We start with a JSONObject - - String string = "{\"0\":\"value\",\"1\":5,\"2\":-2.345E68,\"3\":true}"; - - JSONObject example = new JSONObject(string); - - //We need a list of key strings like the reverse operation - - JSONArray keyStrings = listNumberArray(example.length()); - - //Then we convert to the Array using both elelements - - JSONArray array = example.toJSONArray(keyStrings); - - System.out.println("Final JSONArray: " + array); -} -``` -

XML Conversions

- -```java -private static void XMLToExampleConversion() { - - //We start with a JSONObject - - String string = "{\"0\":\"value\",\"1\":5,\"2\":-2.345E68,\"3\":true}"; - JSONObject example = new JSONObject(string); - - //We obtain a String with XML format with toString() - - String output = XML.toString(example); - System.out.println("Final XML: " + output); -} -``` -```java -private static void XMLFromExampleConversion() { - - //We start with a string with the XML format - - String string = "<0>value<1>5<2>-2.345E+68<3>true"; - - //We obtain a JSONObject with toJSONOBject() - - JSONObject output = XML.toJSONObject(string); - - System.out.println("Final JSONObject: " + output); -} -``` -

Cookie Conversions

- -```java -private static void CookieToExampleConversion() { - - //We start with a JSONObject - //The JSONOBject needs to entries that gives the cookie a name and gives the field "name" a name too. - //The Cokkie format doesn't support booleans - - String string = "{\"name\":\"Cookie-Name\",\"value\":\"name\",\"1\":5,\"2\":-2.345E68,\"3\":'true'}"; - JSONObject example = new JSONObject(string); - - //We obtain a String with Cookie format with toString() - - String output = Cookie.toString(example); - System.out.println("Final Cookie: " + output); -} -``` -```java -private static void CookieFromExampleConversion() { - - //We start with a string with the Cookie format - - String string = "Cookie-Name=name;1=5;2=-2.345E%2b68;3=true"; - - //We obtain a JSONObject with toJSONOBject() - - JSONObject output = Cookie.toJSONObject(string); - System.out.println("Final JSONObject: " + output); -} -``` - -

HTTP Conversions

- -```java -private static void HTTPToExampleConversion() { - - //We start with a JSONObject - //The JSONObject must have the minimun header for a HTTP request or header - - String string = "{\"Method\":\"POST\",\"Request-URI\":'/',\"HTTP-Version\":'HTTP/1.1',\"Value1\":true,\"Value2\":2,\"Value3\":-2.345E68}"; - - JSONObject example = new JSONObject(string); - - //We obtain a String with HTTP format with toString() - - String output = HTTP.toString(example); - System.out.println("Final HTTP: " + output); -} -``` -```java -private static void HTTPFromExampleConversion() { - - //We start with a string with the HTTP format - - String string = "Final HTTP: POST '/' HTTP/1.1 Value3: -2.345E+68 Value1: true Value2: 2"; - - //We obtain a JSONObject with toJSONOBject() - - JSONObject output = HTTP.toJSONObject(string); - System.out.println("Final JSONObject: " + output); -} -``` -

CDL Conversions

- -```java -private static void CDLToExampleConversion() { - - //We start with some JSONObjects with the same values in the keys but different values in the "values" - - String string = "{\"0\":\"value\",\"1\":5,\"2\":-2.345E68,\"3\":true}"; - JSONObject example = new JSONObject(string); - - String string2 = "{\"0\":\"value2\",\"1\":6,\"2\":-8.345E68,\"3\":false}"; - JSONObject example2 = new JSONObject(string2); - - //We need now a JSONArray with those JSONObjects - - JSONArray array = new JSONArray(); - array.put(example); - array.put(example2); - - //We obtain a String with XML format with toString() - - String output = CDL.toString(array); - System.out.println("Final CDL: \r\n" + output); -} -``` -```java -private static void CDLFromExampleConversion() { - - //We start wtih a String with the CDL format - - String string = "0,1,2,3\n" - + "value,5,-2.345E+68,true\n" - + "value2,6,-8.345E+68,false"; - - //We obtain a JSONArray with toJSONOBject() - - JSONArray output = CDL.toJSONArray(string); - System.out.println("Final JSONArray: " + output); -} -``` -

Properties Conversions

- -```java -private static Properties PropertyToExampleConversion() { - - //We start with a JSONObject - - String string = "{\"0\":\"value\",\"1\":5,\"2\":-2.345E68,\"3\":true}"; - JSONObject example = new JSONObject(string); - - //We obtain a String with Properties format with toString() - - Properties output = Property.toProperties(example); - System.out.println("Final Properties: " + output); - - return output; -} -``` -```java -private static void PropertyFromExampleConversion() { - - //We start with a Properties object - - Properties input = PropertyToExampleConversion(); - - //We obtain a JSONObject with toJSONOBject() - - JSONObject output = Property.toJSONObject(input); - System.out.println("Final JSONObject: " + output); -} -``` -

List of all examples methods

- -```java -public static void main(String[] args) { - //JSONObjectToArray(); - //JSONExampleArray1(); - //JSONExampleArray2(); - //JSONExampleStringer(); - //JSONExampleObject1(); - //JSONExampleObject2(); - //JSONExampleObject3(); - //JSONExamplWriter(); - //XMLToExampleConversion(); - //XMLFromExampleConversion(); - //CookieToExampleConversion(); - //CookieFromExampleConversion(); - //HTTPToExampleConversion(); - //HTTPFromExampleConversion(); - //CDLToExampleConversion(); - //CDLFromExampleConversion(); - //PropertyToExampleConversion(); - //PropertyFromExampleConversion(); -} -``` - diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 5af9a566b..000000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security Policy - -## Reporting a Vulnerability - -Please follow the instructions in the ["How are vulnerabilities and exploits handled?"](https://github.com/stleary/JSON-java/wiki/FAQ#how-are-vulnerabilities-and-exploits-handled) section in the FAQ. diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 30a85785b..000000000 --- a/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - */ -apply plugin: 'java' -apply plugin: 'eclipse' -// apply plugin: 'jacoco' -apply plugin: 'maven-publish' - -//plugins { - // id 'java' - //id 'maven-publish' -// } - -repositories { - mavenLocal() - mavenCentral() - maven { - url = uri('https://oss.sonatype.org/content/repositories/snapshots') - } -} - -dependencies { - testImplementation 'junit:junit:4.13.2' - testImplementation 'com.jayway.jsonpath:json-path:2.4.0' - testImplementation 'org.mockito:mockito-core:4.2.0' -} - -subprojects { - tasks.withType(Javadoc).all { enabled = false } -} - -group = 'org.json' -version = 'v20230618-SNAPSHOT' -description = 'JSON in Java' -sourceCompatibility = '1.8' - -configurations.all { -} - -java { - withSourcesJar() - withJavadocJar() -} - -publishing { - publications { - maven(MavenPublication) { - from(components.java) - } - } -} - -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md deleted file mode 100644 index d81ff6147..000000000 --- a/docs/CONTRIBUTING.md +++ /dev/null @@ -1,22 +0,0 @@ -# Contribution Guidelines - -Feel free to work on any issue with a #hacktoberfest label. - -If you discover an issue you would like to work on, you can add a new issue to the list. If it meets our criteria, a hacktoberfest label will be added. - -# Who is allowed to submit pull requests for this project? - -Anyone can submit pull requests for code, tests, or documentation. - -# How do you decide which pull requests to accept? - -* Does it call out a bug that needs to be fixed? If so, it goes to the top of the list. -* Does it fix a major user inconvenience? These are given high priority as well. -* Does it align with the specs? If not, it will probably not be accepted. It turns out there are gray areas in the specs. If this is in a gray area, it will likely be given the benefit of the doubt. -* Does it break the existing behavior of the lib? If so, it will not be accepted, unless it fixes an egregious bug. This is happening less frequently now. - -# For more guidance, see these links: - -[README.md (includes build instructions)](https://github.com/stleary/JSON-java#readme) - -[FAQ - all your questions answered](https://github.com/stleary/JSON-java/wiki/FAQ) diff --git a/docs/FILES.md b/docs/FILES.md deleted file mode 100644 index 152272190..000000000 --- a/docs/FILES.md +++ /dev/null @@ -1,62 +0,0 @@ -# Files - -**JSONObject.java**: The `JSONObject` can parse text from a `String` or a `JSONTokener` -to produce a map-like object. The object provides methods for manipulating its -contents, and for producing a JSON compliant object serialization. - -**JSONArray.java**: The `JSONArray` can parse text from a String or a `JSONTokener` -to produce a vector-like object. The object provides methods for manipulating -its contents, and for producing a JSON compliant array serialization. - -**JSONTokener.java**: The `JSONTokener` breaks a text into a sequence of individual -tokens. It can be constructed from a `String`, `Reader`, or `InputStream`. It also can -parse text from a `String`, `Number`, `Boolean` or `null` like `"hello"`, `42`, `true`, -`null` to produce a simple json object. - -**JSONException.java**: The `JSONException` is the standard exception type thrown -by this package. - -**JSONPointer.java**: Implementation of -[JSON Pointer (RFC 6901)](https://tools.ietf.org/html/rfc6901). Supports -JSON Pointers both in the form of string representation and URI fragment -representation. - -**JSONPropertyIgnore.java**: Annotation class that can be used on Java Bean getter methods. -When used on a bean method that would normally be serialized into a `JSONObject`, it -overrides the getter-to-key-name logic and forces the property to be excluded from the -resulting `JSONObject`. - -**JSONPropertyName.java**: Annotation class that can be used on Java Bean getter methods. -When used on a bean method that would normally be serialized into a `JSONObject`, it -overrides the getter-to-key-name logic and uses the value of the annotation. The Bean -processor will look through the class hierarchy. This means you can use the annotation on -a base class or interface and the value of the annotation will be used even if the getter -is overridden in a child class. - -**JSONString.java**: The `JSONString` interface requires a `toJSONString` method, -allowing an object to provide its own serialization. - -**JSONStringer.java**: The `JSONStringer` provides a convenient facility for -building JSON strings. - -**JSONWriter.java**: The `JSONWriter` provides a convenient facility for building -JSON text through a writer. - - -**CDL.java**: `CDL` provides support for converting between JSON and comma -delimited lists. - -**Cookie.java**: `Cookie` provides support for converting between JSON and cookies. - -**CookieList.java**: `CookieList` provides support for converting between JSON and -cookie lists. - -**HTTP.java**: `HTTP` provides support for converting between JSON and HTTP headers. - -**HTTPTokener.java**: `HTTPTokener` extends `JSONTokener` for parsing HTTP headers. - -**XML.java**: `XML` provides support for converting between JSON and XML. - -**JSONML.java**: `JSONML` provides support for converting between JSONML and XML. - -**XMLTokener.java**: `XMLTokener` extends `JSONTokener` for parsing XML text. \ No newline at end of file diff --git a/docs/NOTES.md b/docs/NOTES.md deleted file mode 100644 index a8298ddfa..000000000 --- a/docs/NOTES.md +++ /dev/null @@ -1,87 +0,0 @@ -# Notes - -**Recent directory structure change** - -_Due to a recent commit - [#515 Merge tests and pom and code](https://github.com/stleary/JSON-java/pull/515) - the structure of the project has changed from a flat directory containing all of the Java files to a directory structure that includes unit tests and several tools used to build the project jar and run the unit tests. If you have difficulty using the new structure, please open an issue so we can work through it._ - -**Implementation notes** - -Numeric types in this package comply with -[ECMA-404: The JSON Data Interchange Format](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) and -[RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc8259#section-6). -This package fully supports `Integer`, `Long`, and `Double` Java types. Partial support -for `BigInteger` and `BigDecimal` values in `JSONObject` and `JSONArray` objects is provided -in the form of `get()`, `opt()`, and `put()` API methods. - -Although 1.6 compatibility is currently supported, it is not a project goal and might be -removed in some future release. - -In compliance with RFC8259 page 10 section 9, the parser is more lax with what is valid -JSON then the Generator. For Example, the tab character (U+0009) is allowed when reading -JSON Text strings, but when output by the Generator, the tab is properly converted to \t in -the string. Other instances may occur where reading invalid JSON text does not cause an -error to be generated. Malformed JSON Texts such as missing end " (quote) on strings or -invalid number formats (1.2e6.3) will cause errors as such documents can not be read -reliably. - -Some notable exceptions that the JSON Parser in this library accepts are: -* Unquoted keys `{ key: "value" }` -* Unquoted values `{ "key": value }` -* Unescaped literals like "tab" in string values `{ "key": "value with an unescaped tab" }` -* Numbers out of range for `Double` or `Long` are parsed as strings - -Recent pull requests added a new method `putAll` on the JSONArray. The `putAll` method -works similarly to other `put` methods in that it does not call `JSONObject.wrap` for items -added. This can lead to inconsistent object representation in JSONArray structures. - -For example, code like this will create a mixed JSONArray, some items wrapped, others -not: - -```java -SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; -// these will be wrapped -JSONArray jArr = new JSONArray(myArr); -// these will not be wrapped -jArr.putAll(new SomeBean[]{ new SomeBean(3), new SomeBean(4) }); -``` - -For structure consistency, it would be recommended that the above code is changed -to look like 1 of 2 ways. - -Option 1: -```Java -SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; -JSONArray jArr = new JSONArray(); -// these will not be wrapped -jArr.putAll(myArr); -// these will not be wrapped -jArr.putAll(new SomeBean[]{ new SomeBean(3), new SomeBean(4) }); -// our jArr is now consistent. -``` - -Option 2: -```Java -SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; -// these will be wrapped -JSONArray jArr = new JSONArray(myArr); -// these will be wrapped -jArr.putAll(new JSONArray(new SomeBean[]{ new SomeBean(3), new SomeBean(4) })); -// our jArr is now consistent. -``` - -**Unit Test Conventions** - -Test filenames should consist of the name of the module being tested, with the suffix "Test". -For example, Cookie.java is tested by CookieTest.java. - -The fundamental issues with JSON-Java testing are:
-* JSONObjects are unordered, making simple string comparison ineffective. -* Comparisons via **equals()** is not currently supported. Neither JSONArray nor JSONObject override hashCode() or equals(), so comparison defaults to the Object equals(), which is not useful. -* Access to the JSONArray and JSONObject internal containers for comparison is not currently available. - -General issues with unit testing are:
-* Just writing tests to make coverage goals tends to result in poor tests. -* Unit tests are a form of documentation - how a given method works is demonstrated by the test. So for a code reviewer or future developer looking at code a good test helps explain how a function is supposed to work according to the original author. This can be difficult if you are not the original developer. -* It is difficult to evaluate unit tests in a vacuum. You also need to see the code being tested to understand if a test is good. -* Without unit tests, it is hard to feel confident about the quality of the code, especially when fixing bugs or refactoring. Good tests prevent regressions and keep the intent of the code correct. -* If you have unit test results along with pull requests, the reviewer has an easier time understanding your code and determining if it works as intended. \ No newline at end of file diff --git a/docs/RELEASES.md b/docs/RELEASES.md deleted file mode 100644 index 30b8af2bc..000000000 --- a/docs/RELEASES.md +++ /dev/null @@ -1,55 +0,0 @@ -# Release history: - -JSON-java releases can be found by searching the Maven repository for groupId "org.json" -and artifactId "json". For example: -[https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav](https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav) - -~~~ -20240303 Revert optLong/getLong changes, and recent commits. - -20240205 Recent commits. - -20231013 First release with minimum Java version 1.8. Recent commits, including fixes for CVE-2023-5072. - -20230618 Final release with Java 1.6 compatibility. Future releases will require Java 1.8 or greater. - -20230227 Fix for CVE-2022-45688 and recent commits - -20220924 New License - public domain, and some minor updates - -20220320 Wrap StackOverflow with JSONException - -20211205 Recent commits and some bug fixes for similar() - -20210307 Recent commits and potentially breaking fix to JSONPointer - -20201115 Recent commits and first release after project structure change - -20200518 Recent commits and snapshot before project structure change - -20190722 Recent commits - -20180813 POM change to include Automatic-Module-Name (#431) - JSONObject(Map) now throws an exception if any of a map keys are null (#405) - -20180130 Recent commits - -20171018 Checkpoint for recent commits. - -20170516 Roll up recent commits. - -20160810 Revert code that was breaking opt*() methods. - -20160807 This release contains a bug in the JSONObject.opt*() and JSONArray.opt*() methods, -it is not recommended for use. -Java 1.6 compatability fixed, JSONArray.toList() and JSONObject.toMap(), -RFC4180 compatibility, JSONPointer, some exception fixes, optional XML type conversion. -Contains the latest code as of 7 Aug 2016 - -20160212 Java 1.6 compatibility, OSGi bundle. Contains the latest code as of 12 Feb 2016. - -20151123 JSONObject and JSONArray initialization with generics. Contains the latest code as of 23 Nov 2015. - -20150729 Checkpoint for Maven central repository release. Contains the latest code -as of 29 July 2015. -~~~ diff --git a/docs/SECURITY.md b/docs/SECURITY.md deleted file mode 100644 index 5af9a566b..000000000 --- a/docs/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security Policy - -## Reporting a Vulnerability - -Please follow the instructions in the ["How are vulnerabilities and exploits handled?"](https://github.com/stleary/JSON-java/wiki/FAQ#how-are-vulnerabilities-and-exploits-handled) section in the FAQ. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index f3d88b1c2faf2fc91d853cd5d4242b5547257070..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 58695 zcma&OV~}Oh(k5J8>Mq;vvTfV8ZQE5{wr$(iDciPf+tV}m-if*I+;_h3N1nY;M6TF7 zBc7A_WUgl&IY|&uNFbnJzkq;%`2QLZ5b*!{1OkHidzBVe;-?mu5upVElKVGD>pC88 zzP}E3wRHBgaO?2nzdZ5pL;m-xf&RU>buj(E-s=DK zf%>P9se`_emGS@673tqyT^;o8?2H}$uO&&u^TlmHfPgSSfPiTK^AZ7DTPH`Szw4#- z&21E&^c|dx9f;^@46XDX9itS+ZRYuqx#wG*>5Bs&gxwSQbj8grds#xkl;ikls1%(2 zR-`Tn(#9}E_aQ!zu~_iyc0gXp2I`O?erY?=JK{M`Ew(*RP3vy^0=b2E0^PSZgm(P6 z+U<&w#)I=>0z=IC4 zh4Q;eq94OGttUh7AGWu7m){;^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PT!B)ZuRVkVa>f*-2aPeV3R79xh zB)3A$>X~szg#}>uNkpLPG#3IKyeMHM*pUuV5=-Jji7S6PSQ9oCLo{oXxzOZfF$PP) zrYwlmSQ-~n94uO3CD{K0QTmj@g%Yzn7_xQ4fTduU0Yqvln`e_`CdXH5iQ5qRr1 zBC;}%YZ2!4I>*=sR)O~jBPx6sxmIEBnq)s-fHz_y0z8-gPl2Us4BiBXNR5CIF!YR@ zb9B305SilU*@4|+ x6JBtc8JSt5M0pkooaq!^FqtuD_KdXXTo>Mw54>`rP&>h&58!3a6l6r9{sG7g--!SK diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index a4b442974..000000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 2fe81a7d9..000000000 --- a/gradlew +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 9109989e3..000000000 --- a/gradlew.bat +++ /dev/null @@ -1,103 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/images/JsonJava.png b/images/JsonJava.png deleted file mode 100644 index 28c5c9cbca0f1fc0f4e023f5ff515a4de5ef0695..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15697 zcmb7rWmB9@ur|RpxCD21cUauro!}M-8a%kmqKj*=#WlEx#oY-O+}-8yy!HNob3V*H z)gPv+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Q9Jn5$Z<+f8$hlP7;-K@X%Y*5eV*T>iu z?Y_*+`=y$Y7%KAd)W}&JmIvN11e47gj@Pf-``jM%*sSk^>?C~}lZzT}<|ZMq;{9d; z%DPTGfv2CJPkvJvTPk&{%(TWmb>&*j+FGW{MR|%FnptD2(59n^!6B^Mq5I*FF%i3^ zy=g2lU=5Lsf7;R$n%tpL=RypowZl4SMf#F1_Ne4Dn%~26sRNfYwALhe?-+GYX}QME zPGxerJ-VJ5V7(;y6!aR733-{OnoSO%m~t4Jedu!;D41Ho zJE^%?K>kgC*hyTZ1zz}^y=}d&1km-y^$but7U1_pi%x5HV@~BLH}McT%f$w z*L8>wqkL$+Pw@#k - * A cookie list is a JSONObject whose members are presumed to be cookie - * name/value pairs. Entries are unescaped while being added, and escaped in - * the toString() output. - * Unescaping means to convert %hh hex strings to the ascii equivalent - * and converting '+' to ' '. - * Escaping converts '+', '%', '=', ';' and ascii control chars to %hh hex strings. - *

- * CookieList should not be considered as just a list of Cookie objects:
- * - CookieList stores a cookie name/value pair as a single entry; Cookie stores - * it as 2 entries (key="name" and key="value").
- * - CookieList requires multiple name/value pairs as input; Cookie allows the - * 'secure' name with no associated value
- * - CookieList has no special handling for attribute name/value pairs.
- */ -public class CookieListTest { - - /** - * Attempts to create a CookieList from a null string. - * Expects a NullPointerException. - */ - @Test(expected=NullPointerException.class) - public void nullCookieListException() { - String cookieStr = null; - CookieList.toJSONObject(cookieStr); - } - - /** - * Attempts to create a CookieList from a malformed string. - * Expects a JSONException. - */ - @Test - public void malFormedCookieListException() { - String cookieStr = "thisCookieHasNoEqualsChar"; - try { - CookieList.toJSONObject(cookieStr); - fail("should throw an exception"); - } catch (JSONException e) { - /** - * Not sure of the missing char, but full string compare fails - */ - assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at 25 [character 26 line 1]", - e.getMessage()); - } - } - - /** - * Creates a CookieList from an empty string. - */ - @Test - public void emptyStringCookieList() { - String cookieStr = ""; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - assertTrue(jsonObject.isEmpty()); - } - - /** - * CookieList with the simplest cookie - a name/value pair with no delimiter. - */ - @Test - public void simpleCookieList() { - String cookieStr = "SID=31d4d96e407aad42"; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("Expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 31d4d96e407aad42", "31d4d96e407aad42".equals(jsonObject.query("/SID"))); - } - - /** - * CookieList with a single a cookie which has a name/value pair and delimiter. - */ - @Test - public void simpleCookieListWithDelimiter() { - String cookieStr = "SID=31d4d96e407aad42;"; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("Expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 31d4d96e407aad42", "31d4d96e407aad42".equals(jsonObject.query("/SID"))); - } - - /** - * CookieList with multiple cookies consisting of name/value pairs - * with delimiters. - */ - @Test - public void multiPartCookieList() { - String cookieStr = - "name1=myCookieValue1; "+ - " name2=myCookieValue2;"+ - "name3=myCookieValue3;"+ - " name4=myCookieValue4; "+ - "name5=myCookieValue5;"+ - " name6=myCookieValue6;"; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("Expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected myCookieValue1", "myCookieValue1".equals(jsonObject.query("/name1"))); - assertTrue("expected myCookieValue2", "myCookieValue2".equals(jsonObject.query("/name2"))); - assertTrue("expected myCookieValue3", "myCookieValue3".equals(jsonObject.query("/name3"))); - assertTrue("expected myCookieValue4", "myCookieValue4".equals(jsonObject.query("/name4"))); - assertTrue("expected myCookieValue5", "myCookieValue5".equals(jsonObject.query("/name5"))); - assertTrue("expected myCookieValue6", "myCookieValue6".equals(jsonObject.query("/name6"))); - } - - /** - * CookieList from a JSONObject with valid key and null value - */ - @Test - public void convertCookieListWithNullValueToString() { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("key", JSONObject.NULL); - String cookieToStr = CookieList.toString(jsonObject); - assertTrue("toString() should be empty", "".equals(cookieToStr)); - } - - /** - * CookieList with multiple entries converted to a JSON document. - */ - @Test - public void convertCookieListToString() { - String cookieStr = - "name1=myCookieValue1; "+ - " name2=myCookieValue2;"+ - "name3=myCookieValue3;"+ - " name4=myCookieValue4; "+ - "name5=myCookieValue5;"+ - " name6=myCookieValue6;"; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - // exercise CookieList.toString() - String cookieListString = CookieList.toString(jsonObject); - // have to convert it back for validation - jsonObject = CookieList.toJSONObject(cookieListString); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("Expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected myCookieValue1", "myCookieValue1".equals(jsonObject.query("/name1"))); - assertTrue("expected myCookieValue2", "myCookieValue2".equals(jsonObject.query("/name2"))); - assertTrue("expected myCookieValue3", "myCookieValue3".equals(jsonObject.query("/name3"))); - assertTrue("expected myCookieValue4", "myCookieValue4".equals(jsonObject.query("/name4"))); - assertTrue("expected myCookieValue5", "myCookieValue5".equals(jsonObject.query("/name5"))); - assertTrue("expected myCookieValue6", "myCookieValue6".equals(jsonObject.query("/name6"))); - } - - /** - * CookieList with multiple entries and some '+' chars and URL-encoded - * values converted to a JSON document. - */ - @Test - public void convertEncodedCookieListToString() { - String cookieStr = - "name1=myCookieValue1; "+ - " name2=my+Cookie+Value+2;"+ - "name3=my%2BCookie%26Value%3B3%3D;"+ - " name4=my%25CookieValue4; "+ - "name5=myCookieValue5;"+ - " name6=myCookieValue6;"; - JSONObject jsonObject = CookieList.toJSONObject(cookieStr); - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("Expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected myCookieValue1", "myCookieValue1".equals(jsonObject.query("/name1"))); - assertTrue("expected my Cookie Value 2", "my Cookie Value 2".equals(jsonObject.query("/name2"))); - assertTrue("expected my+Cookie&Value;3=", "my+Cookie&Value;3=".equals(jsonObject.query("/name3"))); - assertTrue("expected my%CookieValue4", "my%CookieValue4".equals(jsonObject.query("/name4"))); - assertTrue("expected my%CookieValue5", "myCookieValue5".equals(jsonObject.query("/name5"))); - assertTrue("expected myCookieValue6", "myCookieValue6".equals(jsonObject.query("/name6"))); - } -} diff --git a/src/test/java/org/json/junit/CookieTest.java b/src/test/java/org/json/junit/CookieTest.java deleted file mode 100644 index edd8a7eeb..000000000 --- a/src/test/java/org/json/junit/CookieTest.java +++ /dev/null @@ -1,242 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import org.json.*; -import org.junit.Test; - - -/** - * HTTP cookie specification: RFC6265 - *

- * At its most basic, a cookie is a name=value pair. The value may be subdivided - * into other cookies, but that is not tested here. The cookie may also include - * certain named attributes, delimited by semicolons. - *

- * The Cookie.toString() method emits certain attributes if present: expires, - * domain, path, secure. All but secure are name-value pairs. Other attributes - * are not included in the toString() output. - *

- * A JSON-Java encoded cookie escapes '+', '%', '=', ';' with %hh values. - */ -public class CookieTest { - - /** - * Attempts to create a JSONObject from a null string. - * Expects a NullPointerException. - */ - @Test(expected=NullPointerException.class) - public void nullCookieException() { - String cookieStr = null; - Cookie.toJSONObject(cookieStr); - } - - /** - * Attempts to create a JSONObject from a cookie string with - * no '=' char. - * Expects a JSONException. - */ - @Test - public void malFormedNameValueException() { - String cookieStr = "thisCookieHasNoEqualsChar"; - try { - Cookie.toJSONObject(cookieStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at 25 [character 26 line 1]", - e.getMessage()); - } - } - - /** - * Attempts to create a JSONObject from a cookie string - * with embedded ';' char. - * Expects a JSONException. - */ - @Test - public void booleanAttribute() { - String cookieStr = "this=Cookie;myAttribute"; - JSONObject jo = Cookie.toJSONObject(cookieStr); - assertTrue("has key 'name'", jo.has("name")); - assertTrue("has key 'value'", jo.has("value")); - assertTrue("has key 'myAttribute'", jo.has("myattribute")); - } - - /** - * Attempts to create a JSONObject from an empty cookie string.
- * Note: Cookie throws an exception, but CookieList does not.
- * Expects a JSONException - */ - @Test - public void emptyStringCookieException() { - String cookieStr = ""; - try { - Cookie.toJSONObject(cookieStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Cookies must have a 'name'", - e.getMessage()); - } - } - /** - * - * Attempts to create a JSONObject from an cookie string where the name is blank.
- * Note: Cookie throws an exception, but CookieList does not.
- * Expects a JSONException - */ - @Test - public void emptyNameCookieException() { - String cookieStr = " = value "; - try { - Cookie.toJSONObject(cookieStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Cookies must have a 'name'", - e.getMessage()); - } - } - - /** - * Cookie from a simple name/value pair with no delimiter - */ - @Test - public void simpleCookie() { - String cookieStr = "SID=31d4d96e407aad42"; - String expectedCookieStr = "{\"name\":\"SID\",\"value\":\"31d4d96e407aad42\"}"; - JSONObject jsonObject = Cookie.toJSONObject(cookieStr); - JSONObject expectedJsonObject = new JSONObject(expectedCookieStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Store a cookie with all of the supported attributes in a - * JSONObject. The secure attribute, which has no value, is treated - * as a boolean. - */ - @Test - public void multiPartCookie() { - String cookieStr = - "PH=deleted; "+ - " expires=Wed, 19-Mar-2014 17:53:53 GMT;"+ - "path=/; "+ - " domain=.yahoo.com;"+ - "secure"; - String expectedCookieStr = - "{"+ - "\"name\":\"PH\","+ - "\"value\":\"deleted\","+ - "\"path\":\"/\","+ - "\"expires\":\"Wed, 19-Mar-2014 17:53:53 GMT\","+ - "\"domain\":\".yahoo.com\","+ - "\"secure\":true"+ - "}"; - JSONObject jsonObject = Cookie.toJSONObject(cookieStr); - JSONObject expectedJsonObject = new JSONObject(expectedCookieStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Cookie.toString() will emit the non-standard "thiswont=beIncluded" - * attribute, and the attribute is still stored in the JSONObject. - * This test confirms both behaviors. - */ - @Test - public void convertCookieToString() { - String cookieStr = - "PH=deleted; "+ - " expires=Wed, 19-Mar-2014 17:53:53 GMT;"+ - "path=/; "+ - " domain=.yahoo.com;"+ - "thisWont=beIncluded;"+ - "secure"; - String expectedCookieStr = - "{\"thiswont\":\"beIncluded\","+ - "\"path\":\"/\","+ - "\"expires\":\"Wed, 19-Mar-2014 17:53:53 GMT\","+ - "\"domain\":\".yahoo.com\","+ - "\"name\":\"PH\","+ - "\"secure\":true,"+ - "\"value\":\"deleted\"}"; - // Add the nonstandard attribute to the expected cookie string - String expectedDirectCompareCookieStr = expectedCookieStr; - // convert all strings into JSONObjects - JSONObject jsonObject = Cookie.toJSONObject(cookieStr); - JSONObject expectedJsonObject = new JSONObject(expectedCookieStr); - JSONObject expectedDirectCompareJsonObject = - new JSONObject(expectedDirectCompareCookieStr); - // emit the string - String cookieToStr = Cookie.toString(jsonObject); - // create a final JSONObject from the string - JSONObject finalJsonObject = Cookie.toJSONObject(cookieToStr); - // JSONObject should contain the nonstandard string - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedDirectCompareJsonObject); - // JSONObject -> string -> JSONObject should not contain the nonstandard string - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - /** - * A string may be URL-encoded when converting to JSONObject. - * If found, '+' is converted to ' ', and %hh hex strings are converted - * to their ascii char equivalents. This test confirms the decoding - * behavior. - */ - @Test - public void convertEncodedCookieToString() { - String cookieStr = - "PH=deleted; "+ - " expires=Wed,+19-Mar-2014+17:53:53+GMT;"+ - "path=/%2Bthis/is%26/a/spec%3Bsegment%3D; "+ - " domain=.yahoo.com;"+ - "secure"; - String expectedCookieStr = - "{\"path\":\"/+this/is&/a/spec;segment=\","+ - "\"expires\":\"Wed, 19-Mar-2014 17:53:53 GMT\","+ - "\"domain\":\".yahoo.com\","+ - "\"name\":\"PH\","+ - "\"secure\":true,"+ - "\"value\":\"deleted\"}"; - JSONObject jsonObject = Cookie.toJSONObject(cookieStr); - JSONObject expectedJsonObject = new JSONObject(expectedCookieStr); - String cookieToStr = Cookie.toString(jsonObject); - JSONObject finalJsonObject = Cookie.toJSONObject(cookieToStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - /** - * A public API method performs a URL encoding for selected chars - * in a string. Control chars, '+', '%', '=', ';' are all encoded - * as %hh hex strings. The string is also trimmed. - * This test confirms that behavior. - */ - @Test - public void escapeString() { - String str = " +%\r\n\t\b%=;;; "; - String expectedStr = "%2b%25%0d%0a%09%08%25%3d%3b%3b%3b"; - String actualStr = Cookie.escape(str); - assertTrue("expect escape() to encode correctly. Actual: " +actualStr+ - " expected: " +expectedStr, expectedStr.equals(actualStr)); - } - - /** - * A public API method performs URL decoding for strings. - * '+' is converted to space and %hh hex strings are converted to - * their ascii equivalent values. The string is not trimmed. - * This test confirms that behavior. - */ - @Test - public void unescapeString() { - String str = " +%2b%25%0d%0a%09%08%25%3d%3b%3b%3b+ "; - String expectedStr = " +%\r\n\t\b%=;;; "; - String actualStr = Cookie.unescape(str); - assertTrue("expect unescape() to decode correctly. Actual: " +actualStr+ - " expected: " +expectedStr, expectedStr.equals(actualStr)); - } -} diff --git a/src/test/java/org/json/junit/EnumTest.java b/src/test/java/org/json/junit/EnumTest.java deleted file mode 100644 index 1496a636a..000000000 --- a/src/test/java/org/json/junit/EnumTest.java +++ /dev/null @@ -1,433 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.EnumSet; -import java.util.List; -import java.util.Map; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.json.junit.data.MyEnum; -import org.json.junit.data.MyEnumClass; -import org.json.junit.data.MyEnumField; -import org.junit.Test; - -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.JsonPath; - -/** - * Enums are not explicitly supported in JSON-Java. But because enums act like - * classes, all required behavior is already be present in some form. - * These tests explore how enum serialization works with JSON-Java. - */ -public class EnumTest { - - /** - * To serialize an enum by its getters, use the JSONObject Object constructor. - * The JSONObject ctor handles enum like any other bean. A JSONobject - * is created whose entries are the getter name/value pairs. - */ - @Test - public void jsonObjectFromEnum() { - // If there are no getters then the object is empty. - MyEnum myEnum = MyEnum.VAL2; - JSONObject jsonObject = new JSONObject(myEnum); - assertTrue("simple enum has no getters", jsonObject.isEmpty()); - - // enum with a getters should create a non-empty object - MyEnumField myEnumField = MyEnumField.VAL2; - jsonObject = new JSONObject(myEnumField); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider() - .parse(jsonObject.toString()); - assertTrue("expecting 2 items in top level object", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expecting val 2", "val 2".equals(jsonObject.query("/value"))); - assertTrue("expecting 2", Integer.valueOf(2).equals(jsonObject.query("/intVal"))); - - /** - * class which contains enum instances. Each enum should be stored - * in its own JSONObject - */ - MyEnumClass myEnumClass = new MyEnumClass(); - myEnumClass.setMyEnum(MyEnum.VAL1); - myEnumClass.setMyEnumField(MyEnumField.VAL3); - jsonObject = new JSONObject(myEnumClass); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected 2 myEnumField items", "VAL3".equals((JsonPath.read(doc, "$.myEnumField")))); - assertTrue("expected 0 myEnum items", "VAL1".equals((JsonPath.read(doc, "$.myEnum")))); - - assertTrue("expecting MyEnumField.VAL3", MyEnumField.VAL3.equals(jsonObject.query("/myEnumField"))); - assertTrue("expecting MyEnum.VAL1", MyEnum.VAL1.equals(jsonObject.query("/myEnum"))); - } - - /** - * To serialize an enum by its set of allowed values, use getNames() - * and the JSONObject Object with names constructor. - */ - @Test - public void jsonObjectFromEnumWithNames() { - String [] names; - JSONObject jsonObject; - - MyEnum myEnum = MyEnum.VAL1; - names = JSONObject.getNames(myEnum); - // The values will be MyEnum fields - jsonObject = new JSONObject(myEnum, names); - - // validate JSON object - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 3 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected VAL1", MyEnum.VAL1.equals(jsonObject.query("/VAL1"))); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonObject.query("/VAL2"))); - assertTrue("expected VAL3", MyEnum.VAL3.equals(jsonObject.query("/VAL3"))); - - MyEnumField myEnumField = MyEnumField.VAL3; - names = JSONObject.getNames(myEnumField); - // The values will be MyEnmField fields - jsonObject = new JSONObject(myEnumField, names); - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 3 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected VAL1", MyEnumField.VAL1.equals(jsonObject.query("/VAL1"))); - assertTrue("expected VAL2", MyEnumField.VAL2.equals(jsonObject.query("/VAL2"))); - assertTrue("expected VAL3", MyEnumField.VAL3.equals(jsonObject.query("/VAL3"))); - } - - /** - * Verify that enums are handled consistently between JSONArray and JSONObject - */ - @Test - public void verifyEnumConsistency(){ - JSONObject jo = new JSONObject(); - - jo.put("value", MyEnumField.VAL2); - String expected="{\"value\":\"VAL2\"}"; - String actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - jo.accumulate("value", MyEnumField.VAL1); - expected="{\"value\":[\"VAL2\",\"VAL1\"]}"; - actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - jo.remove("value"); - jo.append("value", MyEnumField.VAL1); - expected="{\"value\":[\"VAL1\"]}"; - actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - jo.put("value", EnumSet.of(MyEnumField.VAL2)); - expected="{\"value\":[\"VAL2\"]}"; - actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - JSONArray ja = new JSONArray(); - ja.put(MyEnumField.VAL2); - jo.put("value", ja); - actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - jo.put("value", new MyEnumField[]{MyEnumField.VAL2}); - actual = jo.toString(); - assertTrue("Expected "+expected+" but actual was "+actual, expected.equals(actual)); - - } - - /** - * To serialize by assigned value, use the put() methods. The value - * will be stored as a enum type. - */ - @Test - public void enumPut() { - JSONObject jsonObject = new JSONObject(); - MyEnum myEnum = MyEnum.VAL2; - jsonObject.put("myEnum", myEnum); - MyEnumField myEnumField = MyEnumField.VAL1; - jsonObject.putOnce("myEnumField", myEnumField); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level objects", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonObject.query("/myEnum"))); - assertTrue("expected VAL1", MyEnumField.VAL1.equals(jsonObject.query("/myEnumField"))); - - JSONArray jsonArray = new JSONArray(); - jsonArray.put(myEnum); - jsonArray.put(1, myEnumField); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 2 top level objects", ((List)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonArray.query("/0"))); - assertTrue("expected VAL1", MyEnumField.VAL1.equals(jsonArray.query("/1"))); - - /** - * Leaving these tests because they exercise get, opt, and remove - */ - assertTrue("expecting myEnum value", MyEnum.VAL2.equals(jsonArray.get(0))); - assertTrue("expecting myEnumField value", MyEnumField.VAL1.equals(jsonArray.opt(1))); - assertTrue("expecting myEnumField value", MyEnumField.VAL1.equals(jsonArray.remove(1))); - } - - /** - * The default action of valueToString() is to call object.toString(). - * For enums, this means the assigned value will be returned as a string. - */ - @Test - public void enumValueToString() { - String expectedStr1 = "\"VAL1\""; - String expectedStr2 = "\"VAL1\""; - MyEnum myEnum = MyEnum.VAL1; - MyEnumField myEnumField = MyEnumField.VAL1; - MyEnumClass myEnumClass = new MyEnumClass(); - - String str1 = JSONObject.valueToString(myEnum); - assertTrue("actual myEnum: "+str1+" expected: "+expectedStr1, - str1.equals(expectedStr1)); - String str2 = JSONObject.valueToString(myEnumField); - assertTrue("actual myEnumField: "+str2+" expected: "+expectedStr2, - str2.equals(expectedStr2)); - - /** - * However, an enum within another class will not be rendered - * unless that class overrides default toString() - */ - String expectedStr3 = "\"org.json.junit.data.MyEnumClass@"; - myEnumClass.setMyEnum(MyEnum.VAL1); - myEnumClass.setMyEnumField(MyEnumField.VAL1); - String str3 = JSONObject.valueToString(myEnumClass); - assertTrue("actual myEnumClass: "+str3+" expected: "+expectedStr3, - str3.startsWith(expectedStr3)); - } - - /** - * In whatever form the enum was added to the JSONObject or JSONArray, - * json[Object|Array].toString should serialize it in a reasonable way. - */ - @Test - public void enumToString() { - MyEnum myEnum = MyEnum.VAL2; - JSONObject jsonObject = new JSONObject(myEnum); - String expectedStr = "{}"; - assertTrue("myEnum toString() should be empty", expectedStr.equals(jsonObject.toString())); - - MyEnumField myEnumField = MyEnumField.VAL2; - jsonObject = new JSONObject(myEnumField); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected val 2", "val 2".equals(jsonObject.query("/value"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonObject.query("/intVal"))); - - MyEnumClass myEnumClass = new MyEnumClass(); - myEnumClass.setMyEnum(MyEnum.VAL1); - myEnumClass.setMyEnumField(MyEnumField.VAL3); - jsonObject = new JSONObject(myEnumClass); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL3", "VAL3".equals((JsonPath.read(doc, "$.myEnumField")))); - assertTrue("expected VAL1", "VAL1".equals((JsonPath.read(doc, "$.myEnum")))); - - String [] names = JSONObject.getNames(myEnum); - jsonObject = new JSONObject(myEnum, names); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 3 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected VAL1", MyEnum.VAL1.equals(jsonObject.query("/VAL1"))); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonObject.query("/VAL2"))); - assertTrue("expected VAL3", MyEnum.VAL3.equals(jsonObject.query("/VAL3"))); - - names = JSONObject.getNames(myEnumField); - jsonObject = new JSONObject(myEnumField, names); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 3 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected VAL1", MyEnumField.VAL1.equals(jsonObject.query("/VAL1"))); - assertTrue("expected VAL2", MyEnumField.VAL2.equals(jsonObject.query("/VAL2"))); - assertTrue("expected VAL3", MyEnumField.VAL3.equals(jsonObject.query("/VAL3"))); - - expectedStr = "{\"myEnum\":\"VAL2\", \"myEnumField\":\"VAL2\"}"; - jsonObject = new JSONObject(); - jsonObject.putOpt("myEnum", myEnum); - jsonObject.putOnce("myEnumField", myEnumField); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonObject.query("/myEnum"))); - assertTrue("expected VAL2", MyEnumField.VAL2.equals(jsonObject.query("/myEnumField"))); - - JSONArray jsonArray = new JSONArray(); - jsonArray.put(myEnum); - jsonArray.put(1, myEnumField); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 2 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL2", MyEnum.VAL2.equals(jsonArray.query("/0"))); - assertTrue("expected VAL2", MyEnumField.VAL2.equals(jsonArray.query("/1"))); - } - - /** - * Wrap should handle enums exactly as a value type like Integer, Boolean, or String. - */ - @Test - public void wrap() { - assertTrue("simple enum has no getters", JSONObject.wrap(MyEnum.VAL2) instanceof MyEnum); - - MyEnumField myEnumField = MyEnumField.VAL2; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("enum",myEnumField); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 1 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected VAL2", MyEnumField.VAL2.equals(jsonObject.query("/enum"))); - - MyEnumClass myEnumClass = new MyEnumClass(); - myEnumClass.setMyEnum(MyEnum.VAL1); - myEnumClass.setMyEnumField(MyEnumField.VAL3); - jsonObject = (JSONObject)JSONObject.wrap(myEnumClass); - - // validate JSON content - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected VAL3", "VAL3".equals((JsonPath.read(doc, "$.myEnumField")))); - assertTrue("expected VAL1", "VAL1".equals((JsonPath.read(doc, "$.myEnum")))); - - assertTrue("expecting MyEnumField.VAL3", MyEnumField.VAL3.equals(jsonObject.query("/myEnumField"))); - assertTrue("expecting MyEnum.VAL1", MyEnum.VAL1.equals(jsonObject.query("/myEnum"))); - } - - /** - * It was determined that some API methods should be added to - * support enums:
- * JSONObject.getEnum(class, key)
- * JSONObject.optEnum(class, key)
- * JSONObject.optEnum(class, key, default)
- * JSONArray.getEnum(class, index)
- * JSONArray.optEnum(class, index)
- * JSONArray.optEnum(class, index, default)
- *

- * Exercise these enum API methods on JSONObject and JSONArray - */ - @Test - public void enumAPI() { - MyEnumClass myEnumClass = new MyEnumClass(); - myEnumClass.setMyEnum(MyEnum.VAL1); - MyEnumField myEnumField = MyEnumField.VAL2; - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("strKey", "value"); - jsonObject.put("strKey2", "VAL1"); - jsonObject.put("enumKey", myEnumField); - jsonObject.put("enumClassKey", myEnumClass); - - // get a plain old enum - MyEnumField actualEnum = jsonObject.getEnum(MyEnumField.class, "enumKey"); - assertTrue("get myEnumField", actualEnum == MyEnumField.VAL2); - - // try to get the wrong value - try { - actualEnum = jsonObject.getEnum(MyEnumField.class, "strKey"); - assertTrue("should throw an exception for wrong key", false); - } catch (Exception ignored) {} - - // get a class that contains an enum - MyEnumClass actualEnumClass = (MyEnumClass)jsonObject.get("enumClassKey"); - assertTrue("get enum", actualEnumClass.getMyEnum() == MyEnum.VAL1); - - // opt a plain old enum - actualEnum = jsonObject.optEnum(MyEnumField.class, "enumKey"); - assertTrue("opt myEnumField", actualEnum == MyEnumField.VAL2); - - // opt the wrong value - actualEnum = jsonObject.optEnum(MyEnumField.class, "strKey"); - assertTrue("opt null", actualEnum == null); - - // opt a class that contains an enum - actualEnumClass = (MyEnumClass)jsonObject.opt("enumClassKey"); - assertTrue("get enum", actualEnumClass.getMyEnum() == MyEnum.VAL1); - - // opt with default a plain old enum - actualEnum = jsonObject.optEnum(MyEnumField.class, "enumKey", null); - assertTrue("opt myEnumField", actualEnum == MyEnumField.VAL2); - - // opt with default the wrong value - actualEnum = jsonObject.optEnum(MyEnumField.class, "strKey", null); - assertNull("opt null", actualEnum); - - // opt with default the string value - actualEnum = jsonObject.optEnum(MyEnumField.class, "strKey2", null); - assertEquals(MyEnumField.VAL1, actualEnum); - - // opt with default an index that does not exist - actualEnum = jsonObject.optEnum(MyEnumField.class, "noKey", null); - assertNull("opt null", actualEnum); - - assertNull("Expected Null when the enum class is null", - jsonObject.optEnum(null, "enumKey")); - - /** - * Exercise the proposed enum API methods on JSONArray - */ - JSONArray jsonArray = new JSONArray(); - jsonArray.put("value"); - jsonArray.put(myEnumField); - jsonArray.put(myEnumClass); - - // get a plain old enum - actualEnum = jsonArray.getEnum(MyEnumField.class, 1); - assertTrue("get myEnumField", actualEnum == MyEnumField.VAL2); - - // try to get the wrong value - try { - actualEnum = jsonArray.getEnum(MyEnumField.class, 0); - assertTrue("should throw an exception for wrong index", false); - } catch (Exception ignored) {} - - // get a class that contains an enum - actualEnumClass = (MyEnumClass)jsonArray.get(2); - assertTrue("get enum", actualEnumClass.getMyEnum() == MyEnum.VAL1); - - // opt a plain old enum - actualEnum = jsonArray.optEnum(MyEnumField.class, 1); - assertTrue("opt myEnumField", actualEnum == MyEnumField.VAL2); - - // opt the wrong value - actualEnum = jsonArray.optEnum(MyEnumField.class, 0); - assertTrue("opt null", actualEnum == null); - - // opt a class that contains an enum - actualEnumClass = (MyEnumClass)jsonArray.opt(2); - assertTrue("get enum", actualEnumClass.getMyEnum() == MyEnum.VAL1); - - // opt with default a plain old enum - actualEnum = jsonArray.optEnum(MyEnumField.class, 1, null); - assertTrue("opt myEnumField", actualEnum == MyEnumField.VAL2); - - // opt with default the wrong value - actualEnum = jsonArray.optEnum(MyEnumField.class, 0, null); - assertTrue("opt null", actualEnum == null); - - // opt with default an index that does not exist - actualEnum = jsonArray.optEnum(MyEnumField.class, 3, null); - assertTrue("opt null", actualEnum == null); - - } -} diff --git a/src/test/java/org/json/junit/HTTPTest.java b/src/test/java/org/json/junit/HTTPTest.java deleted file mode 100644 index 703d5ad2f..000000000 --- a/src/test/java/org/json/junit/HTTPTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import org.json.*; -import org.junit.Test; - - -/** - * Unit tests for JSON-Java HTTP.java. See RFC7230. - */ -public class HTTPTest { - - /** - * Attempt to call HTTP.toJSONObject() with a null string - * Expects a NUllPointerException. - */ - @Test(expected=NullPointerException.class) - public void nullHTTPException() { - String httpStr = null; - HTTP.toJSONObject(httpStr); - } - - /** - * Attempt to call HTTP.toJSONObject() with a string containing - * an empty object. Expects a JSONException. - */ - @Test - public void notEnoughHTTPException() { - String httpStr = "{}"; - JSONObject jsonObject = new JSONObject(httpStr); - try { - HTTP.toString(jsonObject); - assertTrue("Expected to throw exception", false); - } catch (JSONException e) { - assertTrue("Expecting an exception message", - "Not enough material for an HTTP header.".equals(e.getMessage())); - } - } - - /** - * Calling HTTP.toJSONObject() with an empty string will result in a - * populated JSONObject with keys but no values for Request-URI, Method, - * and HTTP-Version. - */ - @Test - public void emptyStringHTTPRequest() { - String httpStr = ""; - String expectedHTTPStr = "{\"Request-URI\":\"\",\"Method\":\"\",\"HTTP-Version\":\"\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a Request-URI, Method, - * and HTTP-Version. - */ - @Test - public void simpleHTTPRequest() { - String httpStr = "GET /hello.txt HTTP/1.1"; - String expectedHTTPStr = - "{\"Request-URI\":\"/hello.txt\",\"Method\":\"GET\",\"HTTP-Version\":\"HTTP/1.1\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a response string containing a - * HTTP-Version, Status-Code, and Reason. - */ - @Test - public void simpleHTTPResponse() { - String httpStr = "HTTP/1.1 200 OK"; - String expectedHTTPStr = - "{\"HTTP-Version\":\"HTTP/1.1\",\"Status-Code\":\"200\",\"Reason-Phrase\":\"OK\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a full request string including - * request headers. - */ - @Test - public void extendedHTTPRequest() { - String httpStr = - "POST /enlighten/calais.asmx HTTP/1.1\n"+ - "Host: api.opencalais.com\n"+ - "Content-Type: text/xml; charset=utf-8\n"+ - "Content-Length: 100\n"+ - "SOAPAction: \"http://clearforest.com/Enlighten\""; - String expectedHTTPStr = - "{"+ - "\"Request-URI\":\"/enlighten/calais.asmx\","+ - "\"Host\":\"api.opencalais.com\","+ - "\"Method\":\"POST\","+ - "\"HTTP-Version\":\"HTTP/1.1\","+ - "\"Content-Length\":\"100\","+ - "\"Content-Type\":\"text/xml; charset=utf-8\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - /** - * Not too easy for JSONObject to parse a string with embedded quotes. - * For the sake of the test, add it here. - */ - expectedJsonObject.put("SOAPAction","\"http://clearforest.com/Enlighten\""); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a full response string including - * response headers. - */ - @Test - public void extendedHTTPResponse() { - String httpStr = - "HTTP/1.1 200 OK\n"+ - "Content-Type: text/xml; charset=utf-8\n"+ - "Content-Length: 100\n"; - String expectedHTTPStr = - "{\"HTTP-Version\":\"HTTP/1.1\","+ - "\"Status-Code\":\"200\","+ - "\"Content-Length\":\"100\","+ - "\"Reason-Phrase\":\"OK\","+ - "\"Content-Type\":\"text/xml; charset=utf-8\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a full POST request string including - * response headers, then convert it back into an HTTP string. - */ - @Test - public void convertHTTPRequestToString() { - String httpStr = - "POST /enlighten/calais.asmx HTTP/1.1\n"+ - "Host: api.opencalais.com\n"+ - "Content-Type: text/xml; charset=utf-8\n"+ - "Content-Length: 100"; - String expectedHTTPStr = - "{"+ - "\"Request-URI\":\"/enlighten/calais.asmx\","+ - "\"Host\":\"api.opencalais.com\","+ - "\"Method\":\"POST\","+ - "\"HTTP-Version\":\"HTTP/1.1\","+ - "\"Content-Length\":\"100\","+ - "\"Content-Type\":\"text/xml; charset=utf-8\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - String httpToStr = HTTP.toString(jsonObject); - /** - * JSONObject objects to crlfs and any trailing chars. - * For the sake of the test, simplify the resulting string - */ - httpToStr = httpToStr.replaceAll("("+HTTP.CRLF+HTTP.CRLF+")", ""); - httpToStr = httpToStr.replaceAll(HTTP.CRLF, "\n"); - JSONObject finalJsonObject = HTTP.toJSONObject(httpToStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - /** - * Call HTTP.toJSONObject() with a full response string including - * response headers, then convert it back into an HTTP string. - */ - @Test - public void convertHTTPResponseToString() { - String httpStr = - "HTTP/1.1 200 OK\n"+ - "Content-Type: text/xml; charset=utf-8\n"+ - "Content-Length: 100\n"; - String expectedHTTPStr = - "{\"HTTP-Version\":\"HTTP/1.1\","+ - "\"Status-Code\":\"200\","+ - "\"Content-Length\":\"100\","+ - "\"Reason-Phrase\":\"OK\","+ - "\"Content-Type\":\"text/xml; charset=utf-8\"}"; - JSONObject jsonObject = HTTP.toJSONObject(httpStr); - JSONObject expectedJsonObject = new JSONObject(expectedHTTPStr); - String httpToStr = HTTP.toString(jsonObject); - /** - * JSONObject objects to crlfs and any trailing chars. - * For the sake of the test, simplify the resulting string - */ - httpToStr = httpToStr.replaceAll("("+HTTP.CRLF+HTTP.CRLF+")", ""); - httpToStr = httpToStr.replaceAll(HTTP.CRLF, "\n"); - JSONObject finalJsonObject = HTTP.toJSONObject(httpToStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } -} diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java deleted file mode 100644 index 485d43e7b..000000000 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ /dev/null @@ -1,1511 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONParserConfiguration; -import org.json.JSONPointerException; -import org.json.JSONString; -import org.json.JSONTokener; -import org.json.ParserConfiguration; -import org.json.junit.data.MyJsonString; -import org.junit.Ignore; -import org.junit.Test; - -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.JsonPath; - - -/** - * Tests for JSON-Java JSONArray.java - */ -public class JSONArrayTest { - private final String arrayStr = - "["+ - "true,"+ - "false,"+ - "\"true\","+ - "\"false\","+ - "\"hello\","+ - "23.45e-4,"+ - "\"23.45\","+ - "42,"+ - "\"43\","+ - "["+ - "\"world\""+ - "],"+ - "{"+ - "\"key1\":\"value1\","+ - "\"key2\":\"value2\","+ - "\"key3\":\"value3\","+ - "\"key4\":\"value4\""+ - "},"+ - "0,"+ - "\"-1\""+ - "]"; - - /** - * Tests that the similar method is working as expected. - */ - @Test - public void verifySimilar() { - final String string1 = "HasSameRef"; - final String string2 = "HasDifferentRef"; - JSONArray obj1 = new JSONArray() - .put("abc") - .put(string1) - .put(2); - - JSONArray obj2 = new JSONArray() - .put("abc") - .put(string1) - .put(3); - - JSONArray obj3 = new JSONArray() - .put("abc") - .put(new String(string1)) - .put(2); - - JSONArray obj4 = new JSONArray() - .put("abc") - .put(2.0) - .put(new String(string1)); - - JSONArray obj5 = new JSONArray() - .put("abc") - .put(2.0) - .put(new String(string2)); - - assertFalse("obj1-obj2 Should eval to false", obj1.similar(obj2)); - assertTrue("obj1-obj3 Should eval to true", obj1.similar(obj3)); - assertFalse("obj4-obj5 Should eval to false", obj4.similar(obj5)); - } - - /** - * Attempt to create a JSONArray with a null string. - * Expects a NullPointerException. - */ - @Test(expected=NullPointerException.class) - public void nullException() { - String str = null; - assertNull("Should throw an exception", new JSONArray(str)); - } - - /** - * Attempt to create a JSONArray with an empty string. - * Expects a JSONException. - */ - @Test - public void emptyStr() { - String str = ""; - try { - assertNull("Should throw an exception", new JSONArray(str)); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "A JSONArray text must start with '[' at 0 [character 1 line 1]", - e.getMessage()); - } - } - - /** - * Attempt to create a JSONArray with an unclosed array. - * Expects an exception - */ - @Test - public void unclosedArray() { - try { - assertNull("Should throw an exception", new JSONArray("[")); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "Expected a ',' or ']' but instead found '[' at 1 [character 2 line 1]", - e.getMessage()); - } - } - - /** - * Attempt to create a JSONArray with an unclosed array. - * Expects an exception - */ - @Test - public void unclosedArray2() { - try { - assertNull("Should throw an exception", new JSONArray("[\"test\"")); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "Expected a ',' or ']' but instead found '\"' at 7 [character 8 line 1]", - e.getMessage()); - } - } - - /** - * Attempt to create a JSONArray with an unclosed array. - * Expects an exception - */ - @Test - public void unclosedArray3() { - try { - assertNull("Should throw an exception", new JSONArray("[\"test\",")); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "Expected a ',' or ']' but instead found ',' at 8 [character 9 line 1]", - e.getMessage()); - } - } - - /** - * Attempt to create a JSONArray with a string as object that is - * not a JSON array doc. - * Expects a JSONException. - */ - @Test - public void badObject() { - String str = "abc"; - try { - assertNull("Should throw an exception", new JSONArray((Object)str)); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "JSONArray initial value should be a string or collection or array.". - equals(e.getMessage())); - } - } - - /** - * Verifies that the constructor has backwards compatibility with RAW types pre-java5. - */ - @Test - public void verifyConstructor() { - - final JSONArray expected = new JSONArray("[10]"); - - @SuppressWarnings("rawtypes") - Collection myRawC = Collections.singleton(Integer.valueOf(10)); - JSONArray jaRaw = new JSONArray(myRawC); - - Collection myCInt = Collections.singleton(Integer.valueOf(10)); - JSONArray jaInt = new JSONArray(myCInt); - - Collection myCObj = Collections.singleton((Object) Integer - .valueOf(10)); - JSONArray jaObj = new JSONArray(myCObj); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaInt)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObj)); - Util.checkJSONArrayMaps(expected); - Util.checkJSONArrayMaps(jaObj); - Util.checkJSONArrayMaps(jaRaw); - Util.checkJSONArrayMaps(jaInt); - } - - /** - * Tests consecutive calls to putAll with array and collection. - */ - @Test - public void verifyPutAll() { - final JSONArray jsonArray = new JSONArray(); - - // array - int[] myInts = { 1, 2, 3, 4, 5 }; - jsonArray.putAll(myInts); - - assertEquals("int arrays lengths should be equal", - jsonArray.length(), - myInts.length); - - for (int i = 0; i < myInts.length; i++) { - assertEquals("int arrays elements should be equal", - myInts[i], - jsonArray.getInt(i)); - } - - // collection - List myList = Arrays.asList("one", "two", "three", "four", "five"); - jsonArray.putAll(myList); - - int len = myInts.length + myList.size(); - - assertEquals("arrays lengths should be equal", - jsonArray.length(), - len); - - for (int i = 0; i < myList.size(); i++) { - assertEquals("collection elements should be equal", - myList.get(i), - jsonArray.getString(myInts.length + i)); - } - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Verifies that the put Collection has backwards compatibility with RAW types pre-java5. - */ - @Test - public void verifyPutCollection() { - - final JSONArray expected = new JSONArray("[[10]]"); - - @SuppressWarnings("rawtypes") - Collection myRawC = Collections.singleton(Integer.valueOf(10)); - JSONArray jaRaw = new JSONArray(); - jaRaw.put(myRawC); - - Collection myCObj = Collections.singleton((Object) Integer - .valueOf(10)); - JSONArray jaObj = new JSONArray(); - jaObj.put(myCObj); - - Collection myCInt = Collections.singleton(Integer.valueOf(10)); - JSONArray jaInt = new JSONArray(); - jaInt.put(myCInt); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObj)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaInt)); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - jaRaw, jaObj, jaInt - ))); - } - - - /** - * Verifies that the put Map has backwards compatibility with RAW types pre-java5. - */ - @Test - public void verifyPutMap() { - - final JSONArray expected = new JSONArray("[{\"myKey\":10}]"); - - @SuppressWarnings("rawtypes") - Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10)); - JSONArray jaRaw = new JSONArray(); - jaRaw.put(myRawC); - - Map myCStrObj = Collections.singletonMap("myKey", - (Object) Integer.valueOf(10)); - JSONArray jaStrObj = new JSONArray(); - jaStrObj.put(myCStrObj); - - Map myCStrInt = Collections.singletonMap("myKey", - Integer.valueOf(10)); - JSONArray jaStrInt = new JSONArray(); - jaStrInt.put(myCStrInt); - - Map myCObjObj = Collections.singletonMap((Object) "myKey", - (Object) Integer.valueOf(10)); - JSONArray jaObjObj = new JSONArray(); - jaObjObj.put(myCObjObj); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrObj)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrInt)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObjObj)); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - expected, jaRaw, jaStrObj, jaStrInt, jaObjObj - ))); - } - - /** - * Create a JSONArray doc with a variety of different elements. - * Confirm that the values can be accessed via the get[type]() API methods - */ - @SuppressWarnings("boxing") - @Test - public void getArrayValues() { - JSONArray jsonArray = new JSONArray(this.arrayStr); - // booleans - assertTrue("Array true", - true == jsonArray.getBoolean(0)); - assertTrue("Array false", - false == jsonArray.getBoolean(1)); - assertTrue("Array string true", - true == jsonArray.getBoolean(2)); - assertTrue("Array string false", - false == jsonArray.getBoolean(3)); - // strings - assertTrue("Array value string", - "hello".equals(jsonArray.getString(4))); - // doubles - assertTrue("Array double", - Double.valueOf(23.45e-4).equals(jsonArray.getDouble(5))); - assertTrue("Array string double", - Double.valueOf(23.45).equals(jsonArray.getDouble(6))); - assertTrue("Array double can be float", - Float.valueOf(23.45e-4f).equals(jsonArray.getFloat(5))); - // ints - assertTrue("Array value int", - Integer.valueOf(42).equals(jsonArray.getInt(7))); - assertTrue("Array value string int", - Integer.valueOf(43).equals(jsonArray.getInt(8))); - // nested objects - JSONArray nestedJsonArray = jsonArray.getJSONArray(9); - assertTrue("Array value JSONArray", nestedJsonArray != null); - JSONObject nestedJsonObject = jsonArray.getJSONObject(10); - assertTrue("Array value JSONObject", nestedJsonObject != null); - // longs - assertTrue("Array value long", - Long.valueOf(0).equals(jsonArray.getLong(11))); - assertTrue("Array value string long", - Long.valueOf(-1).equals(jsonArray.getLong(12))); - - assertTrue("Array value null", jsonArray.isNull(-1)); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Create a JSONArray doc with a variety of different elements. - * Confirm that attempting to get the wrong types via the get[type]() - * API methods result in JSONExceptions - */ - @Test - public void failedGetArrayValues() { - JSONArray jsonArray = new JSONArray(this.arrayStr); - try { - jsonArray.getBoolean(4); - assertTrue("expected getBoolean to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a boolean (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.get(-1); - assertTrue("expected get to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[-1] not found.",e.getMessage()); - } - try { - jsonArray.getDouble(4); - assertTrue("expected getDouble to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a double (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.getInt(4); - assertTrue("expected getInt to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a int (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.getJSONArray(4); - assertTrue("expected getJSONArray to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a JSONArray (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.getJSONObject(4); - assertTrue("expected getJSONObject to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a JSONObject (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.getLong(4); - assertTrue("expected getLong to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[4] is not a long (class java.lang.String : hello).",e.getMessage()); - } - try { - jsonArray.getString(5); - assertTrue("expected getString to fail", false); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray[5] is not a String (class java.math.BigDecimal : 0.002345).",e.getMessage()); - } - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * The JSON parser is permissive of unambiguous unquoted keys and values. - * Such JSON text should be allowed, even if it does not strictly conform - * to the spec. However, after being parsed, toString() should emit strictly - * conforming JSON text. - */ - // TODO: This test will only run in non-strictMode. TBD later. - @Ignore - public void unquotedText() { - String str = "[value1, something!, (parens), foo@bar.com, 23, 23+45]"; - JSONArray jsonArray = new JSONArray(str); - List expected = Arrays.asList("value1", "something!", "(parens)", "foo@bar.com", 23, "23+45"); - assertEquals(expected, jsonArray.toList()); - } - - /** - * Exercise JSONArray.join() by converting a JSONArray into a - * comma-separated string. Since this is very nearly a JSON document, - * array braces are added to the beginning and end prior to validation. - */ - @Test - public void join() { - JSONArray jsonArray = new JSONArray(this.arrayStr); - String joinStr = jsonArray.join(","); - - // validate JSON - /** - * Don't need to remake the JSONArray to perform the parsing - */ - Object doc = Configuration.defaultConfiguration().jsonProvider().parse("["+joinStr+"]"); - assertTrue("expected 13 items in top level object", ((List)(JsonPath.read(doc, "$"))).size() == 13); - assertTrue("expected true", Boolean.TRUE.equals(jsonArray.query("/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonArray.query("/1"))); - assertTrue("expected \"true\"", "true".equals(jsonArray.query("/2"))); - assertTrue("expected \"false\"", "false".equals(jsonArray.query("/3"))); - assertTrue("expected hello", "hello".equals(jsonArray.query("/4"))); - assertTrue("expected 0.002345", BigDecimal.valueOf(0.002345).equals(jsonArray.query("/5"))); - assertTrue("expected \"23.45\"", "23.45".equals(jsonArray.query("/6"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonArray.query("/7"))); - assertTrue("expected \"43\"", "43".equals(jsonArray.query("/8"))); - assertTrue("expected 1 item in [9]", ((List)(JsonPath.read(doc, "$[9]"))).size() == 1); - assertTrue("expected world", "world".equals(jsonArray.query("/9/0"))); - assertTrue("expected 4 items in [10]", ((Map)(JsonPath.read(doc, "$[10]"))).size() == 4); - assertTrue("expected value1", "value1".equals(jsonArray.query("/10/key1"))); - assertTrue("expected value2", "value2".equals(jsonArray.query("/10/key2"))); - assertTrue("expected value3", "value3".equals(jsonArray.query("/10/key3"))); - assertTrue("expected value4", "value4".equals(jsonArray.query("/10/key4"))); - assertTrue("expected 0", Integer.valueOf(0).equals(jsonArray.query("/11"))); - assertTrue("expected \"-1\"", "-1".equals(jsonArray.query("/12"))); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Confirm the JSONArray.length() method - */ - @Test - public void length() { - assertTrue("expected empty JSONArray length 0", - new JSONArray().length() == 0); - JSONArray jsonArray = new JSONArray(this.arrayStr); - assertTrue("expected JSONArray length 13. instead found "+jsonArray.length(), jsonArray.length() == 13); - JSONArray nestedJsonArray = jsonArray.getJSONArray(9); - assertTrue("expected JSONArray length 1", nestedJsonArray.length() == 1); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - jsonArray, nestedJsonArray - ))); - } - - /** - * Create a JSONArray doc with a variety of different elements. - * Confirm that the values can be accessed via the opt[type](index) - * and opt[type](index, default) API methods. - */ - @SuppressWarnings("boxing") - @Test - public void opt() { - JSONArray jsonArray = new JSONArray(this.arrayStr); - assertTrue("Array opt value true", - Boolean.TRUE == jsonArray.opt(0)); - assertTrue("Array opt value out of range", - null == jsonArray.opt(-1)); - - assertTrue("Array opt value out of range", - null == jsonArray.opt(jsonArray.length())); - - assertTrue("Array opt boolean", - Boolean.TRUE == jsonArray.optBoolean(0)); - assertTrue("Array opt boolean default", - Boolean.FALSE == jsonArray.optBoolean(-1, Boolean.FALSE)); - assertTrue("Array opt boolean implicit default", - Boolean.FALSE == jsonArray.optBoolean(-1)); - - assertTrue("Array opt boolean object", - Boolean.TRUE.equals(jsonArray.optBooleanObject(0))); - assertTrue("Array opt boolean object default", - Boolean.FALSE.equals(jsonArray.optBooleanObject(-1, Boolean.FALSE))); - assertTrue("Array opt boolean object implicit default", - Boolean.FALSE.equals(jsonArray.optBooleanObject(-1))); - - assertTrue("Array opt double", - Double.valueOf(23.45e-4).equals(jsonArray.optDouble(5))); - assertTrue("Array opt double default", - Double.valueOf(1).equals(jsonArray.optDouble(0, 1))); - assertTrue("Array opt double default implicit", - Double.valueOf(jsonArray.optDouble(99)).isNaN()); - - assertTrue("Array opt double object", - Double.valueOf(23.45e-4).equals(jsonArray.optDoubleObject(5))); - assertTrue("Array opt double object default", - Double.valueOf(1).equals(jsonArray.optDoubleObject(0, 1D))); - assertTrue("Array opt double object default implicit", - jsonArray.optDoubleObject(99).isNaN()); - - assertTrue("Array opt float", - Float.valueOf(Double.valueOf(23.45e-4).floatValue()).equals(jsonArray.optFloat(5))); - assertTrue("Array opt float default", - Float.valueOf(1).equals(jsonArray.optFloat(0, 1))); - assertTrue("Array opt float default implicit", - Float.valueOf(jsonArray.optFloat(99)).isNaN()); - - assertTrue("Array opt float object", - Float.valueOf(23.45e-4F).equals(jsonArray.optFloatObject(5))); - assertTrue("Array opt float object default", - Float.valueOf(1).equals(jsonArray.optFloatObject(0, 1F))); - assertTrue("Array opt float object default implicit", - jsonArray.optFloatObject(99).isNaN()); - - assertTrue("Array opt Number", - BigDecimal.valueOf(23.45e-4).equals(jsonArray.optNumber(5))); - assertTrue("Array opt Number default", - Double.valueOf(1).equals(jsonArray.optNumber(0, 1d))); - assertTrue("Array opt Number default implicit", - Double.valueOf(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN()); - - assertTrue("Array opt int", - Integer.valueOf(42).equals(jsonArray.optInt(7))); - assertTrue("Array opt int default", - Integer.valueOf(-1).equals(jsonArray.optInt(0, -1))); - assertTrue("Array opt int default implicit", - 0 == jsonArray.optInt(0)); - - assertTrue("Array opt int object", - Integer.valueOf(42).equals(jsonArray.optIntegerObject(7))); - assertTrue("Array opt int object default", - Integer.valueOf(-1).equals(jsonArray.optIntegerObject(0, -1))); - assertTrue("Array opt int object default implicit", - Integer.valueOf(0).equals(jsonArray.optIntegerObject(0))); - - JSONArray nestedJsonArray = jsonArray.optJSONArray(9); - assertTrue("Array opt JSONArray", nestedJsonArray != null); - assertTrue("Array opt JSONArray null", - null == jsonArray.optJSONArray(99)); - assertTrue("Array opt JSONArray default", - "value".equals(jsonArray.optJSONArray(99, new JSONArray("[\"value\"]")).getString(0))); - - JSONObject nestedJsonObject = jsonArray.optJSONObject(10); - assertTrue("Array opt JSONObject", nestedJsonObject != null); - assertTrue("Array opt JSONObject null", - null == jsonArray.optJSONObject(99)); - assertTrue("Array opt JSONObject default", - "value".equals(jsonArray.optJSONObject(99, new JSONObject("{\"key\":\"value\"}")).getString("key"))); - - assertTrue("Array opt long", - 0 == jsonArray.optLong(11)); - assertTrue("Array opt long default", - -2 == jsonArray.optLong(-1, -2)); - assertTrue("Array opt long default implicit", - 0 == jsonArray.optLong(-1)); - - assertTrue("Array opt long object", - Long.valueOf(0).equals(jsonArray.optLongObject(11))); - assertTrue("Array opt long object default", - Long.valueOf(-2).equals(jsonArray.optLongObject(-1, -2L))); - assertTrue("Array opt long object default implicit", - Long.valueOf(0).equals(jsonArray.optLongObject(-1))); - - assertTrue("Array opt string", - "hello".equals(jsonArray.optString(4))); - assertTrue("Array opt string default implicit", - "".equals(jsonArray.optString(-1))); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - jsonArray, nestedJsonArray - ))); - Util.checkJSONObjectMaps(nestedJsonObject); - } - - /** - * Verifies that the opt methods properly convert string values. - */ - @Test - public void optStringConversion(){ - JSONArray ja = new JSONArray("[\"123\",\"true\",\"false\"]"); - assertTrue("unexpected optBoolean value",ja.optBoolean(1,false)==true); - assertTrue("unexpected optBooleanObject value",Boolean.valueOf(true).equals(ja.optBooleanObject(1,false))); - assertTrue("unexpected optBoolean value",ja.optBoolean(2,true)==false); - assertTrue("unexpected optBooleanObject value",Boolean.valueOf(false).equals(ja.optBooleanObject(2,true))); - assertTrue("unexpected optInt value",ja.optInt(0,0)==123); - assertTrue("unexpected optIntegerObject value",Integer.valueOf(123).equals(ja.optIntegerObject(0,0))); - assertTrue("unexpected optLong value",ja.optLong(0,0)==123); - assertTrue("unexpected optLongObject value",Long.valueOf(123).equals(ja.optLongObject(0,0L))); - assertTrue("unexpected optDouble value",ja.optDouble(0,0.0)==123.0); - assertTrue("unexpected optDoubleObject value",Double.valueOf(123.0).equals(ja.optDoubleObject(0,0.0))); - assertTrue("unexpected optBigInteger value",ja.optBigInteger(0,BigInteger.ZERO).compareTo(new BigInteger("123"))==0); - assertTrue("unexpected optBigDecimal value",ja.optBigDecimal(0,BigDecimal.ZERO).compareTo(new BigDecimal("123"))==0); - Util.checkJSONArrayMaps(ja); - } - - /** - * Exercise the JSONArray.put(value) method with various parameters - * and confirm the resulting JSONArray. - */ - @SuppressWarnings("boxing") - @Test - public void put() { - JSONArray jsonArray = new JSONArray(); - - // index 0 - jsonArray.put(true); - // 1 - jsonArray.put(false); - - String jsonArrayStr = - "["+ - "\"hello\","+ - "\"world\""+ - "]"; - // 2 - jsonArray.put(new JSONArray(jsonArrayStr)); - - // 3 - jsonArray.put(2.5); - // 4 - jsonArray.put(1); - // 5 - jsonArray.put(45L); - - // 6 - jsonArray.put("objectPut"); - - String jsonObjectStr = - "{"+ - "\"key10\":\"val10\","+ - "\"key20\":\"val20\","+ - "\"key30\":\"val30\""+ - "}"; - JSONObject jsonObject = new JSONObject(jsonObjectStr); - // 7 - jsonArray.put(jsonObject); - - Map map = new HashMap(); - map.put("k1", "v1"); - // 8 - jsonArray.put(map); - - Collection collection = new ArrayList(); - collection.add(1); - collection.add(2); - // 9 - jsonArray.put(collection); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 10 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 10); - assertTrue("expected true", Boolean.TRUE.equals(jsonArray.query("/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonArray.query("/1"))); - assertTrue("expected 2 items in [2]", ((List)(JsonPath.read(doc, "$[2]"))).size() == 2); - assertTrue("expected hello", "hello".equals(jsonArray.query("/2/0"))); - assertTrue("expected world", "world".equals(jsonArray.query("/2/1"))); - assertTrue("expected 2.5", Double.valueOf(2.5).equals(jsonArray.query("/3"))); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/4"))); - assertTrue("expected 45", Long.valueOf(45).equals(jsonArray.query("/5"))); - assertTrue("expected objectPut", "objectPut".equals(jsonArray.query("/6"))); - assertTrue("expected 3 items in [7]", ((Map)(JsonPath.read(doc, "$[7]"))).size() == 3); - assertTrue("expected val10", "val10".equals(jsonArray.query("/7/key10"))); - assertTrue("expected val20", "val20".equals(jsonArray.query("/7/key20"))); - assertTrue("expected val30", "val30".equals(jsonArray.query("/7/key30"))); - assertTrue("expected 1 item in [8]", ((Map)(JsonPath.read(doc, "$[8]"))).size() == 1); - assertTrue("expected v1", "v1".equals(jsonArray.query("/8/k1"))); - assertTrue("expected 2 items in [9]", ((List)(JsonPath.read(doc, "$[9]"))).size() == 2); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/9/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/9/1"))); - Util.checkJSONArrayMaps(jsonArray); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise the JSONArray.put(index, value) method with various parameters - * and confirm the resulting JSONArray. - */ - @SuppressWarnings("boxing") - @Test - public void putIndex() { - JSONArray jsonArray = new JSONArray(); - - // 1 - jsonArray.put(1, false); - // index 0 - jsonArray.put(0, true); - - String jsonArrayStr = - "["+ - "\"hello\","+ - "\"world\""+ - "]"; - // 2 - jsonArray.put(2, new JSONArray(jsonArrayStr)); - - // 5 - jsonArray.put(5, 45L); - // 4 - jsonArray.put(4, 1); - // 3 - jsonArray.put(3, 2.5); - - // 6 - jsonArray.put(6, "objectPut"); - - // 7 will be null - - String jsonObjectStr = - "{"+ - "\"key10\":\"val10\","+ - "\"key20\":\"val20\","+ - "\"key30\":\"val30\""+ - "}"; - JSONObject jsonObject = new JSONObject(jsonObjectStr); - jsonArray.put(8, jsonObject); - Collection collection = new ArrayList(); - collection.add(1); - collection.add(2); - jsonArray.put(9,collection); - - Map map = new HashMap(); - map.put("k1", "v1"); - jsonArray.put(10, map); - try { - jsonArray.put(-1, "abc"); - assertTrue("put index < 0 should have thrown exception", false); - } catch(Exception ignored) {} - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 11 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 11); - assertTrue("expected true", Boolean.TRUE.equals(jsonArray.query("/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonArray.query("/1"))); - assertTrue("expected 2 items in [2]", ((List)(JsonPath.read(doc, "$[2]"))).size() == 2); - assertTrue("expected hello", "hello".equals(jsonArray.query("/2/0"))); - assertTrue("expected world", "world".equals(jsonArray.query("/2/1"))); - assertTrue("expected 2.5", Double.valueOf(2.5).equals(jsonArray.query("/3"))); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/4"))); - assertTrue("expected 45", Long.valueOf(45).equals(jsonArray.query("/5"))); - assertTrue("expected objectPut", "objectPut".equals(jsonArray.query("/6"))); - assertTrue("expected null", JSONObject.NULL.equals(jsonArray.query("/7"))); - assertTrue("expected 3 items in [8]", ((Map)(JsonPath.read(doc, "$[8]"))).size() == 3); - assertTrue("expected val10", "val10".equals(jsonArray.query("/8/key10"))); - assertTrue("expected val20", "val20".equals(jsonArray.query("/8/key20"))); - assertTrue("expected val30", "val30".equals(jsonArray.query("/8/key30"))); - assertTrue("expected 2 items in [9]", ((List)(JsonPath.read(doc, "$[9]"))).size() == 2); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/9/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/9/1"))); - assertTrue("expected 1 item in [10]", ((Map)(JsonPath.read(doc, "$[10]"))).size() == 1); - assertTrue("expected v1", "v1".equals(jsonArray.query("/10/k1"))); - Util.checkJSONObjectMaps(jsonObject); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Exercise the JSONArray.remove(index) method - * and confirm the resulting JSONArray. - */ - @Test - public void remove() { - String arrayStr1 = - "["+ - "1"+ - "]"; - JSONArray jsonArray = new JSONArray(arrayStr1); - jsonArray.remove(0); - assertTrue("array should be empty", null == jsonArray.remove(5)); - assertTrue("jsonArray should be empty", jsonArray.isEmpty()); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Exercise the JSONArray.similar() method with various parameters - * and confirm the results when not similar. - */ - @Test - public void notSimilar() { - String arrayStr1 = - "["+ - "1"+ - "]"; - JSONArray jsonArray = new JSONArray(arrayStr1); - JSONArray otherJsonArray = new JSONArray(); - assertTrue("arrays lengths differ", !jsonArray.similar(otherJsonArray)); - - JSONObject jsonObject = new JSONObject("{\"k1\":\"v1\"}"); - JSONObject otherJsonObject = new JSONObject(); - jsonArray = new JSONArray(); - jsonArray.put(jsonObject); - otherJsonArray = new JSONArray(); - otherJsonArray.put(otherJsonObject); - assertTrue("arrays JSONObjects differ", !jsonArray.similar(otherJsonArray)); - - JSONArray nestedJsonArray = new JSONArray("[1, 2]"); - JSONArray otherNestedJsonArray = new JSONArray(); - jsonArray = new JSONArray(); - jsonArray.put(nestedJsonArray); - otherJsonArray = new JSONArray(); - otherJsonArray.put(otherNestedJsonArray); - assertTrue("arrays nested JSONArrays differ", - !jsonArray.similar(otherJsonArray)); - - jsonArray = new JSONArray(); - jsonArray.put("hello"); - otherJsonArray = new JSONArray(); - otherJsonArray.put("world"); - assertTrue("arrays values differ", - !jsonArray.similar(otherJsonArray)); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - jsonArray, otherJsonArray - ))); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject, otherJsonObject - ))); - } - - /** - * Exercise JSONArray toString() method with various indent levels. - */ - @Test - public void jsonArrayToStringIndent() { - String jsonArray0Str = - "[" + - "[1,2," + - "{\"key3\":true}" + - "]," + - "{\"key1\":\"val1\",\"key2\":" + - "{\"key2\":\"val2\"}" + - "}," + - "[" + - "[1,2.1]" + - "," + - "[null]" + - "]" + - "]"; - - String jsonArray1Strs [] = - { - "[", - " [", - " 1,", - " 2,", - " {\"key3\": true}", - " ],", - " {", - " \"key1\": \"val1\",", - " \"key2\": {\"key2\": \"val2\"}", - " },", - " [", - " [", - " 1,", - " 2.1", - " ],", - " [null]", - " ]", - "]" - }; - String jsonArray4Strs [] = - { - "[", - " [", - " 1,", - " 2,", - " {\"key3\": true}", - " ],", - " {", - " \"key1\": \"val1\",", - " \"key2\": {\"key2\": \"val2\"}", - " },", - " [", - " [", - " 1,", - " 2.1", - " ],", - " [null]", - " ]", - "]" - }; - JSONArray jsonArray = new JSONArray(jsonArray0Str); - String [] actualStrArray = jsonArray.toString().split("\\r?\\n"); - assertEquals("Expected 1 line", 1, actualStrArray.length); - actualStrArray = jsonArray.toString(0).split("\\r?\\n"); - assertEquals("Expected 1 line", 1, actualStrArray.length); - - actualStrArray = jsonArray.toString(1).split("\\r?\\n"); - assertEquals("Expected lines", jsonArray1Strs.length, actualStrArray.length); - List list = Arrays.asList(actualStrArray); - for (String s : jsonArray1Strs) { - list.contains(s); - } - - actualStrArray = jsonArray.toString(4).split("\\r?\\n"); - assertEquals("Expected lines", jsonArray1Strs.length, actualStrArray.length); - list = Arrays.asList(actualStrArray); - for (String s : jsonArray4Strs) { - list.contains(s); - } - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Convert an empty JSONArray to JSONObject - */ - @Test - public void toJSONObject() { - JSONArray names = new JSONArray(); - JSONArray jsonArray = new JSONArray(); - assertTrue("toJSONObject should return null", - null == jsonArray.toJSONObject(names)); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - names, jsonArray - ))); - } - - /** - * Confirm the creation of a JSONArray from an array of ints - */ - @Test - public void objectArrayVsIsArray() { - int[] myInts = { 1, 2, 3, 4, 5, 6, 7 }; - Object myObject = myInts; - JSONArray jsonArray = new JSONArray(myObject); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 7 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 7); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/1"))); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2"))); - assertTrue("expected 4", Integer.valueOf(4).equals(jsonArray.query("/3"))); - assertTrue("expected 5", Integer.valueOf(5).equals(jsonArray.query("/4"))); - assertTrue("expected 6", Integer.valueOf(6).equals(jsonArray.query("/5"))); - assertTrue("expected 7", Integer.valueOf(7).equals(jsonArray.query("/6"))); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Exercise the JSONArray iterator. - */ - @SuppressWarnings("boxing") - @Test - public void iteratorTest() { - JSONArray jsonArray = new JSONArray(this.arrayStr); - Iterator it = jsonArray.iterator(); - assertTrue("Array true", - Boolean.TRUE.equals(it.next())); - assertTrue("Array false", - Boolean.FALSE.equals(it.next())); - assertTrue("Array string true", - "true".equals(it.next())); - assertTrue("Array string false", - "false".equals(it.next())); - assertTrue("Array string", - "hello".equals(it.next())); - - assertTrue("Array double [23.45e-4]", - new BigDecimal("0.002345").equals(it.next())); - assertTrue("Array string double", - Double.valueOf(23.45).equals(Double.parseDouble((String)it.next()))); - - assertTrue("Array value int", - Integer.valueOf(42).equals(it.next())); - assertTrue("Array value string int", - Integer.valueOf(43).equals(Integer.parseInt((String)it.next()))); - - JSONArray nestedJsonArray = (JSONArray)it.next(); - assertTrue("Array value JSONArray", nestedJsonArray != null); - - JSONObject nestedJsonObject = (JSONObject)it.next(); - assertTrue("Array value JSONObject", nestedJsonObject != null); - - assertTrue("Array value long", - Long.valueOf(0).equals(((Number) it.next()).longValue())); - assertTrue("Array value string long", - Long.valueOf(-1).equals(Long.parseLong((String) it.next()))); - assertTrue("should be at end of array", !it.hasNext()); - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - jsonArray, nestedJsonArray - ))); - Util.checkJSONObjectMaps(nestedJsonObject); - } - - @Test(expected = JSONPointerException.class) - public void queryWithNoResult() { - new JSONArray().query("/a/b"); - } - - @Test - public void optQueryWithNoResult() { - assertNull(new JSONArray().optQuery("/a/b")); - } - - @Test(expected = IllegalArgumentException.class) - public void optQueryWithSyntaxError() { - new JSONArray().optQuery("invalid"); - } - - - /** - * Exercise the JSONArray write() method - */ - @Test - public void write() throws IOException { - String str = "[\"value1\",\"value2\",{\"key1\":1,\"key2\":2,\"key3\":3}]"; - JSONArray jsonArray = new JSONArray(str); - String expectedStr = str; - StringWriter stringWriter = new StringWriter(); - try { - jsonArray.write(stringWriter); - String actualStr = stringWriter.toString(); - JSONArray finalArray = new JSONArray(actualStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, finalArray); - assertTrue("write() expected " + expectedStr + - " but found " + actualStr, - actualStr.startsWith("[\"value1\",\"value2\",{") - && actualStr.contains("\"key1\":1") - && actualStr.contains("\"key2\":2") - && actualStr.contains("\"key3\":3") - ); - } finally { - stringWriter.close(); - } - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Exercise the JSONArray write() method using Appendable. - */ -/* - @Test - public void writeAppendable() { - String str = "[\"value1\",\"value2\",{\"key1\":1,\"key2\":2,\"key3\":3}]"; - JSONArray jsonArray = new JSONArray(str); - String expectedStr = str; - StringBuilder stringBuilder = new StringBuilder(); - Appendable appendable = jsonArray.write(stringBuilder); - String actualStr = appendable.toString(); - assertTrue("write() expected " + expectedStr + - " but found " + actualStr, - expectedStr.equals(actualStr)); - } -*/ - - /** - * Exercise the JSONArray write(Writer, int, int) method - */ - @Test - public void write3Param() throws IOException { - String str0 = "[\"value1\",\"value2\",{\"key1\":1,\"key2\":false,\"key3\":3.14}]"; - JSONArray jsonArray = new JSONArray(str0); - String expectedStr = str0; - StringWriter stringWriter = new StringWriter(); - try { - String actualStr = jsonArray.write(stringWriter, 0, 0).toString(); - JSONArray finalArray = new JSONArray(actualStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, finalArray); - assertTrue("write() expected " + expectedStr + - " but found " + actualStr, - actualStr.startsWith("[\"value1\",\"value2\",{") - && actualStr.contains("\"key1\":1") - && actualStr.contains("\"key2\":false") - && actualStr.contains("\"key3\":3.14") - ); - } finally { - stringWriter.close(); - } - - stringWriter = new StringWriter(); - try { - String actualStr = jsonArray.write(stringWriter, 2, 1).toString(); - JSONArray finalArray = new JSONArray(actualStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, finalArray); - assertTrue("write() expected " + expectedStr + - " but found " + actualStr, - actualStr.startsWith("[\n" + - " \"value1\",\n" + - " \"value2\",\n" + - " {") - && actualStr.contains("\"key1\": 1") - && actualStr.contains("\"key2\": false") - && actualStr.contains("\"key3\": 3.14") - ); - Util.checkJSONArrayMaps(finalArray); - } finally { - stringWriter.close(); - } - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Exercise the JSONArray write(Appendable, int, int) method - */ -/* - @Test - public void write3ParamAppendable() { - String str0 = "[\"value1\",\"value2\",{\"key1\":1,\"key2\":false,\"key3\":3.14}]"; - String str2 = - "[\n" + - " \"value1\",\n" + - " \"value2\",\n" + - " {\n" + - " \"key1\": 1,\n" + - " \"key2\": false,\n" + - " \"key3\": 3.14\n" + - " }\n" + - " ]"; - JSONArray jsonArray = new JSONArray(str0); - String expectedStr = str0; - StringBuilder stringBuilder = new StringBuilder(); - Appendable appendable = jsonArray.write(stringBuilder, 0, 0); - String actualStr = appendable.toString(); - assertEquals(expectedStr, actualStr); - - expectedStr = str2; - stringBuilder = new StringBuilder(); - appendable = jsonArray.write(stringBuilder, 2, 1); - actualStr = appendable.toString(); - assertEquals(expectedStr, actualStr); - } -*/ - - /** - * Exercise JSONArray toString() method with various indent levels. - */ - @Test - public void toList() { - String jsonArrayStr = - "[" + - "[1,2," + - "{\"key3\":true}" + - "]," + - "{\"key1\":\"val1\",\"key2\":" + - "{\"key2\":null}," + - "\"key3\":42,\"key4\":[]" + - "}," + - "[" + - "[\"value1\",2.1]" + - "," + - "[null]" + - "]" + - "]"; - - JSONArray jsonArray = new JSONArray(jsonArrayStr); - List list = jsonArray.toList(); - - assertTrue("List should not be null", list != null); - assertTrue("List should have 3 elements", list.size() == 3); - - List val1List = (List) list.get(0); - assertTrue("val1 should not be null", val1List != null); - assertTrue("val1 should have 3 elements", val1List.size() == 3); - - assertTrue("val1 value 1 should be 1", val1List.get(0).equals(Integer.valueOf(1))); - assertTrue("val1 value 2 should be 2", val1List.get(1).equals(Integer.valueOf(2))); - - Map key1Value3Map = (Map)val1List.get(2); - assertTrue("Map should not be null", key1Value3Map != null); - assertTrue("Map should have 1 element", key1Value3Map.size() == 1); - assertTrue("Map key3 should be true", key1Value3Map.get("key3").equals(Boolean.TRUE)); - - Map val2Map = (Map) list.get(1); - assertTrue("val2 should not be null", val2Map != null); - assertTrue("val2 should have 4 elements", val2Map.size() == 4); - assertTrue("val2 map key 1 should be val1", val2Map.get("key1").equals("val1")); - assertTrue("val2 map key 3 should be 42", val2Map.get("key3").equals(Integer.valueOf(42))); - - Map val2Key2Map = (Map)val2Map.get("key2"); - assertTrue("val2 map key 2 should not be null", val2Key2Map != null); - assertTrue("val2 map key 2 should have an entry", val2Key2Map.containsKey("key2")); - assertTrue("val2 map key 2 value should be null", val2Key2Map.get("key2") == null); - - List val2Key4List = (List)val2Map.get("key4"); - assertTrue("val2 map key 4 should not be null", val2Key4List != null); - assertTrue("val2 map key 4 should be empty", val2Key4List.isEmpty()); - - List val3List = (List) list.get(2); - assertTrue("val3 should not be null", val3List != null); - assertTrue("val3 should have 2 elements", val3List.size() == 2); - - List val3Val1List = (List)val3List.get(0); - assertTrue("val3 list val 1 should not be null", val3Val1List != null); - assertTrue("val3 list val 1 should have 2 elements", val3Val1List.size() == 2); - assertTrue("val3 list val 1 list element 1 should be value1", val3Val1List.get(0).equals("value1")); - assertTrue("val3 list val 1 list element 2 should be 2.1", val3Val1List.get(1).equals(new BigDecimal("2.1"))); - - List val3Val2List = (List)val3List.get(1); - assertTrue("val3 list val 2 should not be null", val3Val2List != null); - assertTrue("val3 list val 2 should have 1 element", val3Val2List.size() == 1); - assertTrue("val3 list val 2 list element 1 should be null", val3Val2List.get(0) == null); - - // assert that toList() is a deep copy - jsonArray.getJSONObject(1).put("key1", "still val1"); - assertTrue("val2 map key 1 should be val1", val2Map.get("key1").equals("val1")); - - // assert that the new list is mutable - assertTrue("Removing an entry should succeed", list.remove(2) != null); - assertTrue("List should have 2 elements", list.size() == 2); - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Create a JSONArray with specified initial capacity. - * Expects an exception if the initial capacity is specified as a negative integer - */ - @Test - public void testJSONArrayInt() { - assertNotNull(new JSONArray(0)); - assertNotNull(new JSONArray(5)); - // Check Size -> Even though the capacity of the JSONArray can be specified using a positive - // integer but the length of JSONArray always reflects upon the items added into it. - // assertEquals(0l, new JSONArray(10).length()); - try { - assertNotNull("Should throw an exception", new JSONArray(-1)); - } catch (JSONException e) { - assertEquals("Expected an exception message", - "JSONArray initial capacity cannot be negative.", - e.getMessage()); - } - } - - /** - * Verifies that the object constructor can properly handle any supported collection object. - */ - @Test - @SuppressWarnings({ "unchecked", "boxing" }) - public void testObjectConstructor() { - // should copy the array - Object o = new Object[] {2, "test2", true}; - JSONArray a = new JSONArray(o); - assertNotNull("Should not error", a); - assertEquals("length", 3, a.length()); - - // should NOT copy the collection - // this is required for backwards compatibility - o = new ArrayList(); - ((Collection)o).add(1); - ((Collection)o).add("test"); - ((Collection)o).add(false); - try { - JSONArray a0 = new JSONArray(o); - assertNull("Should error", a0); - } catch (JSONException ex) { - } - - // should NOT copy the JSONArray - // this is required for backwards compatibility - o = a; - try { - JSONArray a1 = new JSONArray(o); - assertNull("Should error", a1); - } catch (JSONException ex) { - } - Util.checkJSONArrayMaps(a); - } - - /** - * Verifies that the JSONArray constructor properly copies the original. - */ - @Test - public void testJSONArrayConstructor() { - // should copy the array - JSONArray a1 = new JSONArray("[2, \"test2\", true]"); - JSONArray a2 = new JSONArray(a1); - assertNotNull("Should not error", a2); - assertEquals("length", a1.length(), a2.length()); - - for(int i = 0; i < a1.length(); i++) { - assertEquals("index " + i + " are equal", a1.get(i), a2.get(i)); - } - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - a1, a2 - ))); - } - - /** - * Verifies that the object constructor can properly handle any supported collection object. - */ - @Test - public void testJSONArrayPutAll() { - // should copy the array - JSONArray a1 = new JSONArray("[2, \"test2\", true]"); - JSONArray a2 = new JSONArray(); - a2.putAll(a1); - assertNotNull("Should not error", a2); - assertEquals("length", a1.length(), a2.length()); - - for(int i = 0; i < a1.length(); i++) { - assertEquals("index " + i + " are equal", a1.get(i), a2.get(i)); - } - Util.checkJSONArraysMaps(new ArrayList(Arrays.asList( - a1, a2 - ))); - } - - /** - * Tests if calling JSONArray clear() method actually makes the JSONArray empty - */ - @Test(expected = JSONException.class) - public void jsonArrayClearMethodTest() { - //Adds random stuff to the JSONArray - JSONArray jsonArray = new JSONArray(); - jsonArray.put(123); - jsonArray.put("456"); - jsonArray.put(new JSONArray()); - jsonArray.clear(); //Clears the JSONArray - assertTrue("expected jsonArray.length() == 0", jsonArray.length() == 0); //Check if its length is 0 - jsonArray.getInt(0); //Should throws org.json.JSONException: JSONArray[0] not found - Util.checkJSONArrayMaps(jsonArray); - } - - /** - * Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654 - */ - @Ignore("This test relies on system constraints and may not always pass. See: https://github.com/stleary/JSON-java/issues/821") - @Test(expected = JSONException.class) - public void issue654StackOverflowInputWellFormed() { - //String input = new String(java.util.Base64.getDecoder().decode(base64Bytes)); - final InputStream resourceAsStream = JSONArrayTest.class.getClassLoader().getResourceAsStream("Issue654WellFormedArray.json"); - JSONTokener tokener = new JSONTokener(resourceAsStream); - JSONArray json_input = new JSONArray(tokener); - assertNotNull(json_input); - fail("Excepected Exception due to stack overflow."); - Util.checkJSONArrayMaps(json_input); - } - - @Test - public void testIssue682SimilarityOfJSONString() { - JSONArray ja1 = new JSONArray() - .put(new MyJsonString()) - .put(2); - JSONArray ja2 = new JSONArray() - .put(new MyJsonString()) - .put(2); - assertTrue(ja1.similar(ja2)); - - JSONArray ja3 = new JSONArray() - .put(new JSONString() { - @Override - public String toJSONString() { - return "\"different value\""; - } - }) - .put(2); - assertFalse(ja1.similar(ja3)); - } - - @Test(expected = JSONException.class) - public void testRecursiveDepth() { - HashMap map = new HashMap<>(); - map.put("t", map); - new JSONArray().put(map); - } - - @Test(expected = JSONException.class) - public void testRecursiveDepthAtPosition() { - HashMap map = new HashMap<>(); - map.put("t", map); - new JSONArray().put(0, map); - } - - @Test(expected = JSONException.class) - public void testRecursiveDepthArray() { - ArrayList array = new ArrayList<>(); - array.add(array); - new JSONArray(array); - } - - @Test - public void testRecursiveDepthAtPositionDefaultObject() { - HashMap map = JSONObjectTest.buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); - new JSONArray().put(0, map); - } - - @Test - public void testRecursiveDepthAtPosition1000Object() { - HashMap map = JSONObjectTest.buildNestedMap(1000); - new JSONArray().put(0, map, new JSONParserConfiguration().withMaxNestingDepth(1000)); - } - - @Test(expected = JSONException.class) - public void testRecursiveDepthAtPosition1001Object() { - HashMap map = JSONObjectTest.buildNestedMap(1001); - new JSONArray().put(0, map); - } - - @Test(expected = JSONException.class) - public void testRecursiveDepthArrayLimitedMaps() { - ArrayList array = new ArrayList<>(); - array.add(array); - new JSONArray(array); - } - - @Test - public void testRecursiveDepthArrayForDefaultLevels() { - ArrayList array = buildNestedArray(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); - new JSONArray(array, new JSONParserConfiguration()); - } - - @Test - public void testRecursiveDepthArrayFor1000Levels() { - try { - ArrayList array = buildNestedArray(1000); - JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000); - new JSONArray(array, parserConfiguration); - } catch (StackOverflowError e) { - String javaVersion = System.getProperty("java.version"); - if (javaVersion.startsWith("11.")) { - System.out.println( - "testRecursiveDepthArrayFor1000Levels() allowing intermittent stackoverflow, Java Version: " - + javaVersion); - } else { - String errorStr = "testRecursiveDepthArrayFor1000Levels() unexpected stackoverflow, Java Version: " - + javaVersion; - System.out.println(errorStr); - throw new RuntimeException(errorStr); - } - } - } - - @Test(expected = JSONException.class) - public void testRecursiveDepthArrayFor1001Levels() { - ArrayList array = buildNestedArray(1001); - new JSONArray(array); - } - - public static ArrayList buildNestedArray(int maxDepth) { - if (maxDepth <= 0) { - return new ArrayList<>(); - } - ArrayList nestedArray = new ArrayList<>(); - nestedArray.add(buildNestedArray(maxDepth - 1)); - return nestedArray; - } -} diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java deleted file mode 100644 index d3568401b..000000000 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ /dev/null @@ -1,1015 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.json.*; -import org.junit.Test; - -/** - * Tests for org.json.JSONML.java - * - * Certain inputs are expected to result in exceptions. These tests are - * executed first. JSONML provides an API to: - * Convert an XML string into a JSONArray or a JSONObject. - * Convert a JSONArray or JSONObject into an XML string. - * Both fromstring and tostring operations operations should be symmetrical - * within the limits of JSONML. - * It should be possible to perform the following operations, which should - * result in the original string being recovered, within the limits of the - * underlying classes: - * Convert a string -> JSONArray -> string -> JSONObject -> string - * Convert a string -> JSONObject -> string -> JSONArray -> string - * - */ -public class JSONMLTest { - - /** - * Attempts to transform a null XML string to JSON. - * Expects a NullPointerException - */ - @Test(expected=NullPointerException.class) - public void nullXMLException() { - String xmlStr = null; - JSONML.toJSONArray(xmlStr); - } - - /** - * Attempts to transform an empty string to JSON. - * Expects a JSONException - */ - @Test - public void emptyXMLException() { - String xmlStr = ""; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Bad XML at 0 [character 1 line 1]", - e.getMessage()); - } - } - - /** - * Attempts to call JSONML.toString() with a null JSONArray. - * Expects a NullPointerException. - */ - @Test(expected=NullPointerException.class) - public void nullJSONXMLException() { - /** - * Tries to convert a null JSONArray to XML. - */ - JSONArray jsonArray= null; - JSONML.toString(jsonArray); - } - - /** - * Attempts to call JSONML.toString() with a null JSONArray. - * Expects a JSONException. - */ - @Test - public void emptyJSONXMLException() { - /** - * Tries to convert an empty JSONArray to XML. - */ - JSONArray jsonArray = new JSONArray(); - try { - JSONML.toString(jsonArray); - assertTrue("Expecting an exception", false); - } catch (JSONException e) { - assertTrue("Expecting an exception message", - "JSONArray[0] not found.". - equals(e.getMessage())); - } - } - - /** - * Attempts to transform an non-XML string to JSON. - * Expects a JSONException - */ - @Test - public void nonXMLException() { - /** - * Attempts to transform a nonXML string to JSON - */ - String xmlStr = "{ \"this is\": \"not xml\"}"; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Bad XML at 23 [character 24 line 1]", - e.getMessage()); - } - } - - /** - * Attempts to transform a JSON document with XML content that - * does not follow JSONML conventions (element name is not first value - * in a nested JSONArray) to a JSONArray then back to string. - * Expects a JSONException - */ - @Test - public void emptyTagException() { - /** - * jsonArrayStr is used to build a JSONArray which is then - * turned into XML. For this transformation, all arrays represent - * elements and the first array entry is the name of the element. - * In this case, one of the arrays does not have a name - */ - String jsonArrayStr = - "[\"addresses\","+ - "{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+ - // this array has no name - "["+ - "[\"name\"],"+ - "[\"nocontent\"],"+ - "\">\""+ - "]"+ - "]"; - JSONArray jsonArray = new JSONArray(jsonArrayStr); - try { - JSONML.toString(jsonArray); - assertTrue("Expecting an exception", false); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONArray[0] is not a String (class org.json.JSONArray).", - e.getMessage()); - } - } - - /** - * Attempts to transform a JSON document with XML content that - * does not follow JSONML conventions (element tag has an embedded space) - * to a JSONArray then back to string. Expects a JSONException - */ - @Test - public void spaceInTagException() { - /** - * jsonArrayStr is used to build a JSONArray which is then - * turned into XML. For this transformation, all arrays represent - * elements and the first array entry is the name of the element. - * In this case, one of the element names has an embedded space, - * which is not allowed. - */ - String jsonArrayStr = - "[\"addresses\","+ - "{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+ - // this array has an invalid name - "[\"addr esses\","+ - "[\"name\"],"+ - "[\"nocontent\"],"+ - "\">\""+ - "]"+ - "]"; - JSONArray jsonArray = new JSONArray(jsonArrayStr); - try { - JSONML.toString(jsonArray); - assertTrue("Expecting an exception", false); - } catch (JSONException e) { - assertTrue("Expecting an exception message", - "'addr esses' contains a space character.". - equals(e.getMessage())); - } - } - - /** - * Attempts to transform a malformed XML document - * (element tag has a frontslash) to a JSONArray.\ - * Expects a JSONException - */ - @Test - public void invalidSlashInTagException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because the 'name' element - * contains an invalid frontslash. - */ - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " abc street\n"+ - "
\n"+ - "
"; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped tag at 176 [character 14 line 4]", - e.getMessage()); - } - } - - /** - * Malformed XML text (invalid tagname) is transformed into a JSONArray. - * Expects a JSONException. - */ - @Test - public void invalidBangInTagException() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - "
\n"+ - "
"; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 215 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Malformed XML text (invalid tagname, no close bracket) is transformed\ - * into a JSONArray. Expects a JSONException. - */ - @Test - public void invalidBangNoCloseInTagException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because an element - * starts with '!' and has no closing tag - */ - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 214 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Malformed XML text (tagname with no close bracket) is transformed\ - * into a JSONArray. Expects a JSONException. - */ - @Test - public void noCloseStartTagException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because an element - * has no closing '>'. - */ - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misplaced '<' at 194 [character 5 line 6]", - e.getMessage()); - } - } - - /** - * Malformed XML text (endtag with no name) is transformed\ - * into a JSONArray. Expects a JSONException. - */ - @Test - public void noCloseEndTagException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because an element - * has no name after the closing tag '\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - " \n"+ - ""; - try { - JSONML.toJSONArray(xmlStr); - assertTrue("Expecting an exception", false); - } catch (JSONException e) { - assertTrue("Expecting an exception message", - "Expected a closing name instead of '>'.". - equals(e.getMessage())); - } - } - - /** - * Malformed XML text (endtag with no close bracket) is transformed\ - * into a JSONArray. Expects a JSONException. - */ - @Test - public void noCloseEndBraceException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because an element - * has '>' after the closing tag '\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - " "; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misplaced '<' at 206 [character 1 line 7]", - e.getMessage()); - } - } - - /** - * Malformed XML text (incomplete CDATA string) is transformed\ - * into a JSONArray. Expects a JSONException. - */ - @Test - public void invalidCDATABangInTagException() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * In this case, the XML is invalid because an element - * does not have a complete CDATA string. - */ - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Joe Tester\n"+ - " \n"+ - "
\n"+ - "
"; - try { - JSONML.toJSONArray(xmlStr); - fail("Expecting an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected 'CDATA[' at 204 [character 11 line 5]", - e.getMessage()); - } - } - - /** - * Convert an XML document into a JSONArray, then use JSONML.toString() - * to convert it into a string. This string is then converted back into - * a JSONArray. Both JSONArrays are compared against a control to - * confirm the contents. - */ - @Test - public void toJSONArray() { - /** - * xmlStr contains XML text which is transformed into a JSONArray. - * Each element becomes a JSONArray: - * 1st entry = elementname - * 2nd entry = attributes object (if present) - * 3rd entry = content (if present) - * 4th entry = child element JSONArrays (if present) - * The result is compared against an expected JSONArray. - * The transformed JSONArray is then transformed back into a string - * which is used to create a final JSONArray, which is also compared - * against the expected JSONArray. - */ - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - "myName\n"+ - ">\n"+ - "
\n"+ - "
"; - String expectedStr = - "[\"addresses\","+ - "{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+ - "[\"address\","+ - "{\"attr1\":\"attrValue1\",\"attr2\":\"attrValue2\",\"attr3\":\"attrValue3\"},"+ - "[\"name\", {\"nameType\":\"mine\"},\"myName\"],"+ - "[\"nocontent\"],"+ - "\">\""+ - "]"+ - "]"; - JSONArray jsonArray = JSONML.toJSONArray(xmlStr); - JSONArray expectedJsonArray = new JSONArray(expectedStr); - String xmlToStr = JSONML.toString(jsonArray); - JSONArray finalJsonArray = JSONML.toJSONArray(xmlToStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray); - } - - /** - * Convert an XML document into a JSONObject. Use JSONML.toString() to - * convert it back into a string, and then re-convert it into a JSONObject. - * Both JSONObjects are compared against a control JSONObject to confirm - * the contents. - *

- * Next convert the XML document into a JSONArray. Use JSONML.toString() to - * convert it back into a string, and then re-convert it into a JSONArray. - * Both JSONArrays are compared against a control JSONArray to confirm - * the contents. - *

- * This test gives a comprehensive example of how the JSONML - * transformations work. - */ - @Test - public void toJSONObjectToJSONArray() { - /** - * xmlStr contains XML text which is transformed into a JSONObject, - * restored to XML, transformed into a JSONArray, and then restored - * to XML again. Both JSONObject and JSONArray should contain the same - * information and should produce the same XML, allowing for non-ordered - * attributes. - * - * Transformation to JSONObject: - * The elementName is stored as a string where key="tagName" - * Attributes are simply stored as key/value pairs - * If the element has either content or child elements, they are stored - * in a jsonArray with key="childNodes". - * - * Transformation to JSONArray: - * 1st entry = elementname - * 2nd entry = attributes object (if present) - * 3rd entry = content (if present) - * 4th entry = child element JSONArrays (if present) - */ - String xmlStr = - "\n"+ - "\n"+ - "

\n"+ - "Joe Tester\n"+ - "\n"+ - "\n"+ - "true\n"+ - "false\n"+ - "null\n"+ - "42\n"+ - "-23\n"+ - "-23.45\n"+ - "-23x.45\n"+ - "\n"+ - "1\n"+ - "2\n"+ - "abc\n"+ - "3\n"+ - "4.1\n"+ - "5.2\n"+ - "\n"+ - "
\n"+ - ""; - - String expectedJSONObjectStr = - "{"+ - "\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"childNodes\":["+ - "{"+ - "\"childNodes\":["+ - "{"+ - "\"childNodes\":[\"Joe Tester\"],"+ - "\"nameType\":\"my name\","+ - "\"tagName\":\"name\""+ - "},"+ - "{"+ - "\"childNodes\":[\"Baker street 5\"],"+ - "\"tagName\":\"street\""+ - "},"+ - "{"+ - "\"tagName\":\"NothingHere\","+ - "\"except\":\"an attribute\""+ - "},"+ - "{"+ - "\"childNodes\":[true],"+ - "\"tagName\":\"TrueValue\""+ - "},"+ - "{"+ - "\"childNodes\":[false],"+ - "\"tagName\":\"FalseValue\""+ - "},"+ - "{"+ - "\"childNodes\":[null],"+ - "\"tagName\":\"NullValue\""+ - "},"+ - "{"+ - "\"childNodes\":[42],"+ - "\"tagName\":\"PositiveValue\""+ - "},"+ - "{"+ - "\"childNodes\":[-23],"+ - "\"tagName\":\"NegativeValue\""+ - "},"+ - "{"+ - "\"childNodes\":[-23.45],"+ - "\"tagName\":\"DoubleValue\""+ - "},"+ - "{"+ - "\"childNodes\":[\"-23x.45\"],"+ - "\"tagName\":\"Nan\""+ - "},"+ - "{"+ - "\"childNodes\":["+ - "{"+ - "\"childNodes\":[1],"+ - "\"tagName\":\"value\""+ - "},"+ - "{"+ - "\"childNodes\":[2],"+ - "\"tagName\":\"value\""+ - "},"+ - "{"+ - "\"childNodes\":["+ - "{"+ - "\"childNodes\":[\"abc\"],"+ - "\"svAttr\":\"svValue\","+ - "\"tagName\":\"subValue\""+ - "}"+ - "],"+ - "\"tagName\":\"value\""+ - "},"+ - "{"+ - "\"childNodes\":[3],"+ - "\"tagName\":\"value\""+ - "},"+ - "{"+ - "\"childNodes\":[4.1],"+ - "\"tagName\":\"value\""+ - "},"+ - "{"+ - "\"childNodes\":[5.2],"+ - "\"tagName\":\"value\""+ - "}"+ - "],"+ - "\"tagName\":\"ArrayOfNum\""+ - "}"+ - "],"+ - "\"addrType\":\"my address\","+ - "\"tagName\":\"address\""+ - "}"+ - "],"+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+ - "\"tagName\":\"addresses\""+ - "}"; - - String expectedJSONArrayStr = - "["+ - "\"addresses\","+ - "{"+ - "\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\""+ - "},"+ - "["+ - "\"address\","+ - "{"+ - "\"addrType\":\"my address\""+ - "},"+ - "["+ - "\"name\","+ - "{"+ - "\"nameType\":\"my name\""+ - "},"+ - "\"Joe Tester\""+ - "],"+ - "[\"street\",\"Baker street 5\"],"+ - "["+ - "\"NothingHere\","+ - "{\"except\":\"an attribute\"}"+ - "],"+ - "[\"TrueValue\",true],"+ - "[\"FalseValue\",false],"+ - "[\"NullValue\",null],"+ - "[\"PositiveValue\",42],"+ - "[\"NegativeValue\",-23],"+ - "[\"DoubleValue\",-23.45],"+ - "[\"Nan\",\"-23x.45\"],"+ - "["+ - "\"ArrayOfNum\","+ - "[\"value\",1],"+ - "[\"value\",2],"+ - "[\"value\","+ - "["+ - "\"subValue\","+ - "{\"svAttr\":\"svValue\"},"+ - "\"abc\""+ - "],"+ - "],"+ - "[\"value\",3],"+ - "[\"value\",4.1],"+ - "[\"value\",5.2]"+ - "]"+ - "]"+ - "]"; - - // make a JSONObject and make sure it looks as expected - JSONObject jsonObject = JSONML.toJSONObject(xmlStr); - JSONObject expectedJsonObject = new JSONObject(expectedJSONObjectStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - - // restore the XML, then make another JSONObject and make sure it - // looks as expected - String jsonObjectXmlToStr = JSONML.toString(jsonObject); - JSONObject finalJsonObject = JSONML.toJSONObject(jsonObjectXmlToStr); - Util.compareActualVsExpectedJsonObjects(finalJsonObject, expectedJsonObject); - - // create a JSON array from the original string and make sure it - // looks as expected - JSONArray jsonArray = JSONML.toJSONArray(xmlStr); - - // restore the XML, then make another JSONArray and make sure it - // looks as expected - String jsonArrayXmlToStr = JSONML.toString(jsonArray); - - // lastly, confirm the restored JSONObject XML and JSONArray XML look - // reasonably similar - JSONObject jsonObjectFromObject = JSONML.toJSONObject(jsonObjectXmlToStr); - JSONObject jsonObjectFromArray = JSONML.toJSONObject(jsonArrayXmlToStr); - Util.compareActualVsExpectedJsonObjects(jsonObjectFromObject, jsonObjectFromArray); - } - - @Test - public void givenXmlStr_testToJSONArray_shouldEqualExpectedArray() throws IOException { - try (Stream jsonLines = Files.lines( - Paths.get("src/test/resources/JSONArrayExpectedTestCaseForToJsonArrayTest.json")); - Stream xmlLines = Files.lines(Paths.get("src/test/resources/XmlTestCaseTestToJsonArray.xml"))) { - - String xmlStr = xmlLines.collect(Collectors.joining()); - String expectedJSONArrayStr = jsonLines.collect(Collectors.joining()); - - JSONArray jsonArray = JSONML.toJSONArray(xmlStr); - JSONArray expectedJsonArray = new JSONArray(expectedJSONArrayStr); - - assertEquals(expectedJsonArray.toString(), jsonArray.toString()); - //TODO Util.compareActualVsExpectedJsonArrays can be replaced with above assertEquals(expectedJsonArray.toString(), jsonArray.toString()) - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - - String jsonArrayXmlToStr = JSONML.toString(jsonArray); - - JSONArray finalJsonArray = JSONML.toJSONArray(jsonArrayXmlToStr); - - //TODO Util.compareActualVsExpectedJsonArrays can be replaced with assertEquals(expectedJsonArray.toString(), finalJsonArray.toString()) - Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray); - } - } - - /** - * Convert an XML document which contains embedded comments into - * a JSONArray. Use JSONML.toString() to turn it into a string, then - * reconvert it into a JSONArray. Compare both JSONArrays to a control - * JSONArray to confirm the contents. - *

- * This test shows how XML comments are handled. - */ - @Test - public void commentsInXML() { - - String xmlStr = - "\n"+ - "\n"+ - "\n"+ - "

\n"+ - "\n"+ - "Joe Tester\n"+ - "\n"+ - "Baker street 5\n"+ - "
\n"+ - ""; - String expectedStr = - "[\"addresses\","+ - "[\"address\","+ - "[\"name\",\"Joe Tester\"],"+ - "[\"street\",\"Baker street 5\"]"+ - "]"+ - "]"; - JSONArray jsonArray = JSONML.toJSONArray(xmlStr); - JSONArray expectedJsonArray = new JSONArray(expectedStr); - String xmlToStr = JSONML.toString(jsonArray); - JSONArray finalJsonArray = JSONML.toJSONArray(xmlToStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray); - } - - /** - * JSON string with lost leading zero and converted "True" to true. See test - * result in comment below. - */ - @Test - public void testToJSONArray_jsonOutput() { - final String originalXml = "011000True"; - final String expectedJsonString = "[\"root\",[\"id\",\"01\"],[\"id\",1],[\"id\",\"00\"],[\"id\",0],[\"item\",{\"id\":\"01\"}],[\"title\",true]]"; - final JSONArray actualJsonOutput = JSONML.toJSONArray(originalXml, false); - assertEquals(expectedJsonString, actualJsonOutput.toString()); - } - - /** - * JSON string cannot be reverted to original xml when type guessing is used. - */ - @Test - public void testToJSONArray_reversibility() { - final String originalXml = "011000True"; - final String revertedXml = JSONML.toString(JSONML.toJSONArray(originalXml, false)); - assertNotEquals(revertedXml, originalXml); - } - - /** - * JSON string cannot be reverted to original xml when type guessing is used. - * When we force all the values as string, the original text comes back. - */ - @Test - public void testToJSONArray_reversibility2() { - final String originalXml = "011000True"; - final String expectedJsonString = "[\"root\",[\"id\",\"01\"],[\"id\",\"1\"],[\"id\",\"00\"],[\"id\",\"0\"],[\"item\",{\"id\":\"01\"}],[\"title\",\"True\"]]"; - final JSONArray json = JSONML.toJSONArray(originalXml,true); - assertEquals(expectedJsonString, json.toString()); - - final String reverseXml = JSONML.toString(json); - assertEquals(originalXml, reverseXml); - } - - /** - * JSON can be reverted to original xml. - */ - @Test - public void testToJSONArray_reversibility3() { - final String originalXml = "400402"; - final JSONArray jsonArray = JSONML.toJSONArray(originalXml, false); - final String revertedXml = JSONML.toString(jsonArray); - assertEquals(revertedXml, originalXml); - } - - /** - * JSON string cannot be reverted to original xml. See test result in - * comment below. - */ - @Test - public void testToJSONObject_reversibility() { - final String originalXml = "400402"; - final JSONObject originalObject=JSONML.toJSONObject(originalXml,false); - final String originalJson = originalObject.toString(); - final String xml = JSONML.toString(originalObject); - final JSONObject revertedObject = JSONML.toJSONObject(xml, false); - final String newJson = revertedObject.toString(); - assertTrue("JSON Objects are not similar", originalObject.similar(revertedObject)); - assertTrue("JSON Strings are not similar", new JSONObject(originalJson).similar(new JSONObject(newJson))); - } - -// these tests do not pass for the following reasons: -// 1. Our XML parser does not handle generic HTML entities, only valid XML entities. Hence   -// or other HTML specific entities would fail on reversability -// 2. Our JSON implementation for storing the XML attributes uses the standard unordered map. -// This means that can not be reversed reliably. -// -// /** -// * Test texts taken from jsonml.org. Currently our implementation FAILS this conversion but shouldn't. -// * Technically JsonML should be able to transform any valid xhtml document, but ours only supports -// * standard XML entities, not HTML entities. -// */ -// @Test -// public void testAttributeConversionReversabilityHTML() { -// final String originalXml = "
#5D28D1Example text here
#AF44EF127310656
#AAD034 © 
"; -// final String expectedJsonString = "[\"table\",{\"class\" : \"MyTable\",\"style\" : \"background-color:yellow\"},[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#550758\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:red\"},\"Example text here\"]],[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#993101\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:green\"},\"127624015\"]],[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#E33D87\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:blue\"},\"\u00A0\",[\"span\",{ \"style\" : \"background-color:maroon\" },\"\u00A9\"],\"\u00A0\"]]]"; -// final JSONArray json = JSONML.toJSONArray(originalXml,true); -// final String actualJsonString = json.toString(); -// -// final String reverseXml = JSONML.toString(json); -// assertNotEquals(originalXml, reverseXml); -// -// assertNotEquals(expectedJsonString, actualJsonString); -// } -// -// /** -// * Test texts taken from jsonml.org but modified to have XML entities only. -// */ -// @Test -// public void testAttributeConversionReversabilityXML() { -// final String originalXml = "
#5D28D1Example text here
#AF44EF127310656
#AAD034&><
"; -// final String expectedJsonString = "[\"table\",{\"class\" : \"MyTable\",\"style\" : \"background-color:yellow\"},[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#550758\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:red\"},\"Example text here\"]],[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#993101\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:green\"},\"127624015\"]],[\"tr\",[\"td\",{\"class\" : \"MyTD\",\"style\" : \"border:1px solid black\"},\"#E33D87\"],[\"td\",{\"class\" : \"MyTD\",\"style\" : \"background-color:blue\"},\"&\",[\"span\",{ \"style\" : \"background-color:maroon\" },\">\"],\"<\"]]]"; -// final JSONArray jsonML = JSONML.toJSONArray(originalXml,true); -// final String actualJsonString = jsonML.toString(); -// -// final String reverseXml = JSONML.toString(jsonML); -// // currently not equal because the hashing of the attribute objects makes the attribute -// // order not happen the same way twice -// assertEquals(originalXml, reverseXml); -// -// assertEquals(expectedJsonString, actualJsonString); -// } - - @Test (timeout = 6000) - public void testIssue484InfinteLoop1() { - try { - JSONML.toJSONObject("??*^M??|?CglR^F??`??>?w??PIlr^E??D^X^]?$?-^R?o??O?*??{OD?^FY??`2a????NM?b^Tq?:O?>S$^K?J?^FB.gUK?m^H??zE??^??!v]?^A???^[^A??^U?c??????h???s???g^Z???`?q^Dbi??:^QZl?)?}1^??k?0??:$V?$?Ovs(}J??^V????2;^QgQ?^_^A?^D?^U?Tg?K?`?h%c?hmGA??w??PIlr??D?$?-?o??O?*??{OD?Y??`2a????NM?bq?:O?>S$ ?J?B.gUK?m\b??zE???!v]???????c??????h???s???g???`?qbi??:Zl?)?}1^??k?0??:$V?$?Ovs(}J??????2;gQ????Tg?K?`?h%c?hmGA?"); - - final int maxNestingDepth = 42; - - try { - JSONML.toJSONArray(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - - @Test - public void testToJSONArrayMaxNestingDepthIsRespectedWithValidXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 1; - - try { - JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - @Test - public void testToJSONArrayMaxNestingDepthWithValidFittingXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 3; - - try { - JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - } catch (JSONException e) { - e.printStackTrace(); - fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " + - "parameter of the JSONMLParserConfiguration used"); - } - } - - - @Test - public void testToJSONObjectMaxDefaultNestingDepthIsRespected() { - final String wayTooLongMalformedXML = new String(new char[6000]).replace("\0", ""); - - try { - JSONML.toJSONObject(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + JSONMLParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH)); - } - } - - @Test - public void testToJSONObjectUnlimitedNestingDepthIsPossible() { - int actualDepth = JSONMLParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH +10; - final String deeperThanDefaultMax = new String(new char[actualDepth]).replace("\0", "") + - "value" + - new String(new char[actualDepth]).replace("\0", ""); - - try { - JSONML.toJSONObject(deeperThanDefaultMax, JSONMLParserConfiguration.ORIGINAL - .withMaxNestingDepth(JSONMLParserConfiguration.UNDEFINED_MAXIMUM_NESTING_DEPTH)); - } catch (JSONException e) { - e.printStackTrace(); - fail("XML document should be parsed beyond the default maximum depth if maxNestingDepth " + - "parameter is set to -1 in JSONMLParserConfiguration"); - } - } - - - @Test - public void testToJSONObjectMaxNestingDepthOf42IsRespected() { - final String wayTooLongMalformedXML = new String(new char[6000]).replace("\0", ""); - - final int maxNestingDepth = 42; - - try { - JSONML.toJSONObject(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - @Test - public void testToJSONObjectMaxNestingDepthIsRespectedWithValidXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 1; - - try { - JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - @Test - public void testToJSONObjectMaxNestingDepthWithValidFittingXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 3; - - try { - JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - } catch (JSONException e) { - e.printStackTrace(); - fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " + - "parameter of the JSONMLParserConfiguration used"); - } - } - -} diff --git a/src/test/java/org/json/junit/JSONObjectLocaleTest.java b/src/test/java/org/json/junit/JSONObjectLocaleTest.java deleted file mode 100755 index 1cdaf743d..000000000 --- a/src/test/java/org/json/junit/JSONObjectLocaleTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import java.util.*; - -import org.json.*; -import org.json.junit.data.MyLocaleBean; -import org.junit.*; - -/** - * Note: This file is saved as UTF-8. Do not save as ASCII or the tests will - * fail. - * - */ -public class JSONObjectLocaleTest { - /** - * JSONObject built from a bean with locale-specific keys. - * In the Turkish alphabet, there are 2 versions of the letter "i". - * 'eh' I ı (dotless i) - * 'ee' İ i (dotted i) - * A problem can occur when parsing the public get methods for a bean. - * If the method starts with getI... then the key name will be lowercased - * to 'i' in English, and 'ı' in Turkish. - * We want the keys to be consistent regardless of locale, so JSON-Java - * lowercase operations are made to be locale-neutral by specifying - * Locale.ROOT. This causes 'I' to be universally lowercased to 'i' - * regardless of the locale currently in effect. - */ - @Test - public void jsonObjectByLocaleBean() { - - MyLocaleBean myLocaleBean = new MyLocaleBean(); - - /** - * This is just the control case which happens when the locale.ROOT - * lowercasing behavior is the same as the current locale. - */ - Locale.setDefault(new Locale("en")); - JSONObject jsonen = new JSONObject(myLocaleBean); - assertEquals("expected size 2, found: " +jsonen.length(), 2, jsonen.length()); - assertEquals("expected jsonen[i] == beanI", "beanI", jsonen.getString("i")); - assertEquals("expected jsonen[id] == beanId", "beanId", jsonen.getString("id")); - - /** - * Without the JSON-Java change, these keys would be stored internally as - * starting with the letter, 'ı' (dotless i), since the lowercasing of - * the getI and getId keys would be specific to the Turkish locale. - */ - Locale.setDefault(new Locale("tr")); - JSONObject jsontr = new JSONObject(myLocaleBean); - assertEquals("expected size 2, found: " +jsontr.length(), 2, jsontr.length()); - assertEquals("expected jsontr[i] == beanI", "beanI", jsontr.getString("i")); - assertEquals("expected jsontr[id] == beanId", "beanId", jsontr.getString("id")); - } -} diff --git a/src/test/java/org/json/junit/JSONObjectNumberTest.java b/src/test/java/org/json/junit/JSONObjectNumberTest.java deleted file mode 100644 index 739de838f..000000000 --- a/src/test/java/org/json/junit/JSONObjectNumberTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.json.junit; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collection; - -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(value = Parameterized.class) -public class JSONObjectNumberTest { - private final String objectString; - private Integer value = 50; - - @Parameters(name = "{index}: {0}") - public static Collection data() { - return Arrays.asList(new Object[][]{ - {"{\"value\":50}", 1}, - {"{\"value\":50.0}", 1}, - {"{\"value\":5e1}", 1}, - {"{\"value\":5E1}", 1}, - {"{\"value\":5e1}", 1}, - {"{\"value\":\"50\"}", 1}, - {"{\"value\":-50}", -1}, - {"{\"value\":-50.0}", -1}, - {"{\"value\":-5e1}", -1}, - {"{\"value\":-5E1}", -1}, - {"{\"value\":-5e1}", -1}, - {"{\"value\":\"-50\"}", -1} - // JSON does not support octal or hex numbers; - // see https://stackoverflow.com/a/52671839/6323312 - // "{\"value\":062}", // octal 50 - // "{\"value\":0x32}" // hex 50 - }); - } - - public JSONObjectNumberTest(String objectString, int resultIsNegative) { - this.objectString = objectString; - this.value *= resultIsNegative; - } - - private JSONObject object; - - @Before - public void setJsonObject() { - object = new JSONObject(objectString); - } - - @Test - public void testGetNumber() { - assertEquals(value.intValue(), object.getNumber("value").intValue()); - } - - @Test - public void testGetBigDecimal() { - assertTrue(BigDecimal.valueOf(value).compareTo(object.getBigDecimal("value")) == 0); - } - - @Test - public void testGetBigInteger() { - assertEquals(BigInteger.valueOf(value), object.getBigInteger("value")); - } - - @Test - public void testGetFloat() { - assertEquals(value.floatValue(), object.getFloat("value"), 0.0f); - } - - @Test - public void testGetDouble() { - assertEquals(value.doubleValue(), object.getDouble("value"), 0.0d); - } - - @Test - public void testGetInt() { - assertEquals(value.intValue(), object.getInt("value")); - } - - @Test - public void testGetLong() { - assertEquals(value.longValue(), object.getLong("value")); - } - - @Test - public void testOptNumber() { - assertEquals(value.intValue(), object.optNumber("value").intValue()); - } - - @Test - public void testOptBigDecimal() { - assertTrue(BigDecimal.valueOf(value).compareTo(object.optBigDecimal("value", null)) == 0); - } - - @Test - public void testOptBigInteger() { - assertEquals(BigInteger.valueOf(value), object.optBigInteger("value", null)); - } - - @Test - public void testOptFloat() { - assertEquals(value.floatValue(), object.optFloat("value"), 0.0f); - } - - @Test - public void testOptFloatObject() { - assertEquals((Float) value.floatValue(), object.optFloatObject("value"), 0.0f); - } - - @Test - public void testOptDouble() { - assertEquals(value.doubleValue(), object.optDouble("value"), 0.0d); - } - - @Test - public void testOptDoubleObject() { - assertEquals((Double) value.doubleValue(), object.optDoubleObject("value"), 0.0d); - } - - @Test - public void testOptInt() { - assertEquals(value.intValue(), object.optInt("value")); - } - - @Test - public void testOptIntegerObject() { - assertEquals((Integer) value.intValue(), object.optIntegerObject("value")); - } - - @Test - public void testOptLong() { - assertEquals(value.longValue(), object.optLong("value")); - } - - @Test - public void testOptLongObject() { - assertEquals((Long) value.longValue(), object.optLongObject("value")); - } -} diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java deleted file mode 100644 index d32a2db68..000000000 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ /dev/null @@ -1,3864 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.regex.Pattern; - -import org.json.CDL; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONPointerException; -import org.json.JSONParserConfiguration; -import org.json.JSONString; -import org.json.JSONTokener; -import org.json.ParserConfiguration; -import org.json.XML; -import org.json.junit.data.BrokenToString; -import org.json.junit.data.ExceptionalBean; -import org.json.junit.data.Fraction; -import org.json.junit.data.GenericBean; -import org.json.junit.data.GenericBeanInt; -import org.json.junit.data.MyBean; -import org.json.junit.data.MyBeanCustomName; -import org.json.junit.data.MyBeanCustomNameSubClass; -import org.json.junit.data.MyBigNumberBean; -import org.json.junit.data.MyEnum; -import org.json.junit.data.MyEnumField; -import org.json.junit.data.MyJsonString; -import org.json.junit.data.MyNumber; -import org.json.junit.data.MyNumberContainer; -import org.json.junit.data.MyPublicClass; -import org.json.junit.data.RecursiveBean; -import org.json.junit.data.RecursiveBeanEquals; -import org.json.junit.data.Singleton; -import org.json.junit.data.SingletonEnum; -import org.json.junit.data.WeirdList; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; - -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.JsonPath; - -/** - * JSONObject, along with JSONArray, are the central classes of the reference app. - * All of the other classes interact with them, and JSON functionality would - * otherwise be impossible. - */ -public class JSONObjectTest { - - /** - * Regular Expression Pattern that matches JSON Numbers. This is primarily used for - * output to guarantee that we are always writing valid JSON. - */ - static final Pattern NUMBER_PATTERN = Pattern.compile("-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?"); - - @After - public void tearDown() { - SingletonEnum.getInstance().setSomeInt(0); - SingletonEnum.getInstance().setSomeString(null); - Singleton.getInstance().setSomeInt(0); - Singleton.getInstance().setSomeString(null); - } - - /** - * Tests that the similar method is working as expected. - */ - @Test - public void verifySimilar() { - final String string1 = "HasSameRef"; - final String string2 = "HasDifferentRef"; - JSONObject obj1 = new JSONObject() - .put("key1", "abc") - .put("key2", 2) - .put("key3", string1); - - JSONObject obj2 = new JSONObject() - .put("key1", "abc") - .put("key2", 3) - .put("key3", string1); - - JSONObject obj3 = new JSONObject() - .put("key1", "abc") - .put("key2", 2) - .put("key3", new String(string1)); - - JSONObject obj4 = new JSONObject() - .put("key1", "abc") - .put("key2", 2.0) - .put("key3", new String(string1)); - - JSONObject obj5 = new JSONObject() - .put("key1", "abc") - .put("key2", 2.0) - .put("key3", new String(string2)); - - assertFalse("obj1-obj2 Should eval to false", obj1.similar(obj2)); - assertTrue("obj1-obj3 Should eval to true", obj1.similar(obj3)); - assertTrue("obj1-obj4 Should eval to true", obj1.similar(obj4)); - assertFalse("obj1-obj5 Should eval to false", obj1.similar(obj5)); - // verify that a double and big decimal are "similar" - assertTrue("should eval to true",new JSONObject().put("a",1.1d).similar(new JSONObject("{\"a\":1.1}"))); - // Confirm #618 is fixed (compare should not exit early if similar numbers are found) - // Note that this test may not work if the JSONObject map entry order changes - JSONObject first = new JSONObject("{\"a\": 1, \"b\": 2, \"c\": 3}"); - JSONObject second = new JSONObject("{\"a\": 1, \"b\": 2.0, \"c\": 4}"); - assertFalse("first-second should eval to false", first.similar(second)); - List jsonObjects = new ArrayList( - Arrays.asList(obj1, obj2, obj3, obj4, obj5) - ); - Util.checkJSONObjectsMaps(jsonObjects); - } - - @Test - public void timeNumberParsing() { - // test data to use - final String[] testData = new String[] { - null, - "", - "100", - "-100", - "abc123", - "012345", - "100.5e199", - "-100.5e199", - "DEADBEEF", - "0xDEADBEEF", - "1234567890.1234567890", - "-1234567890.1234567890", - "adloghakuidghauiehgauioehgdkjfb nsruoh aeu noerty384 nkljfgh " - + "395h tdfn kdz8yt3 4hkls gn.ey85 4hzfhnz.o8y5a84 onvklt " - + "yh389thub nkz8y49lihv al4itlaithknty8hnbl" - // long (in length) number sequences with invalid data at the end of the - // string offer very poor performance for the REGEX. - ,"123467890123467890123467890123467890123467890123467890123467" - + "8901234678901234678901234678901234678901234678901234678" - + "9012346789012346789012346789012346789012346789012346789" - + "0a" - }; - final int testDataLength = testData.length; - /** - * Changed to 1000 for faster test runs - */ - // final int iterations = 1000000; - final int iterations = 1000; - - // 10 million iterations 1,000,000 * 10 (currently 100,000) - long startTime = System.nanoTime(); - for(int i = 0; i < iterations; i++) { - for(int j = 0; j < testDataLength; j++) { - try { - BigDecimal v1 = new BigDecimal(testData[j]); - v1.signum(); - } catch(Exception ignore) { - //do nothing - } - } - } - final long elapsedNano1 = System.nanoTime() - startTime; - System.out.println("new BigDecimal(testData[]) : " + elapsedNano1 / 1000000 + " ms"); - - startTime = System.nanoTime(); - for(int i = 0; i < iterations; i++) { - for(int j = 0; j < testDataLength; j++) { - try { - boolean v2 = NUMBER_PATTERN.matcher(testData[j]).matches(); - assert v2 == !!v2; - } catch(Exception ignore) { - //do nothing - } - } - } - final long elapsedNano2 = System.nanoTime() - startTime; - System.out.println("NUMBER_PATTERN.matcher(testData[]).matches() : " + elapsedNano2 / 1000000 + " ms"); - // don't assert normally as the testing is machine dependent. - // assertTrue("Expected Pattern matching to be faster than BigDecimal constructor",elapsedNano2)(JsonPath.read(doc, "$"))).size() == 4); - assertTrue("expected \"falseKey\":false", Boolean.FALSE.equals(jsonObjectByName.query("/falseKey"))); - assertTrue("expected \"nullKey\":null", JSONObject.NULL.equals(jsonObjectByName.query("/nullKey"))); - assertTrue("expected \"stringKey\":\"hello world!\"", "hello world!".equals(jsonObjectByName.query("/stringKey"))); - assertTrue("expected \"doubleKey\":-23.45e67", new BigDecimal("-23.45e67").equals(jsonObjectByName.query("/doubleKey"))); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList(jsonObject, jsonObjectByName))); - } - - /** - * JSONObjects can be built from a Map. - * In this test the map is null. - * the JSONObject(JsonTokener) ctor is not tested directly since it already - * has full coverage from other tests. - */ - @Test - public void jsonObjectByNullMap() { - Map map = null; - JSONObject jsonObject = new JSONObject(map); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * JSONObjects can be built from a Map. - * In this test all of the map entries are valid JSON types. - */ - @Test - public void jsonObjectByMap() { - Map map = new HashMap(); - map.put("trueKey", Boolean.valueOf(true)); - map.put("falseKey", Boolean.valueOf(false)); - map.put("stringKey", "hello world!"); - map.put("escapeStringKey", "h\be\tllo w\u1234orld!"); - map.put("intKey", Long.valueOf(42)); - map.put("doubleKey", Double.valueOf(-23.45e67)); - JSONObject jsonObject = new JSONObject(map); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected \"trueKey\":true", Boolean.TRUE.equals(jsonObject.query("/trueKey"))); - assertTrue("expected \"falseKey\":false", Boolean.FALSE.equals(jsonObject.query("/falseKey"))); - assertTrue("expected \"stringKey\":\"hello world!\"", "hello world!".equals(jsonObject.query("/stringKey"))); - assertTrue("expected \"escapeStringKey\":\"h\be\tllo w\u1234orld!\"", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/escapeStringKey"))); - assertTrue("expected \"doubleKey\":-23.45e67", Double.valueOf("-23.45e67").equals(jsonObject.query("/doubleKey"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Verifies that the constructor has backwards compatability with RAW types pre-java5. - */ - @Test - public void verifyConstructor() { - - final JSONObject expected = new JSONObject("{\"myKey\":10}"); - - @SuppressWarnings("rawtypes") - Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10)); - JSONObject jaRaw = new JSONObject(myRawC); - - Map myCStrObj = Collections.singletonMap("myKey", - (Object) Integer.valueOf(10)); - JSONObject jaStrObj = new JSONObject(myCStrObj); - - Map myCStrInt = Collections.singletonMap("myKey", - Integer.valueOf(10)); - JSONObject jaStrInt = new JSONObject(myCStrInt); - - Map myCObjObj = Collections.singletonMap((Object) "myKey", - (Object) Integer.valueOf(10)); - JSONObject jaObjObj = new JSONObject(myCObjObj); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrObj)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrInt)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObjObj)); - Util.checkJSONObjectsMaps(new ArrayList( - Arrays.asList(jaRaw, jaStrObj, jaStrInt, jaObjObj)) - ); - } - - /** - * Tests Number serialization. - */ - @Test - public void verifyNumberOutput(){ - /** - * MyNumberContainer is a POJO, so call JSONObject(bean), - * which builds a map of getter names/values - * The only getter is getMyNumber (key=myNumber), - * whose return value is MyNumber. MyNumber extends Number, - * but is not recognized as such by wrap() per current - * implementation, so wrap() returns the default new JSONObject(bean). - * The only getter is getNumber (key=number), whose return value is - * BigDecimal(42). - */ - JSONObject jsonObject0 = new JSONObject(new MyNumberContainer()); - String actual = jsonObject0.toString(); - String expected = "{\"myNumber\":{\"number\":42}}"; - assertEquals("Equal", expected , actual); - - /** - * JSONObject.put() handles objects differently than the - * bean constructor. Where the bean ctor wraps objects before - * placing them in the map, put() inserts the object without wrapping. - * In this case, a MyNumber instance is the value. - * The MyNumber.toString() method is responsible for - * returning a reasonable value: the string '42'. - */ - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("myNumber", new MyNumber()); - actual = jsonObject1.toString(); - expected = "{\"myNumber\":42}"; - assertEquals("Equal", expected , actual); - - /** - * Calls the JSONObject(Map) ctor, which calls wrap() for values. - * AtomicInteger is a Number, but is not recognized by wrap(), per - * current implementation. However, the type is - * 'java.util.concurrent.atomic', so due to the 'java' prefix, - * wrap() inserts the value as a string. That is why 42 comes back - * wrapped in quotes. - */ - JSONObject jsonObject2 = new JSONObject(Collections.singletonMap("myNumber", new AtomicInteger(42))); - actual = jsonObject2.toString(); - expected = "{\"myNumber\":\"42\"}"; - assertEquals("Equal", expected , actual); - - /** - * JSONObject.put() inserts the AtomicInteger directly into the - * map not calling wrap(). In toString()->write()->writeValue(), - * AtomicInteger is recognized as a Number, and converted via - * numberToString() into the unquoted string '42'. - */ - JSONObject jsonObject3 = new JSONObject(); - jsonObject3.put("myNumber", new AtomicInteger(42)); - actual = jsonObject3.toString(); - expected = "{\"myNumber\":42}"; - assertEquals("Equal", expected , actual); - - /** - * Calls the JSONObject(Map) ctor, which calls wrap() for values. - * Fraction is a Number, but is not recognized by wrap(), per - * current implementation. As a POJO, Fraction is handled as a - * bean and inserted into a contained JSONObject. It has 2 getters, - * for numerator and denominator. - */ - JSONObject jsonObject4 = new JSONObject(Collections.singletonMap("myNumber", new Fraction(4,2))); - assertEquals(1, jsonObject4.length()); - assertEquals(2, ((JSONObject)(jsonObject4.get("myNumber"))).length()); - assertEquals("Numerator", BigInteger.valueOf(4) , jsonObject4.query("/myNumber/numerator")); - assertEquals("Denominator", BigInteger.valueOf(2) , jsonObject4.query("/myNumber/denominator")); - - /** - * JSONObject.put() inserts the Fraction directly into the - * map not calling wrap(). In toString()->write()->writeValue(), - * Fraction is recognized as a Number, and converted via - * numberToString() into the unquoted string '4/2'. But the - * BigDecimal sanity check fails, so writeValue() defaults - * to returning a safe JSON quoted string. Pretty slick! - */ - JSONObject jsonObject5 = new JSONObject(); - jsonObject5.put("myNumber", new Fraction(4,2)); - actual = jsonObject5.toString(); - expected = "{\"myNumber\":\"4/2\"}"; // valid JSON, bug fixed - assertEquals("Equal", expected , actual); - - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject0, jsonObject1, jsonObject2, jsonObject3, jsonObject4, jsonObject5 - ))); - } - - /** - * Verifies that the put Collection has backwards compatibility with RAW types pre-java5. - */ - @Test - public void verifyPutCollection() { - - final JSONObject expected = new JSONObject("{\"myCollection\":[10]}"); - - @SuppressWarnings("rawtypes") - Collection myRawC = Collections.singleton(Integer.valueOf(10)); - JSONObject jaRaw = new JSONObject(); - jaRaw.put("myCollection", myRawC); - - Collection myCObj = Collections.singleton((Object) Integer - .valueOf(10)); - JSONObject jaObj = new JSONObject(); - jaObj.put("myCollection", myCObj); - - Collection myCInt = Collections.singleton(Integer - .valueOf(10)); - JSONObject jaInt = new JSONObject(); - jaInt.put("myCollection", myCInt); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObj)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaInt)); - - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jaRaw, jaObj, jaInt - ))); - } - - - /** - * Verifies that the put Map has backwards compatibility with RAW types pre-java5. - */ - @Test - public void verifyPutMap() { - - final JSONObject expected = new JSONObject("{\"myMap\":{\"myKey\":10}}"); - - @SuppressWarnings("rawtypes") - Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10)); - JSONObject jaRaw = new JSONObject(); - jaRaw.put("myMap", myRawC); - - Map myCStrObj = Collections.singletonMap("myKey", - (Object) Integer.valueOf(10)); - JSONObject jaStrObj = new JSONObject(); - jaStrObj.put("myMap", myCStrObj); - - Map myCStrInt = Collections.singletonMap("myKey", - Integer.valueOf(10)); - JSONObject jaStrInt = new JSONObject(); - jaStrInt.put("myMap", myCStrInt); - - Map myCObjObj = Collections.singletonMap((Object) "myKey", - (Object) Integer.valueOf(10)); - JSONObject jaObjObj = new JSONObject(); - jaObjObj.put("myMap", myCObjObj); - - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaRaw)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrObj)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaStrInt)); - assertTrue( - "The RAW Collection should give me the same as the Typed Collection", - expected.similar(jaObjObj)); - - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jaRaw, jaStrObj, jaStrInt, jaStrObj - ))); - } - - - /** - * JSONObjects can be built from a Map. - * In this test the map entries are not valid JSON types. - * The actual conversion is kind of interesting. - */ - @Test - public void jsonObjectByMapWithUnsupportedValues() { - Map jsonMap = new HashMap(); - // Just insert some random objects - jsonMap.put("key1", new CDL()); - jsonMap.put("key2", new Exception()); - - JSONObject jsonObject = new JSONObject(jsonMap); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected 0 key1 items", ((Map)(JsonPath.read(doc, "$.key1"))).size() == 0); - assertTrue("expected \"key2\":java.lang.Exception","java.lang.Exception".equals(jsonObject.query("/key2"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * JSONObjects can be built from a Map. - * In this test one of the map values is null - */ - @Test - public void jsonObjectByMapWithNullValue() { - Map map = new HashMap(); - map.put("trueKey", Boolean.valueOf(true)); - map.put("falseKey", Boolean.valueOf(false)); - map.put("stringKey", "hello world!"); - map.put("nullKey", null); - map.put("escapeStringKey", "h\be\tllo w\u1234orld!"); - map.put("intKey", Long.valueOf(42)); - map.put("doubleKey", Double.valueOf(-23.45e67)); - JSONObject jsonObject = new JSONObject(map); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected \"trueKey\":true", Boolean.TRUE.equals(jsonObject.query("/trueKey"))); - assertTrue("expected \"falseKey\":false", Boolean.FALSE.equals(jsonObject.query("/falseKey"))); - assertTrue("expected \"stringKey\":\"hello world!\"", "hello world!".equals(jsonObject.query("/stringKey"))); - assertTrue("expected \"escapeStringKey\":\"h\be\tllo w\u1234orld!\"", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/escapeStringKey"))); - assertTrue("expected \"intKey\":42", Long.valueOf("42").equals(jsonObject.query("/intKey"))); - assertTrue("expected \"doubleKey\":-23.45e67", Double.valueOf("-23.45e67").equals(jsonObject.query("/doubleKey"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * JSONObject built from a bean. In this case all but one of the - * bean getters return valid JSON types - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectByBean1() { - /** - * Default access classes have to be mocked since JSONObject, which is - * not in the same package, cannot call MyBean methods by reflection. - */ - MyBean myBean = mock(MyBean.class); - when(myBean.getDoubleKey()).thenReturn(-23.45e7); - when(myBean.getIntKey()).thenReturn(42); - when(myBean.getStringKey()).thenReturn("hello world!"); - when(myBean.getEscapeStringKey()).thenReturn("h\be\tllo w\u1234orld!"); - when(myBean.isTrueKey()).thenReturn(true); - when(myBean.isFalseKey()).thenReturn(false); - when(myBean.getStringReaderKey()).thenReturn( - new StringReader("") { - }); - - JSONObject jsonObject = new JSONObject(myBean); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 8 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 8); - assertTrue("expected 0 items in stringReaderKey", ((Map) (JsonPath.read(doc, "$.stringReaderKey"))).size() == 0); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/trueKey"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/falseKey"))); - assertTrue("expected hello world!","hello world!".equals(jsonObject.query("/stringKey"))); - assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/escapeStringKey"))); - assertTrue("expected 42", Integer.valueOf("42").equals(jsonObject.query("/intKey"))); - assertTrue("expected -23.45e7", Double.valueOf("-23.45e7").equals(jsonObject.query("/doubleKey"))); - // sorry, mockito artifact - assertTrue("expected 2 mockitoInterceptor items", ((Map)(JsonPath.read(doc, "$.mockitoInterceptor"))).size() == 2); - assertTrue("expected 0 mockitoInterceptor.serializationSupport items", - ((Map)(JsonPath.read(doc, "$.mockitoInterceptor.serializationSupport"))).size() == 0); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * JSONObject built from a bean that has custom field names. - */ - @Test - public void jsonObjectByBean2() { - JSONObject jsonObject = new JSONObject(new MyBeanCustomName()); - assertNotNull(jsonObject); - assertEquals("Wrong number of keys found:", - 5, - jsonObject.keySet().size()); - assertFalse("Normal field name (someString) processing did not work", - jsonObject.has("someString")); - assertFalse("Normal field name (myDouble) processing did not work", - jsonObject.has("myDouble")); - assertFalse("Normal field name (someFloat) processing did not work", - jsonObject.has("someFloat")); - assertFalse("Ignored field not found!", - jsonObject.has("ignoredInt")); - // getSomeInt() has no user-defined annotation - assertTrue("Normal field name (someInt) should have been found", - jsonObject.has("someInt")); - // the user-defined annotation does not replace any value, so someLong should be found - assertTrue("Normal field name (someLong) should have been found", - jsonObject.has("someLong")); - // myStringField replaces someString property name via user-defined annotation - assertTrue("Overridden String field name (myStringField) should have been found", - jsonObject.has("myStringField")); - // weird name replaces myDouble property name via user-defined annotation - assertTrue("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) should have been found", - jsonObject.has("Some Weird NAme that Normally Wouldn't be possible!")); - // InterfaceField replaces someFloat property name via user-defined annotation - assertTrue("Overridden String field name (InterfaceField) should have been found", - jsonObject.has("InterfaceField")); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * JSONObject built from a bean that has custom field names inherited from a parent class. - */ - @Test - public void jsonObjectByBean3() { - JSONObject jsonObject = new JSONObject(new MyBeanCustomNameSubClass()); - assertNotNull(jsonObject); - assertEquals("Wrong number of keys found:", - 7, - jsonObject.keySet().size()); - assertFalse("Normal int field name (someInt) found, but was overridden", - jsonObject.has("someInt")); - assertFalse("Normal field name (myDouble) processing did not work", - jsonObject.has("myDouble")); - // myDouble was replaced by weird name, and then replaced again by AMoreNormalName via user-defined annotation - assertFalse("Overridden String field name (Some Weird NAme that Normally Wouldn't be possible!) should not be FOUND!", - jsonObject.has("Some Weird NAme that Normally Wouldn't be possible!")); - assertFalse("Normal field name (someFloat) found, but was overridden", - jsonObject.has("someFloat")); - assertFalse("Ignored field found! but was overridden", - jsonObject.has("ignoredInt")); - // shouldNotBeJSON property name was first ignored, then replaced by ShouldBeIgnored via user-defined annotations - assertFalse("Ignored field at the same level as forced name should not have been found", - jsonObject.has("ShouldBeIgnored")); - // able property name was replaced by Getable via user-defined annotation - assertFalse("Normally ignored field (able) with explicit property name should not have been found", - jsonObject.has("able")); - // property name someInt was replaced by newIntFieldName via user-defined annotation - assertTrue("Overridden int field name (newIntFieldName) should have been found", - jsonObject.has("newIntFieldName")); - // property name someLong was not replaced via user-defined annotation - assertTrue("Normal field name (someLong) should have been found", - jsonObject.has("someLong")); - // property name someString was replaced by myStringField via user-defined annotation - assertTrue("Overridden String field name (myStringField) should have been found", - jsonObject.has("myStringField")); - // property name myDouble was replaced by a weird name, followed by AMoreNormalName via user-defined annotations - assertTrue("Overridden double field name (AMoreNormalName) should have been found", - jsonObject.has("AMoreNormalName")); - // property name someFloat was replaced by InterfaceField via user-defined annotation - assertTrue("Overridden String field name (InterfaceField) should have been found", - jsonObject.has("InterfaceField")); - // property name ignoredInt was replaced by none, followed by forcedInt via user-defined annotations - assertTrue("Forced field should have been found!", - jsonObject.has("forcedInt")); - // property name able was replaced by Getable via user-defined annotation - assertTrue("Overridden boolean field name (Getable) should have been found", - jsonObject.has("Getable")); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * A bean is also an object. But in order to test the JSONObject - * ctor that takes an object and a list of names, - * this particular bean needs some public - * data members, which have been added to the class. - */ - @Test - public void jsonObjectByObjectAndNames() { - String[] keys = {"publicString", "publicInt"}; - // just need a class that has public data members - MyPublicClass myPublicClass = new MyPublicClass(); - JSONObject jsonObject = new JSONObject(myPublicClass, keys); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected \"publicString\":\"abc\"", "abc".equals(jsonObject.query("/publicString"))); - assertTrue("expected \"publicInt\":42", Integer.valueOf(42).equals(jsonObject.query("/publicInt"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise the JSONObject from resource bundle functionality. - * The test resource bundle is uncomplicated, but provides adequate test coverage. - */ - @Test - public void jsonObjectByResourceBundle() { - JSONObject jsonObject = new - JSONObject("org.json.junit.data.StringsResourceBundle", - Locale.getDefault()); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 2 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 2); - assertTrue("expected 2 greetings items", ((Map)(JsonPath.read(doc, "$.greetings"))).size() == 2); - assertTrue("expected \"hello\":\"Hello, \"", "Hello, ".equals(jsonObject.query("/greetings/hello"))); - assertTrue("expected \"world\":\"World!\"", "World!".equals(jsonObject.query("/greetings/world"))); - assertTrue("expected 2 farewells items", ((Map)(JsonPath.read(doc, "$.farewells"))).size() == 2); - assertTrue("expected \"later\":\"Later, \"", "Later, ".equals(jsonObject.query("/farewells/later"))); - assertTrue("expected \"world\":\"World!\"", "Alligator!".equals(jsonObject.query("/farewells/gator"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise the JSONObject.accumulate() method - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectAccumulate() { - - JSONObject jsonObject = new JSONObject(); - jsonObject.accumulate("myArray", true); - jsonObject.accumulate("myArray", false); - jsonObject.accumulate("myArray", "hello world!"); - jsonObject.accumulate("myArray", "h\be\tllo w\u1234orld!"); - jsonObject.accumulate("myArray", 42); - jsonObject.accumulate("myArray", -23.45e7); - // include an unsupported object for coverage - try { - jsonObject.accumulate("myArray", Double.NaN); - fail("Expected exception"); - } catch (JSONException ignored) {} - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 6 myArray items", ((List)(JsonPath.read(doc, "$.myArray"))).size() == 6); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/myArray/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/myArray/1"))); - assertTrue("expected hello world!", "hello world!".equals(jsonObject.query("/myArray/2"))); - assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/myArray/3"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonObject.query("/myArray/4"))); - assertTrue("expected -23.45e7", Double.valueOf(-23.45e7).equals(jsonObject.query("/myArray/5"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise the JSONObject append() functionality - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectAppend() { - JSONObject jsonObject = new JSONObject(); - jsonObject.append("myArray", true); - jsonObject.append("myArray", false); - jsonObject.append("myArray", "hello world!"); - jsonObject.append("myArray", "h\be\tllo w\u1234orld!"); - jsonObject.append("myArray", 42); - jsonObject.append("myArray", -23.45e7); - // include an unsupported object for coverage - try { - jsonObject.append("myArray", Double.NaN); - fail("Expected exception"); - } catch (JSONException ignored) {} - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 6 myArray items", ((List)(JsonPath.read(doc, "$.myArray"))).size() == 6); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/myArray/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/myArray/1"))); - assertTrue("expected hello world!", "hello world!".equals(jsonObject.query("/myArray/2"))); - assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/myArray/3"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonObject.query("/myArray/4"))); - assertTrue("expected -23.45e7", Double.valueOf(-23.45e7).equals(jsonObject.query("/myArray/5"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise the JSONObject doubleToString() method - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectDoubleToString() { - String [] expectedStrs = {"1", "1", "-23.4", "-2.345E68", "null", "null" }; - Double [] doubles = { 1.0, 00001.00000, -23.4, -23.45e67, - Double.NaN, Double.NEGATIVE_INFINITY }; - for (int i = 0; i < expectedStrs.length; ++i) { - String actualStr = JSONObject.doubleToString(doubles[i]); - assertTrue("value expected ["+expectedStrs[i]+ - "] found ["+actualStr+ "]", - expectedStrs[i].equals(actualStr)); - } - } - - /** - * Exercise some JSONObject get[type] and opt[type] methods - */ - @Test - public void jsonObjectValues() { - String str = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"trueStrKey\":\"true\","+ - "\"falseStrKey\":\"false\","+ - "\"stringKey\":\"hello world!\","+ - "\"intKey\":42,"+ - "\"intStrKey\":\"43\","+ - "\"longKey\":1234567890123456789,"+ - "\"longStrKey\":\"987654321098765432\","+ - "\"doubleKey\":-23.45e7,"+ - "\"doubleStrKey\":\"00001.000\","+ - "\"BigDecimalStrKey\":\"19007199254740993.35481234487103587486413587843213584\","+ - "\"negZeroKey\":-0.0,"+ - "\"negZeroStrKey\":\"-0.0\","+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\":{\"myKey\":\"myVal\"}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - assertTrue("trueKey should be true", jsonObject.getBoolean("trueKey")); - assertTrue("opt trueKey should be true", jsonObject.optBoolean("trueKey")); - assertTrue("opt trueKey should be true", jsonObject.optBooleanObject("trueKey")); - assertTrue("falseKey should be false", !jsonObject.getBoolean("falseKey")); - assertTrue("trueStrKey should be true", jsonObject.getBoolean("trueStrKey")); - assertTrue("trueStrKey should be true", jsonObject.optBoolean("trueStrKey")); - assertTrue("trueStrKey should be true", jsonObject.optBooleanObject("trueStrKey")); - assertTrue("falseStrKey should be false", !jsonObject.getBoolean("falseStrKey")); - assertTrue("stringKey should be string", - jsonObject.getString("stringKey").equals("hello world!")); - assertTrue("doubleKey should be double", - jsonObject.getDouble("doubleKey") == -23.45e7); - assertTrue("doubleStrKey should be double", - jsonObject.getDouble("doubleStrKey") == 1); - assertTrue("doubleKey can be float", - jsonObject.getFloat("doubleKey") == -23.45e7f); - assertTrue("doubleStrKey can be float", - jsonObject.getFloat("doubleStrKey") == 1f); - assertTrue("opt doubleKey should be double", - jsonObject.optDouble("doubleKey") == -23.45e7); - assertTrue("opt doubleKey with Default should be double", - jsonObject.optDouble("doubleStrKey", Double.NaN) == 1); - assertTrue("opt doubleKey should be Double", - Double.valueOf(-23.45e7).equals(jsonObject.optDoubleObject("doubleKey"))); - assertTrue("opt doubleKey with Default should be Double", - Double.valueOf(1).equals(jsonObject.optDoubleObject("doubleStrKey", Double.NaN))); - assertTrue("opt negZeroKey should be a Double", - jsonObject.opt("negZeroKey") instanceof Double); - assertTrue("get negZeroKey should be a Double", - jsonObject.get("negZeroKey") instanceof Double); - assertTrue("optNumber negZeroKey should return Double", - jsonObject.optNumber("negZeroKey") instanceof Double); - assertTrue("optNumber negZeroStrKey should return Double", - jsonObject.optNumber("negZeroStrKey") instanceof Double); - assertTrue("opt negZeroKey should be double", - Double.compare(jsonObject.optDouble("negZeroKey"), -0.0d) == 0); - assertTrue("opt negZeroStrKey with Default should be double", - Double.compare(jsonObject.optDouble("negZeroStrKey"), -0.0d) == 0); - assertTrue("opt negZeroKey should be Double", - Double.valueOf(-0.0d).equals(jsonObject.optDoubleObject("negZeroKey"))); - assertTrue("opt negZeroStrKey with Default should be Double", - Double.valueOf(-0.0d).equals(jsonObject.optDoubleObject("negZeroStrKey"))); - assertTrue("optNumber negZeroKey should be -0.0", - Double.compare(jsonObject.optNumber("negZeroKey").doubleValue(), -0.0d) == 0); - assertTrue("optNumber negZeroStrKey should be -0.0", - Double.compare(jsonObject.optNumber("negZeroStrKey").doubleValue(), -0.0d) == 0); - assertTrue("optFloat doubleKey should be float", - jsonObject.optFloat("doubleKey") == -23.45e7f); - assertTrue("optFloat doubleKey with Default should be float", - jsonObject.optFloat("doubleStrKey", Float.NaN) == 1f); - assertTrue("optFloat doubleKey should be Float", - Float.valueOf(-23.45e7f).equals(jsonObject.optFloatObject("doubleKey"))); - assertTrue("optFloat doubleKey with Default should be Float", - Float.valueOf(1f).equals(jsonObject.optFloatObject("doubleStrKey", Float.NaN))); - assertTrue("intKey should be int", - jsonObject.optInt("intKey") == 42); - assertTrue("opt intKey should be int", - jsonObject.optInt("intKey", 0) == 42); - assertTrue("intKey should be Integer", - Integer.valueOf(42).equals(jsonObject.optIntegerObject("intKey"))); - assertTrue("opt intKey should be Integer", - Integer.valueOf(42).equals(jsonObject.optIntegerObject("intKey", 0))); - assertTrue("opt intKey with default should be int", - jsonObject.getInt("intKey") == 42); - assertTrue("intStrKey should be int", - jsonObject.getInt("intStrKey") == 43); - assertTrue("longKey should be long", - jsonObject.getLong("longKey") == 1234567890123456789L); - assertTrue("opt longKey should be long", - jsonObject.optLong("longKey") == 1234567890123456789L); - assertTrue("opt longKey with default should be long", - jsonObject.optLong("longKey", 0) == 1234567890123456789L); - assertTrue("opt longKey should be Long", - Long.valueOf(1234567890123456789L).equals(jsonObject.optLongObject("longKey"))); - assertTrue("opt longKey with default should be Long", - Long.valueOf(1234567890123456789L).equals(jsonObject.optLongObject("longKey", 0L))); - assertTrue("longStrKey should be long", - jsonObject.getLong("longStrKey") == 987654321098765432L); - assertTrue("optNumber int should return Integer", - jsonObject.optNumber("intKey") instanceof Integer); - assertTrue("optNumber long should return Long", - jsonObject.optNumber("longKey") instanceof Long); - assertTrue("optNumber double should return BigDecimal", - jsonObject.optNumber("doubleKey") instanceof BigDecimal); - assertTrue("optNumber Str int should return Integer", - jsonObject.optNumber("intStrKey") instanceof Integer); - assertTrue("optNumber Str long should return Long", - jsonObject.optNumber("longStrKey") instanceof Long); - assertTrue("optNumber Str double should return BigDecimal", - jsonObject.optNumber("doubleStrKey") instanceof BigDecimal); - assertTrue("optNumber BigDecimalStrKey should return BigDecimal", - jsonObject.optNumber("BigDecimalStrKey") instanceof BigDecimal); - assertTrue("xKey should not exist", - jsonObject.isNull("xKey")); - assertTrue("stringKey should exist", - jsonObject.has("stringKey")); - assertTrue("opt stringKey should string", - jsonObject.optString("stringKey").equals("hello world!")); - assertTrue("opt stringKey with default should string", - jsonObject.optString("stringKey", "not found").equals("hello world!")); - JSONArray jsonArray = jsonObject.getJSONArray("arrayKey"); - assertTrue("arrayKey should be JSONArray", - jsonArray.getInt(0) == 0 && - jsonArray.getInt(1) == 1 && - jsonArray.getInt(2) == 2); - jsonArray = jsonObject.optJSONArray("arrayKey"); - assertTrue("opt arrayKey should be JSONArray", - jsonArray.getInt(0) == 0 && - jsonArray.getInt(1) == 1 && - jsonArray.getInt(2) == 2); - JSONObject jsonObjectInner = jsonObject.getJSONObject("objectKey"); - assertTrue("objectKey should be JSONObject", - jsonObjectInner.get("myKey").equals("myVal")); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Check whether JSONObject handles large or high precision numbers correctly - */ - @Test - public void stringToValueNumbersTest() { - assertTrue("-0 Should be a Double!",JSONObject.stringToValue("-0") instanceof Double); - assertTrue("-0.0 Should be a Double!",JSONObject.stringToValue("-0.0") instanceof Double); - assertTrue("'-' Should be a String!",JSONObject.stringToValue("-") instanceof String); - assertTrue( "0.2 should be a BigDecimal!", - JSONObject.stringToValue( "0.2" ) instanceof BigDecimal ); - assertTrue( "Doubles should be BigDecimal, even when incorrectly converting floats!", - JSONObject.stringToValue( Double.valueOf( "0.2f" ).toString() ) instanceof BigDecimal ); - /** - * This test documents a need for BigDecimal conversion. - */ - Object obj = JSONObject.stringToValue( "299792.457999999984" ); - assertTrue( "does not evaluate to 299792.457999999984 BigDecimal!", - obj.equals(new BigDecimal("299792.457999999984")) ); - assertTrue( "1 should be an Integer!", - JSONObject.stringToValue( "1" ) instanceof Integer ); - assertTrue( "Integer.MAX_VALUE should still be an Integer!", - JSONObject.stringToValue( Integer.valueOf( Integer.MAX_VALUE ).toString() ) instanceof Integer ); - assertTrue( "Large integers should be a Long!", - JSONObject.stringToValue( Long.valueOf(((long)Integer.MAX_VALUE) + 1 ) .toString() ) instanceof Long ); - assertTrue( "Long.MAX_VALUE should still be an Integer!", - JSONObject.stringToValue( Long.valueOf( Long.MAX_VALUE ).toString() ) instanceof Long ); - - String str = new BigInteger( Long.valueOf( Long.MAX_VALUE ).toString() ).add( BigInteger.ONE ).toString(); - assertTrue( "Really large integers currently evaluate to BigInteger", - JSONObject.stringToValue(str).equals(new BigInteger("9223372036854775808"))); - } - - /** - * This test documents numeric values which could be numerically - * handled as BigDecimal or BigInteger. It helps determine what outputs - * will change if those types are supported. - */ - @Test - public void jsonValidNumberValuesNeitherLongNorIEEE754Compatible() { - // Valid JSON Numbers, probably should return BigDecimal or BigInteger objects - String str = - "{"+ - "\"numberWithDecimals\":299792.457999999984,"+ - "\"largeNumber\":12345678901234567890,"+ - "\"preciseNumber\":0.2000000000000000111,"+ - "\"largeExponent\":-23.45e2327"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - // Comes back as a double, but loses precision - assertTrue( "numberWithDecimals currently evaluates to double 299792.458", - jsonObject.get( "numberWithDecimals" ).equals( new BigDecimal( "299792.457999999984" ) ) ); - Object obj = jsonObject.get( "largeNumber" ); - assertTrue("largeNumber currently evaluates to BigInteger", - new BigInteger("12345678901234567890").equals(obj)); - // comes back as a double but loses precision - assertEquals( "preciseNumber currently evaluates to double 0.2", - 0.2, jsonObject.getDouble( "preciseNumber" ), 0.0); - obj = jsonObject.get( "largeExponent" ); - assertTrue("largeExponent should evaluate as a BigDecimal", - new BigDecimal("-23.45e2327").equals(obj)); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * This test documents how JSON-Java handles invalid numeric input. - */ - // TODO: to be restored after strictMode parsing is fixed - @Ignore - public void jsonInvalidNumberValues() { - // Number-notations supported by Java and invalid as JSON - String str = - "{"+ - "\"hexNumber\":-0x123,"+ - "\"tooManyZeros\":00,"+ - "\"negativeInfinite\":-Infinity,"+ - "\"negativeNaN\":-NaN,"+ - "\"negativeFraction\":-.01,"+ - "\"tooManyZerosFraction\":00.001,"+ - "\"negativeHexFloat\":-0x1.fffp1,"+ - "\"hexFloat\":0x1.0P-1074,"+ - "\"floatIdentifier\":0.1f,"+ - "\"doubleIdentifier\":0.1d"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - Object obj; - obj = jsonObject.get( "hexNumber" ); - assertFalse( "hexNumber must not be a number (should throw exception!?)", - obj instanceof Number ); - assertTrue("hexNumber currently evaluates to string", - obj.equals("-0x123")); - assertTrue( "tooManyZeros currently evaluates to string", - jsonObject.get( "tooManyZeros" ).equals("00")); - obj = jsonObject.get("negativeInfinite"); - assertTrue( "negativeInfinite currently evaluates to string", - obj.equals("-Infinity")); - obj = jsonObject.get("negativeNaN"); - assertTrue( "negativeNaN currently evaluates to string", - obj.equals("-NaN")); - assertTrue( "negativeFraction currently evaluates to double -0.01", - jsonObject.get( "negativeFraction" ).equals(BigDecimal.valueOf(-0.01))); - assertTrue( "tooManyZerosFraction currently evaluates to double 0.001", - jsonObject.optLong( "tooManyZerosFraction" )==0); - assertTrue( "negativeHexFloat currently evaluates to double -3.99951171875", - jsonObject.get( "negativeHexFloat" ).equals(Double.valueOf(-3.99951171875))); - assertTrue("hexFloat currently evaluates to double 4.9E-324", - jsonObject.get("hexFloat").equals(Double.valueOf(4.9E-324))); - assertTrue("floatIdentifier currently evaluates to double 0.1", - jsonObject.get("floatIdentifier").equals(Double.valueOf(0.1))); - assertTrue("doubleIdentifier currently evaluates to double 0.1", - jsonObject.get("doubleIdentifier").equals(Double.valueOf(0.1))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Tests how JSONObject get[type] handles incorrect types - */ - @Test - public void jsonObjectNonAndWrongValues() { - String str = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"trueStrKey\":\"true\","+ - "\"falseStrKey\":\"false\","+ - "\"stringKey\":\"hello world!\","+ - "\"intKey\":42,"+ - "\"intStrKey\":\"43\","+ - "\"longKey\":1234567890123456789,"+ - "\"longStrKey\":\"987654321098765432\","+ - "\"doubleKey\":-23.45e7,"+ - "\"doubleStrKey\":\"00001.000\","+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\":{\"myKey\":\"myVal\"}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - try { - jsonObject.getBoolean("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("expecting an exception message", - "JSONObject[\"nonKey\"] not found.", e.getMessage()); - } - try { - jsonObject.getBoolean("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a Boolean (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getString("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getString("trueKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"trueKey\"] is not a string (class java.lang.Boolean : true).", - e.getMessage()); - } - try { - jsonObject.getDouble("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getDouble("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a double (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getFloat("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getFloat("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a float (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getInt("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getInt("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a int (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getLong("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getLong("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a long (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getJSONArray("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getJSONArray("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a JSONArray (class java.lang.String : hello world!).", - e.getMessage()); - } - try { - jsonObject.getJSONObject("nonKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"nonKey\"] not found.", - e.getMessage()); - } - try { - jsonObject.getJSONObject("stringKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"stringKey\"] is not a JSONObject (class java.lang.String : hello world!).", - e.getMessage()); - } - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * This test documents an unexpected numeric behavior. - * A double that ends with .0 is parsed, serialized, then - * parsed again. On the second parse, it has become an int. - */ - @Test - public void unexpectedDoubleToIntConversion() { - String key30 = "key30"; - String key31 = "key31"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put(key30, Double.valueOf(3.0)); - jsonObject.put(key31, Double.valueOf(3.1)); - - assertTrue("3.0 should remain a double", - jsonObject.getDouble(key30) == 3); - assertTrue("3.1 should remain a double", - jsonObject.getDouble(key31) == 3.1); - - // turns 3.0 into 3. - String serializedString = jsonObject.toString(); - JSONObject deserialized = new JSONObject(serializedString); - assertTrue("3.0 is now an int", deserialized.get(key30) instanceof Integer); - assertTrue("3.0 can still be interpreted as a double", - deserialized.getDouble(key30) == 3.0); - assertTrue("3.1 remains a double", deserialized.getDouble(key31) == 3.1); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Document behaviors of big numbers. Includes both JSONObject - * and JSONArray tests - */ - @SuppressWarnings("boxing") - @Test - public void bigNumberOperations() { - /** - * JSONObject tries to parse BigInteger as a bean, but it only has - * one getter, getLowestBitSet(). The value is lost and an unhelpful - * value is stored. This should be fixed. - */ - BigInteger bigInteger = new BigInteger("123456789012345678901234567890"); - JSONObject jsonObject0 = new JSONObject(bigInteger); - Object obj = jsonObject0.get("lowestSetBit"); - assertTrue("JSONObject only has 1 value", jsonObject0.length() == 1); - assertTrue("JSONObject parses BigInteger as the Integer lowestBitSet", - obj instanceof Integer); - assertTrue("this bigInteger lowestBitSet happens to be 1", - obj.equals(1)); - - /** - * JSONObject tries to parse BigDecimal as a bean, but it has - * no getters, The value is lost and no value is stored. - * This should be fixed. - */ - BigDecimal bigDecimal = new BigDecimal( - "123456789012345678901234567890.12345678901234567890123456789"); - JSONObject jsonObject1 = new JSONObject(bigDecimal); - assertTrue("large bigDecimal is not stored", jsonObject1.isEmpty()); - - /** - * JSONObject put(String, Object) method stores and serializes - * bigInt and bigDec correctly. Nothing needs to change. - */ - JSONObject jsonObject2 = new JSONObject(); - jsonObject2.put("bigInt", bigInteger); - assertTrue("jsonObject.put() handles bigInt correctly", - jsonObject2.get("bigInt").equals(bigInteger)); - assertTrue("jsonObject.getBigInteger() handles bigInt correctly", - jsonObject2.getBigInteger("bigInt").equals(bigInteger)); - assertTrue("jsonObject.optBigInteger() handles bigInt correctly", - jsonObject2.optBigInteger("bigInt", BigInteger.ONE).equals(bigInteger)); - assertTrue("jsonObject serializes bigInt correctly", - jsonObject2.toString().equals("{\"bigInt\":123456789012345678901234567890}")); - assertTrue("BigInteger as BigDecimal", - jsonObject2.getBigDecimal("bigInt").equals(new BigDecimal(bigInteger))); - - - JSONObject jsonObject3 = new JSONObject(); - jsonObject3.put("bigDec", bigDecimal); - assertTrue("jsonObject.put() handles bigDec correctly", - jsonObject3.get("bigDec").equals(bigDecimal)); - assertTrue("jsonObject.getBigDecimal() handles bigDec correctly", - jsonObject3.getBigDecimal("bigDec").equals(bigDecimal)); - assertTrue("jsonObject.optBigDecimal() handles bigDec correctly", - jsonObject3.optBigDecimal("bigDec", BigDecimal.ONE).equals(bigDecimal)); - assertTrue("jsonObject serializes bigDec correctly", - jsonObject3.toString().equals( - "{\"bigDec\":123456789012345678901234567890.12345678901234567890123456789}")); - - assertTrue("BigDecimal as BigInteger", - jsonObject3.getBigInteger("bigDec").equals(bigDecimal.toBigInteger())); - /** - * exercise some exceptions - */ - try { - // bigInt key does not exist - jsonObject3.getBigDecimal("bigInt"); - fail("expected an exeption"); - } catch (JSONException ignored) {} - obj = jsonObject3.optBigDecimal("bigInt", BigDecimal.ONE); - assertTrue("expected BigDecimal", obj.equals(BigDecimal.ONE)); - jsonObject3.put("stringKey", "abc"); - try { - jsonObject3.getBigDecimal("stringKey"); - fail("expected an exeption"); - } catch (JSONException ignored) {} - obj = jsonObject3.optBigInteger("bigDec", BigInteger.ONE); - assertTrue("expected BigInteger", obj instanceof BigInteger); - assertEquals(bigDecimal.toBigInteger(), obj); - - /** - * JSONObject.numberToString() works correctly, nothing to change. - */ - String str = JSONObject.numberToString(bigInteger); - assertTrue("numberToString() handles bigInteger correctly", - str.equals("123456789012345678901234567890")); - str = JSONObject.numberToString(bigDecimal); - assertTrue("numberToString() handles bigDecimal correctly", - str.equals("123456789012345678901234567890.12345678901234567890123456789")); - - /** - * JSONObject.stringToValue() turns bigInt into an accurate string, - * and rounds bigDec. This incorrect, but users may have come to - * expect this behavior. Change would be marginally better, but - * might inconvenience users. - */ - obj = JSONObject.stringToValue(bigInteger.toString()); - assertTrue("stringToValue() turns bigInteger string into Number", - obj instanceof Number); - obj = JSONObject.stringToValue(bigDecimal.toString()); - assertTrue("stringToValue() changes bigDecimal Number", - obj instanceof Number); - - /** - * wrap() vs put() big number behavior is now the same. - */ - // bigInt map ctor - Map map = new HashMap(); - map.put("bigInt", bigInteger); - JSONObject jsonObject4 = new JSONObject(map); - String actualFromMapStr = jsonObject4.toString(); - assertTrue("bigInt in map (or array or bean) is a string", - actualFromMapStr.equals( - "{\"bigInt\":123456789012345678901234567890}")); - // bigInt put - JSONObject jsonObject5 = new JSONObject(); - jsonObject5.put("bigInt", bigInteger); - String actualFromPutStr = jsonObject5.toString(); - assertTrue("bigInt from put is a number", - actualFromPutStr.equals( - "{\"bigInt\":123456789012345678901234567890}")); - // bigDec map ctor - map = new HashMap(); - map.put("bigDec", bigDecimal); - JSONObject jsonObject6 = new JSONObject(map); - actualFromMapStr = jsonObject6.toString(); - assertTrue("bigDec in map (or array or bean) is a bigDec", - actualFromMapStr.equals( - "{\"bigDec\":123456789012345678901234567890.12345678901234567890123456789}")); - // bigDec put - JSONObject jsonObject7 = new JSONObject(); - jsonObject7.put("bigDec", bigDecimal); - actualFromPutStr = jsonObject7.toString(); - assertTrue("bigDec from put is a number", - actualFromPutStr.equals( - "{\"bigDec\":123456789012345678901234567890.12345678901234567890123456789}")); - // bigInt,bigDec put - JSONArray jsonArray0 = new JSONArray(); - jsonArray0.put(bigInteger); - jsonArray0.put(bigDecimal); - actualFromPutStr = jsonArray0.toString(); - assertTrue("bigInt, bigDec from put is a number", - actualFromPutStr.equals( - "[123456789012345678901234567890,123456789012345678901234567890.12345678901234567890123456789]")); - assertTrue("getBigInt is bigInt", jsonArray0.getBigInteger(0).equals(bigInteger)); - assertTrue("getBigDec is bigDec", jsonArray0.getBigDecimal(1).equals(bigDecimal)); - assertTrue("optBigInt is bigInt", jsonArray0.optBigInteger(0, BigInteger.ONE).equals(bigInteger)); - assertTrue("optBigDec is bigDec", jsonArray0.optBigDecimal(1, BigDecimal.ONE).equals(bigDecimal)); - jsonArray0.put(Boolean.TRUE); - try { - jsonArray0.getBigInteger(2); - fail("should not be able to get big int"); - } catch (Exception ignored) {} - try { - jsonArray0.getBigDecimal(2); - fail("should not be able to get big dec"); - } catch (Exception ignored) {} - assertTrue("optBigInt is default", jsonArray0.optBigInteger(2, BigInteger.ONE).equals(BigInteger.ONE)); - assertTrue("optBigDec is default", jsonArray0.optBigDecimal(2, BigDecimal.ONE).equals(BigDecimal.ONE)); - - // bigInt,bigDec list ctor - List list = new ArrayList(); - list.add(bigInteger); - list.add(bigDecimal); - JSONArray jsonArray1 = new JSONArray(list); - String actualFromListStr = jsonArray1.toString(); - assertTrue("bigInt, bigDec in list is a bigInt, bigDec", - actualFromListStr.equals( - "[123456789012345678901234567890,123456789012345678901234567890.12345678901234567890123456789]")); - // bigInt bean ctor - MyBigNumberBean myBigNumberBean = mock(MyBigNumberBean.class); - when(myBigNumberBean.getBigInteger()).thenReturn(new BigInteger("123456789012345678901234567890")); - JSONObject jsonObject8 = new JSONObject(myBigNumberBean); - String actualFromBeanStr = jsonObject8.toString(); - // can't do a full string compare because mockery adds an extra key/value - assertTrue("bigInt from bean ctor is a bigInt", - actualFromBeanStr.contains("123456789012345678901234567890")); - // bigDec bean ctor - myBigNumberBean = mock(MyBigNumberBean.class); - when(myBigNumberBean.getBigDecimal()).thenReturn(new BigDecimal("123456789012345678901234567890.12345678901234567890123456789")); - jsonObject8 = new JSONObject(myBigNumberBean); - actualFromBeanStr = jsonObject8.toString(); - // can't do a full string compare because mockery adds an extra key/value - assertTrue("bigDec from bean ctor is a bigDec", - actualFromBeanStr.contains("123456789012345678901234567890.12345678901234567890123456789")); - // bigInt,bigDec wrap() - obj = JSONObject.wrap(bigInteger); - assertTrue("wrap() returns big num",obj.equals(bigInteger)); - obj = JSONObject.wrap(bigDecimal); - assertTrue("wrap() returns string",obj.equals(bigDecimal)); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject0, jsonObject1, jsonObject2, jsonObject3, jsonObject4, - jsonObject5, jsonObject6, jsonObject7, jsonObject8 - ))); - Util.checkJSONArrayMaps(jsonArray0, jsonObject0.getMapType()); - Util.checkJSONArrayMaps(jsonArray1, jsonObject0.getMapType()); - } - - /** - * The purpose for the static method getNames() methods are not clear. - * This method is not called from within JSON-Java. Most likely - * uses are to prep names arrays for: - * JSONObject(JSONObject jo, String[] names) - * JSONObject(Object object, String names[]), - */ - @Test - public void jsonObjectNames() { - - // getNames() from null JSONObject - assertTrue("null names from null Object", - null == JSONObject.getNames((Object)null)); - - // getNames() from object with no fields - assertTrue("null names from Object with no fields", - null == JSONObject.getNames(new MyJsonString())); - - // getNames from new JSONOjbect - JSONObject jsonObject0 = new JSONObject(); - String [] names = JSONObject.getNames(jsonObject0); - assertTrue("names should be null", names == null); - - - // getNames() from empty JSONObject - String emptyStr = "{}"; - JSONObject jsonObject1 = new JSONObject(emptyStr); - assertTrue("empty JSONObject should have null names", - null == JSONObject.getNames(jsonObject1)); - - // getNames() from JSONObject - String str = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"stringKey\":\"hello world!\","+ - "}"; - JSONObject jsonObject2 = new JSONObject(str); - names = JSONObject.getNames(jsonObject2); - JSONArray jsonArray0 = new JSONArray(names); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider() - .parse(jsonArray0.toString()); - List docList = JsonPath.read(doc, "$"); - assertTrue("expected 3 items", docList.size() == 3); - assertTrue( - "expected to find trueKey", - ((List) JsonPath.read(doc, "$[?(@=='trueKey')]")).size() == 1); - assertTrue( - "expected to find falseKey", - ((List) JsonPath.read(doc, "$[?(@=='falseKey')]")).size() == 1); - assertTrue( - "expected to find stringKey", - ((List) JsonPath.read(doc, "$[?(@=='stringKey')]")).size() == 1); - - /** - * getNames() from an enum with properties has an interesting result. - * It returns the enum values, not the selected enum properties - */ - MyEnumField myEnumField = MyEnumField.VAL1; - names = JSONObject.getNames(myEnumField); - - // validate JSON - JSONArray jsonArray1 = new JSONArray(names); - doc = Configuration.defaultConfiguration().jsonProvider() - .parse(jsonArray1.toString()); - docList = JsonPath.read(doc, "$"); - assertTrue("expected 3 items", docList.size() == 3); - assertTrue( - "expected to find VAL1", - ((List) JsonPath.read(doc, "$[?(@=='VAL1')]")).size() == 1); - assertTrue( - "expected to find VAL2", - ((List) JsonPath.read(doc, "$[?(@=='VAL2')]")).size() == 1); - assertTrue( - "expected to find VAL3", - ((List) JsonPath.read(doc, "$[?(@=='VAL3')]")).size() == 1); - - /** - * A bean is also an object. But in order to test the static - * method getNames(), this particular bean needs some public - * data members. - */ - MyPublicClass myPublicClass = new MyPublicClass(); - names = JSONObject.getNames(myPublicClass); - - // validate JSON - JSONArray jsonArray2 = new JSONArray(names); - doc = Configuration.defaultConfiguration().jsonProvider() - .parse(jsonArray2.toString()); - docList = JsonPath.read(doc, "$"); - assertTrue("expected 2 items", docList.size() == 2); - assertTrue( - "expected to find publicString", - ((List) JsonPath.read(doc, "$[?(@=='publicString')]")).size() == 1); - assertTrue( - "expected to find publicInt", - ((List) JsonPath.read(doc, "$[?(@=='publicInt')]")).size() == 1); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject0, jsonObject1, jsonObject2 - ))); - Util.checkJSONArrayMaps(jsonArray0, jsonObject0.getMapType()); - Util.checkJSONArrayMaps(jsonArray1, jsonObject0.getMapType()); - Util.checkJSONArrayMaps(jsonArray2, jsonObject0.getMapType()); - } - - /** - * Populate a JSONArray from an empty JSONObject names() method. - * It should be empty. - */ - @Test - public void emptyJsonObjectNamesToJsonAray() { - JSONObject jsonObject = new JSONObject(); - JSONArray jsonArray = jsonObject.names(); - assertTrue("jsonArray should be null", jsonArray == null); - Util.checkJSONObjectMaps(jsonObject); - Util.checkJSONArrayMaps(jsonArray, jsonObject.getMapType()); - } - - /** - * Populate a JSONArray from a JSONObject names() method. - * Confirm that it contains the expected names. - */ - @Test - public void jsonObjectNamesToJsonAray() { - String str = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"stringKey\":\"hello world!\","+ - "}"; - - JSONObject jsonObject = new JSONObject(str); - JSONArray jsonArray = jsonObject.names(); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 3 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected to find trueKey", ((List) JsonPath.read(doc, "$[?(@=='trueKey')]")).size() == 1); - assertTrue("expected to find falseKey", ((List) JsonPath.read(doc, "$[?(@=='falseKey')]")).size() == 1); - assertTrue("expected to find stringKey", ((List) JsonPath.read(doc, "$[?(@=='stringKey')]")).size() == 1); - Util.checkJSONObjectMaps(jsonObject); - Util.checkJSONArrayMaps(jsonArray, jsonObject.getMapType()); - } - - /** - * Exercise the JSONObject increment() method. - */ - @SuppressWarnings("cast") - @Test - public void jsonObjectIncrement() { - String str = - "{"+ - "\"keyLong\":9999999991,"+ - "\"keyDouble\":1.1"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - jsonObject.increment("keyInt"); - jsonObject.increment("keyInt"); - jsonObject.increment("keyLong"); - jsonObject.increment("keyDouble"); - jsonObject.increment("keyInt"); - jsonObject.increment("keyLong"); - jsonObject.increment("keyDouble"); - /** - * JSONObject constructor won't handle these types correctly, but - * adding them via put works. - */ - jsonObject.put("keyFloat", 1.1f); - jsonObject.put("keyBigInt", new BigInteger("123456789123456789123456789123456780")); - jsonObject.put("keyBigDec", new BigDecimal("123456789123456789123456789123456780.1")); - jsonObject.increment("keyFloat"); - jsonObject.increment("keyFloat"); - jsonObject.increment("keyBigInt"); - jsonObject.increment("keyBigDec"); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 6 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonObject.query("/keyInt"))); - assertTrue("expected 9999999993", Long.valueOf(9999999993L).equals(jsonObject.query("/keyLong"))); - assertTrue("expected 3.1", BigDecimal.valueOf(3.1).equals(jsonObject.query("/keyDouble"))); - assertTrue("expected 123456789123456789123456789123456781", new BigInteger("123456789123456789123456789123456781").equals(jsonObject.query("/keyBigInt"))); - assertTrue("expected 123456789123456789123456789123456781.1", new BigDecimal("123456789123456789123456789123456781.1").equals(jsonObject.query("/keyBigDec"))); - - /** - * Should work the same way on any platform! @see https://docs.oracle - * .com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3 This is the - * effect of a float to double conversion and is inherent to the - * shortcomings of the IEEE 754 format, when converting 32-bit into - * double-precision 64-bit. Java type-casts float to double. A 32 bit - * float is type-casted to 64 bit double by simply appending zero-bits - * to the mantissa (and extended the signed exponent by 3 bits.) and - * there is no way to obtain more information than it is stored in the - * 32-bits float. - * - * Like 1/3 cannot be represented as base10 number because it is - * periodically, 1/5 (for example) cannot be represented as base2 number - * since it is periodically in base2 (take a look at - * http://www.h-schmidt.net/FloatConverter/) The same happens to 3.1, - * that decimal number (base10 representation) is periodic in base2 - * representation, therefore appending zero-bits is inaccurate. Only - * repeating the periodically occurring bits (0110) would be a proper - * conversion. However one cannot detect from a 32 bit IEE754 - * representation which bits would "repeat infinitely", since the - * missing bits would not fit into the 32 bit float, i.e. the - * information needed simply is not there! - */ - assertEquals(Float.valueOf(3.1f), jsonObject.query("/keyFloat")); - - /** - * float f = 3.1f; double df = (double) f; double d = 3.1d; - * System.out.println - * (Integer.toBinaryString(Float.floatToRawIntBits(f))); - * System.out.println - * (Long.toBinaryString(Double.doubleToRawLongBits(df))); - * System.out.println - * (Long.toBinaryString(Double.doubleToRawLongBits(d))); - * - * - Float: - * seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm - * 1000000010001100110011001100110 - * - Double - * seeeeeeeeeeemmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - * 10000000 10001100110011001100110 - * 100000000001000110011001100110011000000000000000000000000000000 - * 100000000001000110011001100110011001100110011001100110011001101 - */ - - /** - * Examples of well documented but probably unexpected behavior in - * java / with 32-bit float to 64-bit float conversion. - */ - assertFalse("Document unexpected behaviour with explicit type-casting float as double!", (double)0.2f == 0.2d ); - assertFalse("Document unexpected behaviour with implicit type-cast!", 0.2f == 0.2d ); - Double d1 = Double.valueOf( 1.1f ); - Double d2 = Double.valueOf( "1.1f" ); - assertFalse( "Document implicit type cast from float to double before calling Double(double d) constructor", d1.equals( d2 ) ); - - assertTrue( "Correctly converting float to double via base10 (string) representation!", Double.valueOf( 3.1d ).equals( Double.valueOf( Float.valueOf( 3.1f ).toString() ) ) ); - - // Pinpointing the not so obvious "buggy" conversion from float to double in JSONObject - JSONObject jo = new JSONObject(); - jo.put( "bug", 3.1f ); // will call put( String key, double value ) with implicit and "buggy" type-cast from float to double - assertFalse( "The java-compiler did add some zero bits for you to the mantissa (unexpected, but well documented)", jo.get( "bug" ).equals( Double.valueOf( 3.1d ) ) ); - - JSONObject inc = new JSONObject(); - inc.put( "bug", Float.valueOf( 3.1f ) ); // This will put in instance of Float into JSONObject, i.e. call put( String key, Object value ) - assertTrue( "Everything is ok here!", inc.get( "bug" ) instanceof Float ); - inc.increment( "bug" ); // after adding 1, increment will call put( String key, double value ) with implicit and "buggy" type-cast from float to double! - // this.put(key, (Float) value + 1); - // 1. The (Object)value will be typecasted to (Float)value since it is an instanceof Float actually nothing is done. - // 2. Float instance will be autoboxed into float because the + operator will work on primitives not Objects! - // 3. A float+float operation will be performed and results into a float primitive. - // 4. There is no method that matches the signature put( String key, float value), java-compiler will choose the method - // put( String key, double value) and does an implicit type-cast(!) by appending zero-bits to the mantissa - assertTrue( "JSONObject increment converts Float to Double", jo.get( "bug" ) instanceof Float ); - // correct implementation (with change of behavior) would be: - // this.put(key, new Float((Float) value + 1)); - // Probably it would be better to deprecate the method and remove some day, while convenient processing the "payload" is not - // really in the scope of a JSON-library (IMHO.) - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject, inc - ))); - } - - /** - * Exercise JSONObject numberToString() method - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectNumberToString() { - String str; - Double dVal; - Integer iVal = 1; - str = JSONObject.numberToString(iVal); - assertTrue("expected "+iVal+" actual "+str, iVal.toString().equals(str)); - dVal = 12.34; - str = JSONObject.numberToString(dVal); - assertTrue("expected "+dVal+" actual "+str, dVal.toString().equals(str)); - dVal = 12.34e27; - str = JSONObject.numberToString(dVal); - assertTrue("expected "+dVal+" actual "+str, dVal.toString().equals(str)); - // trailing .0 is truncated, so it doesn't quite match toString() - dVal = 5000000.0000000; - str = JSONObject.numberToString(dVal); - assertTrue("expected 5000000 actual "+str, str.equals("5000000")); - } - - /** - * Exercise JSONObject put() and similar() methods - */ - @SuppressWarnings("boxing") - @Test - public void jsonObjectPut() { - String expectedStr = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\":{"+ - "\"myKey1\":\"myVal1\","+ - "\"myKey2\":\"myVal2\","+ - "\"myKey3\":\"myVal3\","+ - "\"myKey4\":\"myVal4\""+ - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("trueKey", true); - jsonObject.put("falseKey", false); - Integer [] intArray = { 0, 1, 2 }; - jsonObject.put("arrayKey", Arrays.asList(intArray)); - Map myMap = new HashMap(); - myMap.put("myKey1", "myVal1"); - myMap.put("myKey2", "myVal2"); - myMap.put("myKey3", "myVal3"); - myMap.put("myKey4", "myVal4"); - jsonObject.put("objectKey", myMap); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 4 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 4); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/trueKey"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/falseKey"))); - assertTrue("expected 3 arrayKey items", ((List)(JsonPath.read(doc, "$.arrayKey"))).size() == 3); - assertTrue("expected 0", Integer.valueOf(0).equals(jsonObject.query("/arrayKey/0"))); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonObject.query("/arrayKey/1"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonObject.query("/arrayKey/2"))); - assertTrue("expected 4 objectKey items", ((Map)(JsonPath.read(doc, "$.objectKey"))).size() == 4); - assertTrue("expected myVal1", "myVal1".equals(jsonObject.query("/objectKey/myKey1"))); - assertTrue("expected myVal2", "myVal2".equals(jsonObject.query("/objectKey/myKey2"))); - assertTrue("expected myVal3", "myVal3".equals(jsonObject.query("/objectKey/myKey3"))); - assertTrue("expected myVal4", "myVal4".equals(jsonObject.query("/objectKey/myKey4"))); - - jsonObject.remove("trueKey"); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - assertTrue("unequal jsonObjects should not be similar", - !jsonObject.similar(expectedJsonObject)); - assertTrue("jsonObject should not be similar to jsonArray", - !jsonObject.similar(new JSONArray())); - - String aCompareValueStr = "{\"a\":\"aval\",\"b\":true}"; - String bCompareValueStr = "{\"a\":\"notAval\",\"b\":true}"; - JSONObject aCompareValueJsonObject = new JSONObject(aCompareValueStr); - JSONObject bCompareValueJsonObject = new JSONObject(bCompareValueStr); - assertTrue("different values should not be similar", - !aCompareValueJsonObject.similar(bCompareValueJsonObject)); - - String aCompareObjectStr = "{\"a\":\"aval\",\"b\":{}}"; - String bCompareObjectStr = "{\"a\":\"aval\",\"b\":true}"; - JSONObject aCompareObjectJsonObject = new JSONObject(aCompareObjectStr); - JSONObject bCompareObjectJsonObject = new JSONObject(bCompareObjectStr); - assertTrue("different nested JSONObjects should not be similar", - !aCompareObjectJsonObject.similar(bCompareObjectJsonObject)); - - String aCompareArrayStr = "{\"a\":\"aval\",\"b\":[]}"; - String bCompareArrayStr = "{\"a\":\"aval\",\"b\":true}"; - JSONObject aCompareArrayJsonObject = new JSONObject(aCompareArrayStr); - JSONObject bCompareArrayJsonObject = new JSONObject(bCompareArrayStr); - assertTrue("different nested JSONArrays should not be similar", - !aCompareArrayJsonObject.similar(bCompareArrayJsonObject)); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject, expectedJsonObject, aCompareValueJsonObject, - aCompareArrayJsonObject, aCompareObjectJsonObject, aCompareArrayJsonObject, - bCompareValueJsonObject, bCompareArrayJsonObject, bCompareObjectJsonObject, - bCompareArrayJsonObject - ))); - } - - /** - * Exercise JSONObject toString() method - */ - @Test - public void jsonObjectToString() { - String str = - "{"+ - "\"trueKey\":true,"+ - "\"falseKey\":false,"+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\":{"+ - "\"myKey1\":\"myVal1\","+ - "\"myKey2\":\"myVal2\","+ - "\"myKey3\":\"myVal3\","+ - "\"myKey4\":\"myVal4\""+ - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 4 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 4); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/trueKey"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/falseKey"))); - assertTrue("expected 3 arrayKey items", ((List)(JsonPath.read(doc, "$.arrayKey"))).size() == 3); - assertTrue("expected 0", Integer.valueOf(0).equals(jsonObject.query("/arrayKey/0"))); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonObject.query("/arrayKey/1"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonObject.query("/arrayKey/2"))); - assertTrue("expected 4 objectKey items", ((Map)(JsonPath.read(doc, "$.objectKey"))).size() == 4); - assertTrue("expected myVal1", "myVal1".equals(jsonObject.query("/objectKey/myKey1"))); - assertTrue("expected myVal2", "myVal2".equals(jsonObject.query("/objectKey/myKey2"))); - assertTrue("expected myVal3", "myVal3".equals(jsonObject.query("/objectKey/myKey3"))); - assertTrue("expected myVal4", "myVal4".equals(jsonObject.query("/objectKey/myKey4"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise JSONObject toString() method with various indent levels. - */ - @Test - public void jsonObjectToStringIndent() { - String jsonObject0Str = - "{"+ - "\"key1\":" + - "[1,2," + - "{\"key3\":true}" + - "],"+ - "\"key2\":" + - "{\"key1\":\"val1\",\"key2\":" + - "{\"key2\":\"val2\"}" + - "},"+ - "\"key3\":" + - "[" + - "[1,2.1]" + - "," + - "[null]" + - "]"+ - "}"; - - String jsonObject1Str = - "{\n" + - " \"key1\": [\n" + - " 1,\n" + - " 2,\n" + - " {\"key3\": true}\n" + - " ],\n" + - " \"key2\": {\n" + - " \"key1\": \"val1\",\n" + - " \"key2\": {\"key2\": \"val2\"}\n" + - " },\n" + - " \"key3\": [\n" + - " [\n" + - " 1,\n" + - " 2.1\n" + - " ],\n" + - " [null]\n" + - " ]\n" + - "}"; - String jsonObject4Str = - "{\n" + - " \"key1\": [\n" + - " 1,\n" + - " 2,\n" + - " {\"key3\": true}\n" + - " ],\n" + - " \"key2\": {\n" + - " \"key1\": \"val1\",\n" + - " \"key2\": {\"key2\": \"val2\"}\n" + - " },\n" + - " \"key3\": [\n" + - " [\n" + - " 1,\n" + - " 2.1\n" + - " ],\n" + - " [null]\n" + - " ]\n" + - "}"; - JSONObject jsonObject = new JSONObject(jsonObject0Str); - // contents are tested in other methods, in this case just validate the spacing by - // checking length - assertEquals("toString() length",jsonObject0Str.length(), jsonObject.toString().length()); - assertEquals("toString(0) length",jsonObject0Str.length(), jsonObject.toString(0).length()); - assertEquals("toString(1) length",jsonObject1Str.length(), jsonObject.toString(1).length()); - assertEquals("toString(4) length",jsonObject4Str.length(), jsonObject.toString(4).length()); - - JSONObject jo = new JSONObject().put("TABLE", new JSONObject().put("yhoo", new JSONObject())); - assertEquals("toString(2)","{\"TABLE\": {\"yhoo\": {}}}", jo.toString(2)); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject, jo - ))); - } - - /** - * Explores how JSONObject handles maps. Insert a string/string map - * as a value in a JSONObject. It will remain a map. Convert the - * JSONObject to string, then create a new JSONObject from the string. - * In the new JSONObject, the value will be stored as a nested JSONObject. - * Confirm that map and nested JSONObject have the same contents. - */ - @Test - public void jsonObjectToStringSuppressWarningOnCastToMap() { - JSONObject jsonObject = new JSONObject(); - Map map = new HashMap<>(); - map.put("abc", "def"); - jsonObject.put("key", map); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 1 key item", ((Map)(JsonPath.read(doc, "$.key"))).size() == 1); - assertTrue("expected def", "def".equals(jsonObject.query("/key/abc"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Explores how JSONObject handles collections. Insert a string collection - * as a value in a JSONObject. It will remain a collection. Convert the - * JSONObject to string, then create a new JSONObject from the string. - * In the new JSONObject, the value will be stored as a nested JSONArray. - * Confirm that collection and nested JSONArray have the same contents. - */ - @Test - public void jsonObjectToStringSuppressWarningOnCastToCollection() { - JSONObject jsonObject = new JSONObject(); - Collection collection = new ArrayList(); - collection.add("abc"); - // ArrayList will be added as an object - jsonObject.put("key", collection); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected 1 key item", ((List)(JsonPath.read(doc, "$.key"))).size() == 1); - assertTrue("expected abc", "abc".equals(jsonObject.query("/key/0"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercises the JSONObject.valueToString() method for various types - */ - @Test - public void valueToString() { - - assertTrue("null valueToString() incorrect", - "null".equals(JSONObject.valueToString(null))); - MyJsonString jsonString = new MyJsonString(); - assertTrue("jsonstring valueToString() incorrect", - "my string".equals(JSONObject.valueToString(jsonString))); - assertTrue("boolean valueToString() incorrect", - "true".equals(JSONObject.valueToString(Boolean.TRUE))); - assertTrue("non-numeric double", - "null".equals(JSONObject.doubleToString(Double.POSITIVE_INFINITY))); - String jsonObjectStr = - "{"+ - "\"key1\":\"val1\","+ - "\"key2\":\"val2\","+ - "\"key3\":\"val3\""+ - "}"; - JSONObject jsonObject = new JSONObject(jsonObjectStr); - assertTrue("jsonObject valueToString() incorrect", - new JSONObject(JSONObject.valueToString(jsonObject)) - .similar(new JSONObject(jsonObject.toString())) - ); - String jsonArrayStr = - "[1,2,3]"; - JSONArray jsonArray = new JSONArray(jsonArrayStr); - assertTrue("jsonArray valueToString() incorrect", - JSONObject.valueToString(jsonArray).equals(jsonArray.toString())); - Map map = new HashMap(); - map.put("key1", "val1"); - map.put("key2", "val2"); - map.put("key3", "val3"); - assertTrue("map valueToString() incorrect", - new JSONObject(jsonObject.toString()) - .similar(new JSONObject(JSONObject.valueToString(map)))); - Collection collection = new ArrayList(); - collection.add(Integer.valueOf(1)); - collection.add(Integer.valueOf(2)); - collection.add(Integer.valueOf(3)); - assertTrue("collection valueToString() expected: "+ - jsonArray.toString()+ " actual: "+ - JSONObject.valueToString(collection), - jsonArray.toString().equals(JSONObject.valueToString(collection))); - Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) }; - assertTrue("array valueToString() incorrect", - jsonArray.toString().equals(JSONObject.valueToString(array))); - Util.checkJSONObjectMaps(jsonObject); - Util.checkJSONArrayMaps(jsonArray, jsonObject.getMapType()); - } - - /** - * Confirm that https://github.com/douglascrockford/JSON-java/issues/167 is fixed. - * The following code was throwing a ClassCastException in the - * JSONObject(Map) constructor - */ - @SuppressWarnings("boxing") - @Test - public void valueToStringConfirmException() { - Map myMap = new HashMap(); - myMap.put(1, "myValue"); - // this is the test, it should not throw an exception - String str = JSONObject.valueToString(myMap); - // confirm result, just in case - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(str); - assertTrue("expected 1 top level item", ((Map)(JsonPath.read(doc, "$"))).size() == 1); - assertTrue("expected myValue", "myValue".equals(JsonPath.read(doc, "$.1"))); - } - - /** - * Exercise the JSONObject wrap() method. Sometimes wrap() will change - * the object being wrapped, other times not. The purpose of wrap() is - * to ensure the value is packaged in a way that is compatible with how - * a JSONObject value or JSONArray value is supposed to be stored. - */ - @Test - public void wrapObject() { - // wrap(null) returns NULL - assertTrue("null wrap() incorrect", - JSONObject.NULL == JSONObject.wrap(null)); - - // wrap(Integer) returns Integer - Integer in = Integer.valueOf(1); - assertTrue("Integer wrap() incorrect", - in == JSONObject.wrap(in)); - - /** - * This test is to document the preferred behavior if BigDecimal is - * supported. Previously bd returned as a string, since it - * is recognized as being a Java package class. Now with explicit - * support for big numbers, it remains a BigDecimal - */ - Object bdWrap = JSONObject.wrap(BigDecimal.ONE); - assertTrue("BigDecimal.ONE evaluates to ONE", - bdWrap.equals(BigDecimal.ONE)); - - // wrap JSONObject returns JSONObject - String jsonObjectStr = - "{"+ - "\"key1\":\"val1\","+ - "\"key2\":\"val2\","+ - "\"key3\":\"val3\""+ - "}"; - JSONObject jsonObject = new JSONObject(jsonObjectStr); - assertTrue("JSONObject wrap() incorrect", - jsonObject == JSONObject.wrap(jsonObject)); - - // wrap collection returns JSONArray - Collection collection = new ArrayList(); - collection.add(Integer.valueOf(1)); - collection.add(Integer.valueOf(2)); - collection.add(Integer.valueOf(3)); - JSONArray jsonArray = (JSONArray) (JSONObject.wrap(collection)); - - // validate JSON - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 3 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/1"))); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2"))); - - // wrap Array returns JSONArray - Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) }; - JSONArray integerArrayJsonArray = (JSONArray)(JSONObject.wrap(array)); - - // validate JSON - doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 3 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/1"))); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2"))); - - // validate JSON - doc = Configuration.defaultConfiguration().jsonProvider().parse(integerArrayJsonArray.toString()); - assertTrue("expected 3 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonArray.query("/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonArray.query("/1"))); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2"))); - - // wrap map returns JSONObject - Map map = new HashMap(); - map.put("key1", "val1"); - map.put("key2", "val2"); - map.put("key3", "val3"); - JSONObject mapJsonObject = (JSONObject) (JSONObject.wrap(map)); - - // validate JSON - doc = Configuration.defaultConfiguration().jsonProvider().parse(mapJsonObject.toString()); - assertTrue("expected 3 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 3); - assertTrue("expected val1", "val1".equals(mapJsonObject.query("/key1"))); - assertTrue("expected val2", "val2".equals(mapJsonObject.query("/key2"))); - assertTrue("expected val3", "val3".equals(mapJsonObject.query("/key3"))); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObject, mapJsonObject - ))); - Util.checkJSONArrayMaps(jsonArray, jsonObject.getMapType()); - Util.checkJSONArrayMaps(integerArrayJsonArray, jsonObject.getMapType()); - } - - - /** - * RFC 7159 defines control characters to be U+0000 through U+001F. This test verifies that the parser is checking for these in expected ways. - */ - @Test - public void jsonObjectParseControlCharacters(){ - for(int i = 0;i<=0x001f;i++){ - final String charString = String.valueOf((char)i); - final String source = "{\"key\":\""+charString+"\"}"; - try { - JSONObject jo = new JSONObject(source); - assertTrue("Expected "+charString+"("+i+") in the JSON Object but did not find it.",charString.equals(jo.getString("key"))); - Util.checkJSONObjectMaps(jo); - } catch (JSONException ex) { - assertTrue("Only \\0 (U+0000), \\n (U+000A), and \\r (U+000D) should cause an error. Instead "+charString+"("+i+") caused an error", - i=='\0' || i=='\n' || i=='\r' - ); - } - } - } - - @Test - public void jsonObjectParseControlCharacterEOFAssertExceptionMessage(){ - char c = '\0'; - final String source = "{\"key\":\"" + c + "\"}"; - try { - JSONObject jo = new JSONObject(source); - fail("JSONException should be thrown"); - } catch (JSONException ex) { - assertEquals("Unterminated string. " + "Character with int code 0" + - " is not allowed within a quoted string. at 8 [character 9 line 1]", ex.getMessage()); - } - } - - @Test - public void jsonObjectParseControlCharacterNewLineAssertExceptionMessage(){ - char[] chars = {'\n', '\r'}; - for( char c : chars) { - final String source = "{\"key\":\"" + c + "\"}"; - try { - JSONObject jo = new JSONObject(source); - fail("JSONException should be thrown"); - } catch (JSONException ex) { - assertEquals("Unterminated string. " + "Character with int code " + (int) c + - " is not allowed within a quoted string. at 9 [character 0 line 2]", ex.getMessage()); - } - } - } - - @Test - public void jsonObjectParseUTF8EncodingAssertExceptionMessage(){ - String c = "\\u123x"; - final String source = "{\"key\":\"" + c + "\"}"; - try { - JSONObject jo = new JSONObject(source); - fail("JSONException should be thrown"); - } catch (JSONException ex) { - assertEquals("Illegal escape. \\u must be followed by a 4 digit hexadecimal number. " + - "\\123x is not valid. at 14 [character 15 line 1]", ex.getMessage()); - } - } - - @Test - public void jsonObjectParseIllegalEscapeAssertExceptionMessage(){ - String c = "\\x"; - final String source = "{\"key\":\"" + c + "\"}"; - try { - JSONObject jo = new JSONObject(source); - fail("JSONException should be thrown"); - } catch (JSONException ex) { - assertEquals("Illegal escape. Escape sequence " + c + " is not valid." + - " at 10 [character 11 line 1]", ex.getMessage()); - } - } - - /** - * Explore how JSONObject handles parsing errors. - */ - @SuppressWarnings({"boxing", "unused"}) - @Ignore - public void jsonObjectParsingErrors() { - try { - // does not start with '{' - String str = "abc"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "A JSONObject text must begin with '{' at 1 [character 2 line 1]", - e.getMessage()); - } - try { - // does not end with '}' - String str = "{"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at 1 [character 2 line 1]", - e.getMessage()); - } - try { - // key with no ':' - String str = "{\"myKey\" = true}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected a ':' after a key at 10 [character 11 line 1]", - e.getMessage()); - } - try { - // entries with no ',' separator - String str = "{\"myKey\":true \"myOtherKey\":false}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected a ',' or '}' at 15 [character 16 line 1]", - e.getMessage()); - } - try { - // key is a nested map - String str = "{{\"foo\": \"bar\"}: \"baz\"}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Missing value at 1 [character 2 line 1]", - e.getMessage()); - } - try { - // key is a nested array containing a map - String str = "{\"a\": 1, [{\"foo\": \"bar\"}]: \"baz\"}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Missing value at 9 [character 10 line 1]", - e.getMessage()); - } - try { - // key contains } - String str = "{foo}: 2}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Value 'foo' is not surrounded by quotes at 4 [character 5] line 1]", - e.getMessage()); - } - try { - // key contains ] - String str = "{foo]: 2}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected a ':' after a key at 5 [character 6 line 1]", - e.getMessage()); - } - try { - // \0 after , - String str = "{\"myKey\":true, \0\"myOtherKey\":false}"; - assertNull("Expected an exception",new JSONObject(str)); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at 15 [character 16 line 1]", - e.getMessage()); - } - try { - // append to wrong key - String str = "{\"myKey\":true, \"myOtherKey\":false}"; - JSONObject jsonObject = new JSONObject(str); - jsonObject.append("myKey", "hello"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "JSONObject[\"myKey\"] is not a JSONArray (null).", - e.getMessage()); - } - try { - // increment wrong key - String str = "{\"myKey\":true, \"myOtherKey\":false}"; - JSONObject jsonObject = new JSONObject(str); - jsonObject.increment("myKey"); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Unable to increment [\"myKey\"].", - e.getMessage()); - } - try { - // invalid key - String str = "{\"myKey\":true, \"myOtherKey\":false}"; - JSONObject jsonObject = new JSONObject(str); - jsonObject.get(null); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Null key.", - e.getMessage()); - } - try { - // invalid numberToString() - JSONObject.numberToString((Number)null); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Null pointer", - e.getMessage()); - } - - try { - // multiple putOnce key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.putOnce("hello", "world"); - jsonObject.putOnce("hello", "world!"); - fail("Expected an exception"); - } catch (JSONException e) { - assertTrue("", true); - } - try { - // test validity of invalid double - JSONObject.testValidity(Double.NaN); - fail("Expected an exception"); - } catch (JSONException e) { - assertTrue("", true); - } - try { - // test validity of invalid float - JSONObject.testValidity(Float.NEGATIVE_INFINITY); - fail("Expected an exception"); - } catch (JSONException e) { - assertTrue("", true); - } - try { - // test exception message when including a duplicate key (level 0) - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\":\"value-04\"\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key (level 0) holding an object - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\": {" - +" \"attr04-01\":\"value-04-01\",n" - +" \"attr04-02\":\"value-04-02\",n" - +" \"attr04-03\":\"value-04-03\"n" - + " }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key (level 0) holding an array - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\": [\n" - +" {" - +" \"attr04-01\":\"value-04-01\",n" - +" \"attr04-02\":\"value-04-02\",n" - +" \"attr04-03\":\"value-04-03\"n" - +" }\n" - + " ]\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key (level 1) - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\":\"value04-04\"\n" - + " }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key (level 1) holding an object - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\": {\n" - +" \"attr04-04-01\":\"value04-04-01\",\n" - +" \"attr04-04-02\":\"value04-04-02\",\n" - +" \"attr04-04-03\":\"value04-04-03\",\n" - +" }\n" - +" }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key (level 1) holding an array - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\": [\n" - +" {\n" - +" \"attr04-04-01\":\"value04-04-01\",\n" - +" \"attr04-04-02\":\"value04-04-02\",\n" - +" \"attr04-04-03\":\"value04-04-03\",\n" - +" }\n" - +" ]\n" - +" }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key in object (level 0) within an array - String str = "[\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\"\n" - +" },\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr01\":\"value-02\"\n" - +" }\n" - + "]"; - new JSONArray(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at 124 [character 17 line 8]", - e.getMessage()); - } - try { - // test exception message when including a duplicate key in object (level 1) within an array - String str = "[\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\": {\n" - +" \"attr02-01\":\"value-02-01\",\n" - +" \"attr02-02\":\"value-02-02\"\n" - +" }\n" - +" },\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\": {\n" - +" \"attr02-01\":\"value-02-01\",\n" - +" \"attr02-01\":\"value-02-02\"\n" - +" }\n" - +" }\n" - + "]"; - new JSONArray(str); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", - e.getMessage()); - } - } - - /** - * Confirm behavior when putOnce() is called with null parameters - */ - @Test - public void jsonObjectPutOnceNull() { - JSONObject jsonObject = new JSONObject(); - jsonObject.putOnce(null, null); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - jsonObject.putOnce("", null); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - jsonObject.putOnce(null, ""); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise JSONObject opt(key, default) method. - */ - @Test - public void jsonObjectOptDefault() { - - String str = "{\"myKey\": \"myval\", \"hiKey\": null}"; - JSONObject jsonObject = new JSONObject(str); - - assertTrue("optBigDecimal() should return default BigDecimal", - BigDecimal.TEN.compareTo(jsonObject.optBigDecimal("myKey", BigDecimal.TEN))==0); - assertTrue("optBigInteger() should return default BigInteger", - BigInteger.TEN.compareTo(jsonObject.optBigInteger("myKey",BigInteger.TEN ))==0); - assertTrue("optBoolean() should return default boolean", - jsonObject.optBoolean("myKey", true)); - assertTrue("optBooleanObject() should return default Boolean", - jsonObject.optBooleanObject("myKey", true)); - assertTrue("optInt() should return default int", - 42 == jsonObject.optInt("myKey", 42)); - assertTrue("optIntegerObject() should return default Integer", - Integer.valueOf(42).equals(jsonObject.optIntegerObject("myKey", 42))); - assertTrue("optEnum() should return default Enum", - MyEnum.VAL1.equals(jsonObject.optEnum(MyEnum.class, "myKey", MyEnum.VAL1))); - assertTrue("optJSONArray() should return null ", - null==jsonObject.optJSONArray("myKey")); - assertTrue("optJSONArray() should return default JSONArray", - "value".equals(jsonObject.optJSONArray("myKey", new JSONArray("[\"value\"]")).getString(0))); - assertTrue("optJSONObject() should return default JSONObject ", - jsonObject.optJSONObject("myKey", new JSONObject("{\"testKey\":\"testValue\"}")).getString("testKey").equals("testValue")); - assertTrue("optLong() should return default long", - 42l == jsonObject.optLong("myKey", 42l)); - assertTrue("optLongObject() should return default Long", - Long.valueOf(42l).equals(jsonObject.optLongObject("myKey", 42l))); - assertTrue("optDouble() should return default double", - 42.3d == jsonObject.optDouble("myKey", 42.3d)); - assertTrue("optDoubleObject() should return default Double", - Double.valueOf(42.3d).equals(jsonObject.optDoubleObject("myKey", 42.3d))); - assertTrue("optFloat() should return default float", - 42.3f == jsonObject.optFloat("myKey", 42.3f)); - assertTrue("optFloatObject() should return default Float", - Float.valueOf(42.3f).equals(jsonObject.optFloatObject("myKey", 42.3f))); - assertTrue("optNumber() should return default Number", - 42l == jsonObject.optNumber("myKey", Long.valueOf(42)).longValue()); - assertTrue("optString() should return default string", - "hi".equals(jsonObject.optString("hiKey", "hi"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Exercise JSONObject opt(key, default) method when the key doesn't exist. - */ - @Test - public void jsonObjectOptNoKey() { - - JSONObject jsonObject = new JSONObject(); - - assertNull(jsonObject.opt(null)); - - assertTrue("optBigDecimal() should return default BigDecimal", - BigDecimal.TEN.compareTo(jsonObject.optBigDecimal("myKey", BigDecimal.TEN))==0); - assertTrue("optBigInteger() should return default BigInteger", - BigInteger.TEN.compareTo(jsonObject.optBigInteger("myKey",BigInteger.TEN ))==0); - assertTrue("optBoolean() should return default boolean", - jsonObject.optBoolean("myKey", true)); - assertTrue("optBooleanObject() should return default Boolean", - jsonObject.optBooleanObject("myKey", true)); - assertTrue("optInt() should return default int", - 42 == jsonObject.optInt("myKey", 42)); - assertTrue("optIntegerObject() should return default Integer", - Integer.valueOf(42).equals(jsonObject.optIntegerObject("myKey", 42))); - assertTrue("optEnum() should return default Enum", - MyEnum.VAL1.equals(jsonObject.optEnum(MyEnum.class, "myKey", MyEnum.VAL1))); - assertTrue("optJSONArray() should return default JSONArray", - "value".equals(jsonObject.optJSONArray("myKey", new JSONArray("[\"value\"]")).getString(0))); - assertTrue("optJSONArray() should return null ", - null==jsonObject.optJSONArray("myKey")); - assertTrue("optJSONObject() should return default JSONObject ", - jsonObject.optJSONObject("myKey", new JSONObject("{\"testKey\":\"testValue\"}")).getString("testKey").equals("testValue")); - assertTrue("optLong() should return default long", - 42l == jsonObject.optLong("myKey", 42l)); - assertTrue("optLongObject() should return default Long", - Long.valueOf(42l).equals(jsonObject.optLongObject("myKey", 42l))); - assertTrue("optDouble() should return default double", - 42.3d == jsonObject.optDouble("myKey", 42.3d)); - assertTrue("optDoubleObject() should return default Double", - Double.valueOf(42.3d).equals(jsonObject.optDoubleObject("myKey", 42.3d))); - assertTrue("optFloat() should return default float", - 42.3f == jsonObject.optFloat("myKey", 42.3f)); - assertTrue("optFloatObject() should return default Float", - Float.valueOf(42.3f).equals(jsonObject.optFloatObject("myKey", 42.3f))); - assertTrue("optNumber() should return default Number", - 42l == jsonObject.optNumber("myKey", Long.valueOf(42)).longValue()); - assertTrue("optString() should return default string", - "hi".equals(jsonObject.optString("hiKey", "hi"))); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Verifies that the opt methods properly convert string values. - */ - @Test - public void jsonObjectOptStringConversion() { - JSONObject jo = new JSONObject("{\"int\":\"123\",\"true\":\"true\",\"false\":\"false\"}"); - assertTrue("unexpected optBoolean value",jo.optBoolean("true",false)==true); - assertTrue("unexpected optBooleanObject value",Boolean.valueOf(true).equals(jo.optBooleanObject("true",false))); - assertTrue("unexpected optBoolean value",jo.optBoolean("false",true)==false); - assertTrue("unexpected optBooleanObject value",Boolean.valueOf(false).equals(jo.optBooleanObject("false",true))); - assertTrue("unexpected optInt value",jo.optInt("int",0)==123); - assertTrue("unexpected optIntegerObject value",Integer.valueOf(123).equals(jo.optIntegerObject("int",0))); - assertTrue("unexpected optLong value",jo.optLong("int",0)==123l); - assertTrue("unexpected optLongObject value",Long.valueOf(123l).equals(jo.optLongObject("int",0L))); - assertTrue("unexpected optDouble value",jo.optDouble("int",0.0d)==123.0d); - assertTrue("unexpected optDoubleObject value",Double.valueOf(123.0d).equals(jo.optDoubleObject("int",0.0d))); - assertTrue("unexpected optFloat value",jo.optFloat("int",0.0f)==123.0f); - assertTrue("unexpected optFloatObject value",Float.valueOf(123.0f).equals(jo.optFloatObject("int",0.0f))); - assertTrue("unexpected optBigInteger value",jo.optBigInteger("int",BigInteger.ZERO).compareTo(new BigInteger("123"))==0); - assertTrue("unexpected optBigDecimal value",jo.optBigDecimal("int",BigDecimal.ZERO).compareTo(new BigDecimal("123"))==0); - assertTrue("unexpected optBigDecimal value",jo.optBigDecimal("int",BigDecimal.ZERO).compareTo(new BigDecimal("123"))==0); - assertTrue("unexpected optNumber value",jo.optNumber("int",BigInteger.ZERO).longValue()==123l); - Util.checkJSONObjectMaps(jo); - } - - /** - * Verifies that the opt methods properly convert string values to numbers and coerce them consistently. - */ - @Test - public void jsonObjectOptCoercion() { - JSONObject jo = new JSONObject("{\"largeNumberStr\":\"19007199254740993.35481234487103587486413587843213584\"}"); - // currently the parser doesn't recognize BigDecimal, to we have to put it manually - jo.put("largeNumber", new BigDecimal("19007199254740993.35481234487103587486413587843213584")); - - // Test type coercion from larger to smaller - assertEquals(new BigDecimal("19007199254740993.35481234487103587486413587843213584"), jo.optBigDecimal("largeNumber",null)); - assertEquals(new BigInteger("19007199254740993"), jo.optBigInteger("largeNumber",null)); - assertEquals(1.9007199254740992E16, jo.optDouble("largeNumber"),0.0); - assertEquals(1.9007199254740992E16, jo.optDoubleObject("largeNumber"),0.0); - assertEquals(1.90071995E16f, jo.optFloat("largeNumber"),0.0f); - assertEquals(1.90071995E16f, jo.optFloatObject("largeNumber"),0.0f); - assertEquals(19007199254740993l, jo.optLong("largeNumber")); - assertEquals(Long.valueOf(19007199254740993l), jo.optLongObject("largeNumber")); - assertEquals(1874919425, jo.optInt("largeNumber")); - assertEquals(Integer.valueOf(1874919425), jo.optIntegerObject("largeNumber")); - - // conversion from a string - assertEquals(new BigDecimal("19007199254740993.35481234487103587486413587843213584"), jo.optBigDecimal("largeNumberStr",null)); - assertEquals(new BigInteger("19007199254740993"), jo.optBigInteger("largeNumberStr",null)); - assertEquals(1.9007199254740992E16, jo.optDouble("largeNumberStr"),0.0); - assertEquals(1.9007199254740992E16, jo.optDoubleObject("largeNumberStr"),0.0); - assertEquals(1.90071995E16f, jo.optFloat("largeNumberStr"),0.0f); - assertEquals(1.90071995E16f, jo.optFloatObject("largeNumberStr"),0.0f); - assertEquals(19007199254740993l, jo.optLong("largeNumberStr")); - assertEquals(Long.valueOf(19007199254740993l), jo.optLongObject("largeNumberStr")); - assertEquals(1874919425, jo.optInt("largeNumberStr")); - assertEquals(Integer.valueOf(1874919425), jo.optIntegerObject("largeNumberStr")); - - // the integer portion of the actual value is larger than a double can hold. - assertNotEquals((long)Double.parseDouble("19007199254740993.35481234487103587486413587843213584"), jo.optLong("largeNumber")); - assertNotEquals(Long.valueOf((long)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")), jo.optLongObject("largeNumber")); - assertNotEquals((int)Double.parseDouble("19007199254740993.35481234487103587486413587843213584"), jo.optInt("largeNumber")); - assertNotEquals(Integer.valueOf((int)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")), jo.optIntegerObject("largeNumber")); - assertNotEquals((long)Double.parseDouble("19007199254740993.35481234487103587486413587843213584"), jo.optLong("largeNumberStr")); - assertNotEquals(Long.valueOf((long)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")), jo.optLongObject("largeNumberStr")); - assertNotEquals((int)Double.parseDouble("19007199254740993.35481234487103587486413587843213584"), jo.optInt("largeNumberStr")); - assertNotEquals(Integer.valueOf((int)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")), jo.optIntegerObject("largeNumberStr")); - assertEquals(19007199254740992l, (long)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")); - assertEquals(2147483647, (int)Double.parseDouble("19007199254740993.35481234487103587486413587843213584")); - Util.checkJSONObjectMaps(jo); - } - - /** - * Verifies that the optBigDecimal method properly converts values to BigDecimal and coerce them consistently. - */ - @Test - public void jsonObjectOptBigDecimal() { - JSONObject jo = new JSONObject().put("int", 123).put("long", 654L) - .put("float", 1.234f).put("double", 2.345d) - .put("bigInteger", new BigInteger("1234")) - .put("bigDecimal", new BigDecimal("1234.56789")) - .put("nullVal", JSONObject.NULL); - - assertEquals(new BigDecimal("123"),jo.optBigDecimal("int", null)); - assertEquals(new BigDecimal("654"),jo.optBigDecimal("long", null)); - assertEquals(new BigDecimal(1.234f),jo.optBigDecimal("float", null)); - assertEquals(new BigDecimal(2.345d),jo.optBigDecimal("double", null)); - assertEquals(new BigDecimal("1234"),jo.optBigDecimal("bigInteger", null)); - assertEquals(new BigDecimal("1234.56789"),jo.optBigDecimal("bigDecimal", null)); - assertNull(jo.optBigDecimal("nullVal", null)); - assertEquals(jo.optBigDecimal("float", null),jo.getBigDecimal("float")); - assertEquals(jo.optBigDecimal("double", null),jo.getBigDecimal("double")); - Util.checkJSONObjectMaps(jo); - } - - /** - * Verifies that the optBigDecimal method properly converts values to BigDecimal and coerce them consistently. - */ - @Test - public void jsonObjectOptBigInteger() { - JSONObject jo = new JSONObject().put("int", 123).put("long", 654L) - .put("float", 1.234f).put("double", 2.345d) - .put("bigInteger", new BigInteger("1234")) - .put("bigDecimal", new BigDecimal("1234.56789")) - .put("nullVal", JSONObject.NULL); - - assertEquals(new BigInteger("123"),jo.optBigInteger("int", null)); - assertEquals(new BigInteger("654"),jo.optBigInteger("long", null)); - assertEquals(new BigInteger("1"),jo.optBigInteger("float", null)); - assertEquals(new BigInteger("2"),jo.optBigInteger("double", null)); - assertEquals(new BigInteger("1234"),jo.optBigInteger("bigInteger", null)); - assertEquals(new BigInteger("1234"),jo.optBigInteger("bigDecimal", null)); - assertNull(jo.optBigDecimal("nullVal", null)); - Util.checkJSONObjectMaps(jo); - } - - /** - * Confirm behavior when JSONObject put(key, null object) is called - */ - @Test - public void jsonObjectputNull() { - - // put null should remove the item. - String str = "{\"myKey\": \"myval\"}"; - JSONObject jsonObjectRemove = new JSONObject(str); - jsonObjectRemove.remove("myKey"); - assertTrue("jsonObject should be empty", jsonObjectRemove.isEmpty()); - - JSONObject jsonObjectPutNull = new JSONObject(str); - jsonObjectPutNull.put("myKey", (Object) null); - assertTrue("jsonObject should be empty", jsonObjectPutNull.isEmpty()); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObjectRemove, jsonObjectPutNull - ))); - } - - /** - * Exercise JSONObject quote() method - * This purpose of quote() is to ensure that for strings with embedded - * quotes, the quotes are properly escaped. - */ - @Test - public void jsonObjectQuote() { - String str; - str = ""; - String quotedStr; - quotedStr = JSONObject.quote(str); - assertTrue("quote() expected escaped quotes, found "+quotedStr, - "\"\"".equals(quotedStr)); - str = "\"\""; - quotedStr = JSONObject.quote(str); - assertTrue("quote() expected escaped quotes, found "+quotedStr, - "\"\\\"\\\"\"".equals(quotedStr)); - str = "null and null will be emitted as "" - */ - String sJONull = XML.toString(jsonObjectJONull); - assertTrue("JSONObject.NULL should emit a null value", - "null".equals(sJONull)); - String sNull = XML.toString(jsonObjectNull); - assertTrue("null should emit an empty string", "".equals(sNull)); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jsonObjectJONull, jsonObjectNull - ))); - } - - @Test(expected = JSONPointerException.class) - public void queryWithNoResult() { - new JSONObject().query("/a/b"); - } - - @Test - public void optQueryWithNoResult() { - assertNull(new JSONObject().optQuery("/a/b")); - } - - @Test(expected = IllegalArgumentException.class) - public void optQueryWithSyntaxError() { - new JSONObject().optQuery("invalid"); - } - - @Test(expected = JSONException.class) - public void invalidEscapeSequence() { - String json = "{ \"\\url\": \"value\" }"; - assertNull("Expected an exception",new JSONObject(json)); - } - - /** - * Exercise JSONObject toMap() method. - */ - @Test - public void toMap() { - String jsonObjectStr = - "{" + - "\"key1\":" + - "[1,2," + - "{\"key3\":true}" + - "]," + - "\"key2\":" + - "{\"key1\":\"val1\",\"key2\":" + - "{\"key2\":null}," + - "\"key3\":42" + - "}," + - "\"key3\":" + - "[" + - "[\"value1\",2.1]" + - "," + - "[null]" + - "]" + - "}"; - - JSONObject jsonObject = new JSONObject(jsonObjectStr); - Map map = jsonObject.toMap(); - - assertTrue("Map should not be null", map != null); - assertTrue("Map should have 3 elements", map.size() == 3); - - List key1List = (List)map.get("key1"); - assertTrue("key1 should not be null", key1List != null); - assertTrue("key1 list should have 3 elements", key1List.size() == 3); - assertTrue("key1 value 1 should be 1", key1List.get(0).equals(Integer.valueOf(1))); - assertTrue("key1 value 2 should be 2", key1List.get(1).equals(Integer.valueOf(2))); - - Map key1Value3Map = (Map)key1List.get(2); - assertTrue("Map should not be null", key1Value3Map != null); - assertTrue("Map should have 1 element", key1Value3Map.size() == 1); - assertTrue("Map key3 should be true", key1Value3Map.get("key3").equals(Boolean.TRUE)); - - Map key2Map = (Map)map.get("key2"); - assertTrue("key2 should not be null", key2Map != null); - assertTrue("key2 map should have 3 elements", key2Map.size() == 3); - assertTrue("key2 map key 1 should be val1", key2Map.get("key1").equals("val1")); - assertTrue("key2 map key 3 should be 42", key2Map.get("key3").equals(Integer.valueOf(42))); - - Map key2Val2Map = (Map)key2Map.get("key2"); - assertTrue("key2 map key 2 should not be null", key2Val2Map != null); - assertTrue("key2 map key 2 should have an entry", key2Val2Map.containsKey("key2")); - assertTrue("key2 map key 2 value should be null", key2Val2Map.get("key2") == null); - - List key3List = (List)map.get("key3"); - assertTrue("key3 should not be null", key3List != null); - assertTrue("key3 list should have 3 elements", key3List.size() == 2); - - List key3Val1List = (List)key3List.get(0); - assertTrue("key3 list val 1 should not be null", key3Val1List != null); - assertTrue("key3 list val 1 should have 2 elements", key3Val1List.size() == 2); - assertTrue("key3 list val 1 list element 1 should be value1", key3Val1List.get(0).equals("value1")); - assertTrue("key3 list val 1 list element 2 should be 2.1", key3Val1List.get(1).equals(new BigDecimal("2.1"))); - - List key3Val2List = (List)key3List.get(1); - assertTrue("key3 list val 2 should not be null", key3Val2List != null); - assertTrue("key3 list val 2 should have 1 element", key3Val2List.size() == 1); - assertTrue("key3 list val 2 list element 1 should be null", key3Val2List.get(0) == null); - - // Assert that toMap() is a deep copy - jsonObject.getJSONArray("key3").getJSONArray(0).put(0, "still value 1"); - assertTrue("key3 list val 1 list element 1 should be value1", key3Val1List.get(0).equals("value1")); - - // assert that the new map is mutable - assertTrue("Removing a key should succeed", map.remove("key3") != null); - assertTrue("Map should have 2 elements", map.size() == 2); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * test that validates a singleton can be serialized as a bean. - */ - @SuppressWarnings("boxing") - @Test - public void testSingletonBean() { - final JSONObject jo = new JSONObject(Singleton.getInstance()); - assertEquals(jo.keySet().toString(), 1, jo.length()); - assertEquals(0, jo.get("someInt")); - assertEquals(null, jo.opt("someString")); - - // Update the singleton values - Singleton.getInstance().setSomeInt(42); - Singleton.getInstance().setSomeString("Something"); - final JSONObject jo2 = new JSONObject(Singleton.getInstance()); - assertEquals(2, jo2.length()); - assertEquals(42, jo2.get("someInt")); - assertEquals("Something", jo2.get("someString")); - - // ensure our original jo hasn't changed. - assertEquals(0, jo.get("someInt")); - assertEquals(null, jo.opt("someString")); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jo, jo2 - ))); - } - - /** - * test that validates a singleton can be serialized as a bean. - */ - @SuppressWarnings("boxing") - @Test - public void testSingletonEnumBean() { - final JSONObject jo = new JSONObject(SingletonEnum.getInstance()); - assertEquals(jo.keySet().toString(), 1, jo.length()); - assertEquals(0, jo.get("someInt")); - assertEquals(null, jo.opt("someString")); - - // Update the singleton values - SingletonEnum.getInstance().setSomeInt(42); - SingletonEnum.getInstance().setSomeString("Something"); - final JSONObject jo2 = new JSONObject(SingletonEnum.getInstance()); - assertEquals(2, jo2.length()); - assertEquals(42, jo2.get("someInt")); - assertEquals("Something", jo2.get("someString")); - - // ensure our original jo hasn't changed. - assertEquals(0, jo.get("someInt")); - assertEquals(null, jo.opt("someString")); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - jo, jo2 - ))); - } - - /** - * Test to validate that a generic class can be serialized as a bean. - */ - @SuppressWarnings("boxing") - @Test - public void testGenericBean() { - GenericBean bean = new GenericBean<>(42); - final JSONObject jo = new JSONObject(bean); - assertEquals(jo.keySet().toString(), 8, jo.length()); - assertEquals(42, jo.get("genericValue")); - assertEquals("Expected the getter to only be called once", - 1, bean.genericGetCounter); - assertEquals(0, bean.genericSetCounter); - Util.checkJSONObjectMaps(jo); - } - - /** - * Test to validate that a generic class can be serialized as a bean. - */ - @SuppressWarnings("boxing") - @Test - public void testGenericIntBean() { - GenericBeanInt bean = new GenericBeanInt(42); - final JSONObject jo = new JSONObject(bean); - assertEquals(jo.keySet().toString(), 10, jo.length()); - assertEquals(42, jo.get("genericValue")); - assertEquals("Expected the getter to only be called once", - 1, bean.genericGetCounter); - assertEquals(0, bean.genericSetCounter); - Util.checkJSONObjectMaps(jo); - } - - /** - * Test to verify key limitations in the JSONObject bean serializer. - */ - @Test - public void testWierdListBean() { - @SuppressWarnings("boxing") - WeirdList bean = new WeirdList(42, 43, 44); - final JSONObject jo = new JSONObject(bean); - // get() should have a key of 0 length - // get(int) should be ignored base on parameter count - // getInt(int) should also be ignored based on parameter count - // add(Integer) should be ignore as it doesn't start with get/is and also has a parameter - // getALL should be mapped - assertEquals("Expected 1 key to be mapped. Instead found: "+jo.keySet().toString(), - 1, jo.length()); - assertNotNull(jo.get("ALL")); - Util.checkJSONObjectMaps(jo); - } - - /** - * Sample test case from https://github.com/stleary/JSON-java/issues/531 - * which verifies that no regression in double/BigDecimal support is present. - */ - @Test - public void testObjectToBigDecimal() { - double value = 1412078745.01074; - Reader reader = new StringReader("[{\"value\": " + value + "}]"); - JSONTokener tokener = new JSONTokener(reader); - JSONArray array = new JSONArray(tokener); - JSONObject jsonObject = array.getJSONObject(0); - - BigDecimal current = jsonObject.getBigDecimal("value"); - BigDecimal wantedValue = BigDecimal.valueOf(value); - - assertEquals(current, wantedValue); - Util.checkJSONObjectMaps(jsonObject); - Util.checkJSONArrayMaps(array, jsonObject.getMapType()); - } - - /** - * Tests the exception portions of populateMap. - */ - @Test - public void testExceptionalBean() { - ExceptionalBean bean = new ExceptionalBean(); - final JSONObject jo = new JSONObject(bean); - assertEquals("Expected 1 key to be mapped. Instead found: "+jo.keySet().toString(), - 1, jo.length()); - assertTrue(jo.get("closeable") instanceof JSONObject); - assertTrue(jo.getJSONObject("closeable").has("string")); - Util.checkJSONObjectMaps(jo); - } - - @Test(expected=NullPointerException.class) - public void testPutNullBoolean() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, false); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullCollection() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, Collections.emptySet()); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullDouble() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, 0.0d); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullFloat() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, 0.0f); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullInt() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, 0); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullLong() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, 0L); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullMap() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, Collections.emptyMap()); - fail("Expected an exception"); - } - @Test(expected=NullPointerException.class) - public void testPutNullObject() { - // null put key - JSONObject jsonObject = new JSONObject("{}"); - jsonObject.put(null, new Object()); - fail("Expected an exception"); - } - @Test(expected=JSONException.class) - public void testSelfRecursiveObject() { - // A -> A ... - RecursiveBean ObjA = new RecursiveBean("ObjA"); - ObjA.setRef(ObjA); - new JSONObject(ObjA); - fail("Expected an exception"); - } - @Test(expected=JSONException.class) - public void testLongSelfRecursiveObject() { - // B -> A -> A ... - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - ObjB.setRef(ObjA); - ObjA.setRef(ObjA); - new JSONObject(ObjB); - fail("Expected an exception"); - } - @Test(expected=JSONException.class) - public void testSimpleRecursiveObject() { - // B -> A -> B ... - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - ObjB.setRef(ObjA); - ObjA.setRef(ObjB); - new JSONObject(ObjA); - fail("Expected an exception"); - } - @Test(expected=JSONException.class) - public void testLongRecursiveObject() { - // D -> C -> B -> A -> D ... - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - RecursiveBean ObjC = new RecursiveBean("ObjC"); - RecursiveBean ObjD = new RecursiveBean("ObjD"); - ObjC.setRef(ObjB); - ObjB.setRef(ObjA); - ObjD.setRef(ObjC); - ObjA.setRef(ObjD); - new JSONObject(ObjB); - fail("Expected an exception"); - } - @Test(expected=JSONException.class) - public void testRepeatObjectRecursive() { - // C -> B -> A -> D -> C ... - // -> D -> C ... - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - RecursiveBean ObjC = new RecursiveBean("ObjC"); - RecursiveBean ObjD = new RecursiveBean("ObjD"); - ObjC.setRef(ObjB); - ObjB.setRef(ObjA); - ObjB.setRef2(ObjD); - ObjA.setRef(ObjD); - ObjD.setRef(ObjC); - new JSONObject(ObjC); - fail("Expected an exception"); - } - @Test - public void testRepeatObjectNotRecursive() { - // C -> B -> A - // -> A - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - RecursiveBean ObjC = new RecursiveBean("ObjC"); - ObjC.setRef(ObjA); - ObjB.setRef(ObjA); - ObjB.setRef2(ObjA); - JSONObject j0 = new JSONObject(ObjC); - JSONObject j1 = new JSONObject(ObjB); - JSONObject j2 = new JSONObject(ObjA); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - j0, j1, j2 - ))); - } - @Test - public void testLongRepeatObjectNotRecursive() { - // C -> B -> A -> D -> E - // -> D -> E - RecursiveBean ObjA = new RecursiveBean("ObjA"); - RecursiveBean ObjB = new RecursiveBean("ObjB"); - RecursiveBean ObjC = new RecursiveBean("ObjC"); - RecursiveBean ObjD = new RecursiveBean("ObjD"); - RecursiveBean ObjE = new RecursiveBean("ObjE"); - ObjC.setRef(ObjB); - ObjB.setRef(ObjA); - ObjB.setRef2(ObjD); - ObjA.setRef(ObjD); - ObjD.setRef(ObjE); - JSONObject j0 = new JSONObject(ObjC); - JSONObject j1 = new JSONObject(ObjB); - JSONObject j2 = new JSONObject(ObjA); - JSONObject j3 = new JSONObject(ObjD); - JSONObject j4 = new JSONObject(ObjE); - Util.checkJSONObjectsMaps(new ArrayList(Arrays.asList( - j0, j1, j2, j3, j4 - ))); - } - @Test(expected=JSONException.class) - public void testRecursiveEquals() { - RecursiveBeanEquals a = new RecursiveBeanEquals("same"); - a.setRef(a); - JSONObject j0 = new JSONObject(a); - Util.checkJSONObjectMaps(j0); - } - @Test - public void testNotRecursiveEquals() { - RecursiveBeanEquals a = new RecursiveBeanEquals("same"); - RecursiveBeanEquals b = new RecursiveBeanEquals("same"); - RecursiveBeanEquals c = new RecursiveBeanEquals("same"); - a.setRef(b); - b.setRef(c); - JSONObject j0 = new JSONObject(a); - Util.checkJSONObjectMaps(j0); - } - - - @Test - public void testIssue548ObjectWithEmptyJsonArray() { - JSONObject jsonObject = new JSONObject("{\"empty_json_array\": []}"); - assertTrue("missing expected key 'empty_json_array'", jsonObject.has("empty_json_array")); - assertNotNull("'empty_json_array' should be an array", jsonObject.getJSONArray("empty_json_array")); - assertEquals("'empty_json_array' should have a length of 0", 0, jsonObject.getJSONArray("empty_json_array").length()); - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Tests if calling JSONObject clear() method actually makes the JSONObject empty - */ - @Test(expected = JSONException.class) - public void jsonObjectClearMethodTest() { - //Adds random stuff to the JSONObject - JSONObject jsonObject = new JSONObject(); - jsonObject.put("key1", 123); - jsonObject.put("key2", "456"); - jsonObject.put("key3", new JSONObject()); - jsonObject.clear(); //Clears the JSONObject - assertTrue("expected jsonObject.length() == 0", jsonObject.length() == 0); //Check if its length is 0 - jsonObject.getInt("key1"); //Should throws org.json.JSONException: JSONObject["asd"] not found - Util.checkJSONObjectMaps(jsonObject); - } - - /** - * Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654 - */ - @Test(expected = JSONException.class) - public void issue654StackOverflowInput() { - //String base64Bytes ="eyJHWiI6Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e1stMC0wLHt7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7ewl7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e1stMCkwLHt7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e1stMC0wLHt7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7CXt7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7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0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0)0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0)0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{s{{{{{{{"; - JSONObject json_input = new JSONObject(input); - assertNotNull(json_input); - fail("Excepected Exception."); - Util.checkJSONObjectMaps(json_input); - } - - /** - * Tests for incorrect object/array nesting. See https://github.com/stleary/JSON-java/issues/654 - */ - @Test(expected = JSONException.class) - public void issue654IncorrectNestingNoKey1() { - JSONObject json_input = new JSONObject("{{\"a\":0}}"); - assertNotNull(json_input); - fail("Expected Exception."); - } - - /** - * Tests for incorrect object/array nesting. See https://github.com/stleary/JSON-java/issues/654 - */ - @Test(expected = JSONException.class) - public void issue654IncorrectNestingNoKey2() { - JSONObject json_input = new JSONObject("{[\"a\"]}"); - assertNotNull(json_input); - fail("Excepected Exception."); - } - - /** - * Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654 - */ - @Ignore("This test relies on system constraints and may not always pass. See: https://github.com/stleary/JSON-java/issues/821") - @Test(expected = JSONException.class) - public void issue654StackOverflowInputWellFormed() { - //String input = new String(java.util.Base64.getDecoder().decode(base64Bytes)); - final InputStream resourceAsStream = JSONObjectTest.class.getClassLoader().getResourceAsStream("Issue654WellFormedObject.json"); - JSONTokener tokener = new JSONTokener(resourceAsStream); - JSONObject json_input = new JSONObject(tokener); - assertNotNull(json_input); - fail("Excepected Exception due to stack overflow."); - } - - @Test - public void testIssue682SimilarityOfJSONString() { - JSONObject jo1 = new JSONObject() - .put("a", new MyJsonString()) - .put("b", 2); - JSONObject jo2 = new JSONObject() - .put("a", new MyJsonString()) - .put("b", 2); - assertTrue(jo1.similar(jo2)); - - JSONObject jo3 = new JSONObject() - .put("a", new JSONString() { - @Override - public String toJSONString() { - return "\"different value\""; - } - }) - .put("b", 2); - assertFalse(jo1.similar(jo3)); - } - - private static final Number[] NON_FINITE_NUMBERS = { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, - Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN }; - - @Test - public void issue713MapConstructorWithNonFiniteNumbers() { - for (Number nonFinite : NON_FINITE_NUMBERS) { - Map map = new HashMap<>(); - map.put("a", nonFinite); - - assertThrows(JSONException.class, () -> new JSONObject(map)); - } - } - - @Test - public void issue713BeanConstructorWithNonFiniteNumbers() { - for (Number nonFinite : NON_FINITE_NUMBERS) { - GenericBean bean = new GenericBean<>(nonFinite); - assertThrows(JSONException.class, () -> new JSONObject(bean)); - } - } - - @Test(expected = JSONException.class) - public void issue743SerializationMap() { - HashMap map = new HashMap<>(); - map.put("t", map); - JSONObject object = new JSONObject(map); - String jsonString = object.toString(); - } - - @Test(expected = JSONException.class) - public void testCircularReferenceMultipleLevel() { - HashMap inside = new HashMap<>(); - HashMap jsonObject = new HashMap<>(); - inside.put("inside", jsonObject); - jsonObject.put("test", inside); - new JSONObject(jsonObject); - } - - @Test - public void issue743SerializationMapWith512Objects() { - HashMap map = buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); - JSONObject object = new JSONObject(map); - String jsonString = object.toString(); - } - - @Test - public void issue743SerializationMapWith1000Objects() { - HashMap map = buildNestedMap(1000); - JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000); - JSONObject object = new JSONObject(map, parserConfiguration); - String jsonString = object.toString(); - } - - @Test(expected = JSONException.class) - public void issue743SerializationMapWith1001Objects() { - HashMap map = buildNestedMap(1001); - JSONObject object = new JSONObject(map); - String jsonString = object.toString(); - } - - @Test(expected = JSONException.class) - public void testCircleReferenceFirstLevel() { - Map jsonObject = new HashMap<>(); - - jsonObject.put("test", jsonObject); - - new JSONObject(jsonObject, new JSONParserConfiguration()); - } - - @Test(expected = StackOverflowError.class) - public void testCircleReferenceMultiplyLevel_notConfigured_expectedStackOverflow() { - Map inside = new HashMap<>(); - - Map jsonObject = new HashMap<>(); - inside.put("test", jsonObject); - jsonObject.put("test", inside); - - new JSONObject(jsonObject, new JSONParserConfiguration().withMaxNestingDepth(99999)); - } - - @Test(expected = JSONException.class) - public void testCircleReferenceMultiplyLevel_configured_expectedJSONException() { - Map inside = new HashMap<>(); - - Map jsonObject = new HashMap<>(); - inside.put("test", jsonObject); - jsonObject.put("test", inside); - - new JSONObject(jsonObject, new JSONParserConfiguration()); - } - - @Test - public void testDifferentKeySameInstanceNotACircleReference() { - Map map1 = new HashMap<>(); - Map map2 = new HashMap<>(); - - map1.put("test1", map2); - map1.put("test2", map2); - - new JSONObject(map1); - } - - @Test - public void clarifyCurrentBehavior() { - // Behavior documented in #653 optLong vs getLong inconsistencies - // This problem still exists. - // Internally, both number_1 and number_2 are stored as strings. This is reasonable since they are parsed as strings. - // However, getLong and optLong should return similar results - JSONObject json = new JSONObject("{\"number_1\":\"01234\", \"number_2\": \"332211\"}"); - assertEquals(json.getLong("number_1"), 1234L); - assertEquals(json.optLong("number_1"), 0); //THIS VALUE IS NOT RETURNED AS A NUMBER - assertEquals(json.getLong("number_2"), 332211L); - assertEquals(json.optLong("number_2"), 332211L); - - // Behavior documented in #826 JSONObject parsing 0-led numeric strings as ints - // After reverting the code, personId is stored as a string, and the behavior is as expected - String personId = "\"0123\""; - JSONObject j1 = new JSONObject("{\"personId\": " + personId + "}"); - assertEquals(j1.getString("personId"), "0123"); - - // Also #826. Here is input with missing quotes. Because of the leading zero, it should not be parsed as a number. - // This example was mentioned in the same ticket - // After reverting the code, personId is stored as a string, and the behavior is as expected - - // TODO: the next two tests fail due to an ambiguity in parsing the value. - // non-StrictMode - it is a valid non-numeric value - // strictMode - Since it is non-numeric, quotes are required. - // This test should be extracted to its own unit test. The result should depend on the strictMode setting. - // For now it s commented out -// JSONObject j2 = new JSONObject("{\"personId\":0123}"); -// assertEquals(j2.getString("personId"), "0123"); - - // Behavior uncovered while working on the code - // All of the values are stored as strings except for hex4, which is stored as a number. This is probably incorrect -// JSONObject j3 = new JSONObject("{ " + -// "\"hex1\": \"010e4\", \"hex2\": \"00f0\", \"hex3\": \"0011\", " + -// "\"hex4\": 00e0, \"hex5\": 00f0, \"hex6\": 0011 }"); -// assertEquals(j3.getString("hex1"), "010e4"); -// assertEquals(j3.getString("hex2"), "00f0"); -// assertEquals(j3.getString("hex3"), "0011"); -// assertEquals(j3.getLong("hex4"), 0, .1); -// assertEquals(j3.getString("hex5"), "00f0"); -// assertEquals(j3.getString("hex6"), "0011"); - } - - /** - * Method to build nested map of max maxDepth - * - * @param maxDepth - * @return - */ - public static HashMap buildNestedMap(int maxDepth) { - if (maxDepth <= 0) { - return new HashMap<>(); - } - HashMap nestedMap = new HashMap<>(); - nestedMap.put("t", buildNestedMap(maxDepth - 1)); - return nestedMap; - } - -} diff --git a/src/test/java/org/json/junit/JSONParserConfigurationTest.java b/src/test/java/org/json/junit/JSONParserConfigurationTest.java deleted file mode 100644 index 427aad4df..000000000 --- a/src/test/java/org/json/junit/JSONParserConfigurationTest.java +++ /dev/null @@ -1,313 +0,0 @@ -package org.json.junit; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONParserConfiguration; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; - -public class JSONParserConfigurationTest { - - private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}"; - - @Test(expected = JSONException.class) - public void testThrowException() { - new JSONObject(TEST_SOURCE); - } - - @Test - public void testOverwrite() { - JSONObject jsonObject = new JSONObject(TEST_SOURCE, - new JSONParserConfiguration().withOverwriteDuplicateKey(true)); - - assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key")); - } - - @Test - public void givenInvalidInputArrays_testStrictModeTrue_shouldThrowJsonException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - List strictModeInputTestCases = getNonCompliantJSONList(); - - strictModeInputTestCases.forEach( - testCase -> assertThrows("expected non-compliant array but got instead: " + testCase, JSONException.class, - () -> new JSONArray(testCase, jsonParserConfiguration))); - } - - @Test - public void givenEmptyArray_testStrictModeTrue_shouldNotThrowJsonException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[]"; - - JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration); - - assertEquals(testCase, jsonArray.toString()); - } - - @Test - public void givenValidDoubleArray_testStrictModeTrue_shouldNotThrowJsonException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[[\"c\"], [10.2], [true, false, true]]"; - - JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration); - JSONArray arrayShouldContainStringAt0 = jsonArray.getJSONArray(0); - JSONArray arrayShouldContainNumberAt0 = jsonArray.getJSONArray(1); - JSONArray arrayShouldContainBooleanAt0 = jsonArray.getJSONArray(2); - - assertTrue(arrayShouldContainStringAt0.get(0) instanceof String); - assertTrue(arrayShouldContainNumberAt0.get(0) instanceof Number); - assertTrue(arrayShouldContainBooleanAt0.get(0) instanceof Boolean); - } - - @Test - public void givenValidEmptyArrayInsideArray_testStrictModeTrue_shouldNotThrowJsonException(){ - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[[]]"; - - JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration); - - assertEquals(testCase, jsonArray.toString()); - } - - @Test - public void givenValidEmptyArrayInsideArray_testStrictModeFalse_shouldNotThrowJsonException(){ - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(false); - - String testCase = "[[]]"; - - JSONArray jsonArray = new JSONArray(testCase, jsonParserConfiguration); - - assertEquals(testCase, jsonArray.toString()); - } - - @Test - public void givenInvalidString_testStrictModeTrue_shouldThrowJsonException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[badString]"; - - JSONException je = assertThrows(JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration)); - - assertEquals("Value 'badString' is not surrounded by quotes at 10 [character 11 line 1]", je.getMessage()); - } - - @Test - public void allowNullInStrictMode() { - String expected = "[null]"; - JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true)); - assertEquals(expected, jsonArray.toString()); - } - - @Test - public void shouldHandleNumericArray() { - String expected = "[10]"; - JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true)); - assertEquals(expected, jsonArray.toString()); - } - - @Test - public void givenCompliantJSONArrayFile_testStrictModeTrue_shouldNotThrowAnyException() throws IOException { - try (Stream lines = Files.lines(Paths.get("src/test/resources/compliantJsonArray.json"))) { - String compliantJsonArrayAsString = lines.collect(Collectors.joining()); - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - new JSONArray(compliantJsonArrayAsString, jsonParserConfiguration); - } - - } - - @Test - public void givenInvalidInputArrays_testStrictModeFalse_shouldNotThrowAnyException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(false); - - List strictModeInputTestCases = getNonCompliantJSONList(); - - strictModeInputTestCases.forEach(testCase -> new JSONArray(testCase, jsonParserConfiguration)); - } - - @Test - public void givenInvalidInputArray_testStrictModeTrue_shouldThrowInvalidCharacterErrorMessage() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[1,2];[3,4]"; - - JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase, - JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration)); - - assertEquals("invalid character ';' found after end of array at 6 [character 7 line 1]", je.getMessage()); - } - - @Test - public void givenInvalidInputArrayWithNumericStrings_testStrictModeTrue_shouldThrowInvalidCharacterErrorMessage() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[\"1\",\"2\"];[3,4]"; - - JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase, - JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration)); - - assertEquals("invalid character ';' found after end of array at 10 [character 11 line 1]", je.getMessage()); - } - - @Test - public void givenInvalidInputArray_testStrictModeTrue_shouldThrowValueNotSurroundedByQuotesErrorMessage() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[{\"test\": implied}]"; - - JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase, - JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration)); - - assertEquals("Value 'implied' is not surrounded by quotes at 17 [character 18 line 1]", je.getMessage()); - } - - @Test - public void givenInvalidInputArray_testStrictModeFalse_shouldNotThrowAnyException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(false); - - String testCase = "[{\"test\": implied}]"; - - new JSONArray(testCase, jsonParserConfiguration); - } - - @Test - public void givenNonCompliantQuotes_testStrictModeTrue_shouldThrowJsonExceptionWithConcreteErrorDescription() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCaseOne = "[\"abc', \"test\"]"; - String testCaseTwo = "['abc\", \"test\"]"; - String testCaseThree = "['abc']"; - String testCaseFour = "[{'testField': \"testValue\"}]"; - - JSONException jeOne = assertThrows(JSONException.class, - () -> new JSONArray(testCaseOne, jsonParserConfiguration)); - JSONException jeTwo = assertThrows(JSONException.class, - () -> new JSONArray(testCaseTwo, jsonParserConfiguration)); - JSONException jeThree = assertThrows(JSONException.class, - () -> new JSONArray(testCaseThree, jsonParserConfiguration)); - JSONException jeFour = assertThrows(JSONException.class, - () -> new JSONArray(testCaseFour, jsonParserConfiguration)); - - assertEquals( - "Value 'test' is not surrounded by quotes at 13 [character 14 line 1]", - jeOne.getMessage()); - assertEquals( - "Single quote wrap not allowed in strict mode at 2 [character 3 line 1]", - jeTwo.getMessage()); - assertEquals( - "Single quote wrap not allowed in strict mode at 2 [character 3 line 1]", - jeThree.getMessage()); - assertEquals( - "Single quote wrap not allowed in strict mode at 3 [character 4 line 1]", - jeFour.getMessage()); - } - - @Test - public void givenUnbalancedQuotes_testStrictModeFalse_shouldThrowJsonException() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(false); - - String testCaseOne = "[\"abc', \"test\"]"; - String testCaseTwo = "['abc\", \"test\"]"; - - JSONException jeOne = assertThrows(JSONException.class, - () -> new JSONArray(testCaseOne, jsonParserConfiguration)); - JSONException jeTwo = assertThrows(JSONException.class, - () -> new JSONArray(testCaseTwo, jsonParserConfiguration)); - - assertEquals("Unterminated string. Character with int code 0 is not allowed within a quoted string. at 15 [character 16 line 1]", jeOne.getMessage()); - assertEquals("Unterminated string. Character with int code 0 is not allowed within a quoted string. at 15 [character 16 line 1]", jeTwo.getMessage()); - } - - - @Test - public void givenInvalidInputArray_testStrictModeTrue_shouldThrowKeyNotSurroundedByQuotesErrorMessage() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withStrictMode(true); - - String testCase = "[{test: implied}]"; - JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase, - JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration)); - - assertEquals("Value 'test' is not surrounded by quotes at 6 [character 7 line 1]", je.getMessage()); - } - - @Test - public void verifyDuplicateKeyThenMaxDepth() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withOverwriteDuplicateKey(true) - .withMaxNestingDepth(42); - - assertEquals(42, jsonParserConfiguration.getMaxNestingDepth()); - assertTrue(jsonParserConfiguration.isOverwriteDuplicateKey()); - } - - @Test - public void verifyMaxDepthThenDuplicateKey() { - JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() - .withMaxNestingDepth(42) - .withOverwriteDuplicateKey(true); - - assertTrue(jsonParserConfiguration.isOverwriteDuplicateKey()); - assertEquals(42, jsonParserConfiguration.getMaxNestingDepth()); - } - - /** - * This method contains short but focused use-case samples and is exclusively used to test strictMode unit tests in - * this class. - * - * @return List with JSON strings. - */ - private List getNonCompliantJSONList() { - return Arrays.asList( - "[1],", - "[1,]", - "[[1]\"sa\",[2]]a", - "[1],\"dsa\": \"test\"", - "[[a]]", - "[]asdf", - "[]]", - "[]}", - "[][", - "[]{", - "[],", - "[]:", - "[],[", - "[],{", - "[1,2];[3,4]", - "[test]", - "[{'testSingleQuote': 'testSingleQuote'}]", - "[1, 2,3]:[4,5]", - "[{test: implied}]", - "[{\"test\": implied}]", - "[{\"number\":\"7990154836330\",\"color\":'c'},{\"number\":8784148854580,\"color\":RosyBrown},{\"number\":\"5875770107113\",\"color\":\"DarkSeaGreen\"}]", - "[{test: \"implied\"}]"); - } -} diff --git a/src/test/java/org/json/junit/JSONPointerTest.java b/src/test/java/org/json/junit/JSONPointerTest.java deleted file mode 100644 index 45c7dbd3d..000000000 --- a/src/test/java/org/json/junit/JSONPointerTest.java +++ /dev/null @@ -1,399 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.InputStream; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.json.JSONPointer; -import org.json.JSONPointerException; -import org.json.JSONTokener; -import org.junit.Test; - -public class JSONPointerTest { - - private static final JSONObject document; - private static final String EXPECTED_COMPLETE_DOCUMENT = "{\"\":0,\" \":7,\"g|h\":4,\"c%d\":2,\"k\\\"l\":6,\"a/b\":1,\"i\\\\j\":5," + - "\"obj\":{\"\":{\"\":\"empty key of an object with an empty key\",\"subKey\":\"Some other value\"}," + - "\"other~key\":{\"another/key\":[\"val\"]},\"key\":\"value\"},\"foo\":[\"bar\",\"baz\"],\"e^f\":3," + - "\"m~n\":8}"; - - - static { - @SuppressWarnings("resource") - InputStream resourceAsStream = JSONPointerTest.class.getClassLoader().getResourceAsStream("jsonpointer-testdoc.json"); - if(resourceAsStream == null) { - throw new ExceptionInInitializerError("Unable to locate test file. Please check your development environment configuration"); - } - document = new JSONObject(new JSONTokener(resourceAsStream)); - } - - private Object query(String pointer) { - return new JSONPointer(pointer).queryFrom(document); - } - - @Test - public void emptyPointer() { - assertTrue(new JSONObject(EXPECTED_COMPLETE_DOCUMENT).similar(query(""))); - } - - @SuppressWarnings("unused") - @Test(expected = NullPointerException.class) - public void nullPointer() { - new JSONPointer((String) null); - } - - @Test - public void objectPropertyQuery() { - assertEquals("[\"bar\",\"baz\"]", query("/foo").toString()); - } - - @Test - public void arrayIndexQuery() { - assertEquals("bar", query("/foo/0")); - } - - @Test(expected = JSONPointerException.class) - public void stringPropOfArrayFailure() { - query("/foo/bar"); - } - - @Test - public void queryByEmptyKey() { - assertEquals(0, query("/")); - } - - @Test - public void queryByEmptyKeySubObject() { - JSONObject json = new JSONObject("{\"\":\"empty key of an object with an empty key\",\"subKey\":\"Some" + - " other value\"}"); - JSONObject obj = (JSONObject) query("/obj/"); - assertTrue(json.similar(obj)); - } - - @Test - public void queryByEmptyKeySubObjectSubOject() { - assertEquals("empty key of an object with an empty key", query("/obj//")); - } - - @Test - public void queryByEmptyKeySubObjectValue() { - assertEquals("Some other value", query("/obj//subKey")); - } - - @Test - public void slashEscaping() { - assertEquals(1, query("/a~1b")); - } - - @Test - public void tildeEscaping() { - assertEquals(8, query("/m~0n")); - } - - /** - * We pass backslashes as-is - * - * @see rfc6901 section 3 - */ - @Test - public void backslashHandling() { - assertEquals(5, query("/i\\j")); - } - - /** - * We pass quotations as-is - * - * @see rfc6901 section 3 - */ - @Test - public void quotationHandling() { - assertEquals(6, query("/k\"l")); - } - - @Test - public void whitespaceKey() { - assertEquals(7, query("/ ")); - } - - @Test - public void uriFragmentNotation() { - assertEquals("[\"bar\",\"baz\"]", query("#/foo").toString()); - } - - @Test - public void uriFragmentNotationRoot() { - assertTrue(new JSONObject(EXPECTED_COMPLETE_DOCUMENT).similar(query("#"))); - } - - @Test - public void uriFragmentPercentHandling() { - assertEquals(2, query("#/c%25d")); - assertEquals(3, query("#/e%5Ef")); - assertEquals(4, query("#/g%7Ch")); - assertEquals(8, query("#/m~0n")); - } - - @SuppressWarnings("unused") - @Test(expected = IllegalArgumentException.class) - public void syntaxError() { - new JSONPointer("key"); - } - - @Test(expected = JSONPointerException.class) - public void arrayIndexFailure() { - query("/foo/2"); - } - - @Test(expected = JSONPointerException.class) - public void primitiveFailure() { - query("/obj/key/failure"); - } - - @Test - public void builderTest() { - JSONPointer pointer = JSONPointer.builder() - .append("obj") - .append("other~key").append("another/key") - .append(0) - .build(); - assertEquals("val", pointer.queryFrom(document)); - } - - @Test(expected = NullPointerException.class) - public void nullToken() { - JSONPointer.builder().append(null); - } - - @Test - public void toStringEscaping() { - JSONPointer pointer = JSONPointer.builder() - .append("obj") - .append("other~key").append("another/key") - .append("\"") - .append(0) - .build(); - assertEquals("/obj/other~0key/another~1key/\"/0", pointer.toString()); - } - - @Test - public void emptyPointerToString() { - assertEquals("", new JSONPointer("").toString()); - } - - @Test - public void toURIFragment() { - assertEquals("#/c%25d", new JSONPointer("/c%d").toURIFragment()); - assertEquals("#/e%5Ef", new JSONPointer("/e^f").toURIFragment()); - assertEquals("#/g%7Ch", new JSONPointer("/g|h").toURIFragment()); - assertEquals("#/m%7En", new JSONPointer("/m~n").toURIFragment()); - } - - @Test - public void tokenListIsCopiedInConstructor() { - JSONPointer.Builder b = JSONPointer.builder().append("key1"); - JSONPointer jp1 = b.build(); - b.append("key2"); - JSONPointer jp2 = b.build(); - if(jp1.toString().equals(jp2.toString())) { - fail("Oops, my pointers are sharing a backing array"); - } - } - - /** - * Coverage for JSONObject query(String) - */ - @Test - public void queryFromJSONObject() { - String str = "{"+ - "\"stringKey\":\"hello world!\","+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\": {"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - Object obj = jsonObject.query("/stringKey"); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonObject.query("/arrayKey/1"); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonObject.query("/objectKey/b"); - assertTrue("Expected bVal", "bVal".equals(obj)); - try { - obj = jsonObject.query("/a/b/c"); - assertTrue("Expected JSONPointerException", false); - } catch (JSONPointerException e) { - assertTrue("Expected bad key/value exception", - "value [null] is not an array or object therefore its key b cannot be resolved". - equals(e.getMessage())); - } - } - - /** - * Coverage for JSONObject query(JSONPointer) - */ - @Test - public void queryFromJSONObjectUsingPointer() { - String str = "{"+ - "\"stringKey\":\"hello world!\","+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\": {"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - Object obj = jsonObject.query(new JSONPointer("/stringKey")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonObject.query(new JSONPointer("/arrayKey/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonObject.query(new JSONPointer("/objectKey/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); - try { - obj = jsonObject.query(new JSONPointer("/a/b/c")); - assertTrue("Expected JSONPointerException", false); - } catch (JSONPointerException e) { - assertTrue("Expected bad key/value exception", - "value [null] is not an array or object therefore its key b cannot be resolved". - equals(e.getMessage())); - } - } - - /** - * Coverage for JSONObject optQuery(JSONPointer) - */ - @Test - public void optQueryFromJSONObjectUsingPointer() { - String str = "{"+ - "\"stringKey\":\"hello world!\","+ - "\"arrayKey\":[0,1,2],"+ - "\"objectKey\": {"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - Object obj = jsonObject.optQuery(new JSONPointer("/stringKey")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonObject.optQuery(new JSONPointer("/arrayKey/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonObject.optQuery(new JSONPointer("/objectKey/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); - obj = jsonObject.optQuery(new JSONPointer("/a/b/c")); - assertTrue("Expected null", obj == null); - } - - /** - * Coverage for JSONArray query(String) - */ - @Test - public void queryFromJSONArray() { - String str = "["+ - "\"hello world!\","+ - "[0,1,2],"+ - "{"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "]"; - JSONArray jsonArray = new JSONArray(str); - Object obj = jsonArray.query("/0"); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonArray.query("/1/1"); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonArray.query("/2/b"); - assertTrue("Expected bVal", "bVal".equals(obj)); - try { - obj = jsonArray.query("/a/b/c"); - assertTrue("Expected JSONPointerException", false); - } catch (JSONPointerException e) { - assertTrue("Expected bad index exception", - "a is not an array index".equals(e.getMessage())); - } - } - - /** - * Coverage for JSONArray query(JSONPointer) - */ - @Test - public void queryFromJSONArrayUsingPointer() { - String str = "["+ - "\"hello world!\","+ - "[0,1,2],"+ - "{"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "]"; - JSONArray jsonArray = new JSONArray(str); - Object obj = jsonArray.query(new JSONPointer("/0")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonArray.query(new JSONPointer("/1/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonArray.query(new JSONPointer("/2/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); - try { - obj = jsonArray.query(new JSONPointer("/a/b/c")); - assertTrue("Expected JSONPointerException", false); - } catch (JSONPointerException e) { - assertTrue("Expected bad index exception", - "a is not an array index".equals(e.getMessage())); - } - } - - /** - * Coverage for JSONArray optQuery(JSONPointer) - */ - @Test - public void optQueryFromJSONArrayUsingPointer() { - String str = "["+ - "\"hello world!\","+ - "[0,1,2],"+ - "{"+ - "\"a\":\"aVal\","+ - "\"b\":\"bVal\""+ - "}"+ - "]"; - JSONArray jsonArray = new JSONArray(str); - Object obj = jsonArray.optQuery(new JSONPointer("/0")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); - obj = jsonArray.optQuery(new JSONPointer("/1/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); - obj = jsonArray.optQuery(new JSONPointer("/2/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); - obj = jsonArray.optQuery(new JSONPointer("/a/b/c")); - assertTrue("Expected null", obj == null); - } - - /** - * When creating a jsonObject we need to parse escaped characters "\\\\" - * --> it's the string representation of "\\", so when query'ing via the JSONPointer - * we DON'T escape them - * - */ - @Test - public void queryFromJSONObjectUsingPointer0() { - String str = "{"+ - "\"string\\\\\\\\Key\":\"hello world!\","+ - - "\"\\\\\":\"slash test\"," + - "}"+ - "}"; - JSONObject jsonObject = new JSONObject(str); - //Summary of issue: When a KEY in the jsonObject is "\\\\" --> it's held - // as "\\" which means when querying, we need to use "\\" - Object twoBackslahObj = jsonObject.optQuery(new JSONPointer("/\\")); - assertEquals("slash test", twoBackslahObj); - - Object fourBackslashObj = jsonObject.optQuery(new JSONPointer("/string\\\\Key")); - assertEquals("hello world!", fourBackslashObj); - } -} diff --git a/src/test/java/org/json/junit/JSONStringTest.java b/src/test/java/org/json/junit/JSONStringTest.java deleted file mode 100644 index 235df1806..000000000 --- a/src/test/java/org/json/junit/JSONStringTest.java +++ /dev/null @@ -1,401 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import java.io.StringWriter; -import java.util.*; - -import org.json.*; -import org.junit.Test; - -/** - * Tests for JSONString implementations, and the difference between - * {@link JSONObject#valueToString} and {@link JSONObject#writeValue}. - */ -public class JSONStringTest { - - /** - * This tests the JSONObject.writeValue() method. We can't test directly - * due to it being a package-protected method. Instead, we can call - * JSONArray.write(), which delegates the writing of each entry to - * writeValue(). - */ - @Test - public void writeValues() throws Exception { - JSONArray jsonArray = new JSONArray(); - jsonArray.put((Object)null); - - StringWriter writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[null]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put(JSONObject.NULL); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[null]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put(new JSONObject()); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[{}]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put(new JSONArray()); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[[]]".equals(output)); - - jsonArray = new JSONArray(); - Map singleMap = Collections.singletonMap("key1", "value1"); - jsonArray.put((Object)singleMap); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[{\"key1\":\"value1\"}]".equals(output)); - - jsonArray = new JSONArray(); - List singleList = Collections.singletonList("entry1"); - jsonArray.put((Object)singleList); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[[\"entry1\"]]".equals(output)); - - jsonArray = new JSONArray(); - int[] intArray = new int[] { 1, 2, 3 }; - jsonArray.put(intArray); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[[1,2,3]]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put(24); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[24]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put("string value"); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[\"string value\"]".equals(output)); - - jsonArray = new JSONArray(); - jsonArray.put(true); - } finally { - writer.close(); - } - - writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[true]".equals(output)); - } finally { - writer.close(); - } - - } - - /** - * This tests the JSONObject.valueToString() method. These should be - * identical to the values above, except for the enclosing [ and ]. - */ - @SuppressWarnings("boxing") - @Test - public void valuesToString() throws Exception { - - String output = JSONObject.valueToString(null); - assertTrue("String values should be equal", "null".equals(output)); - - output = JSONObject.valueToString(JSONObject.NULL); - assertTrue("String values should be equal", "null".equals(output)); - - output = JSONObject.valueToString(new JSONObject()); - assertTrue("String values should be equal", "{}".equals(output)); - - output = JSONObject.valueToString(new JSONArray()); - assertTrue("String values should be equal", "[]".equals(output)); - - Map singleMap = Collections.singletonMap("key1", "value1"); - output = JSONObject.valueToString(singleMap); - assertTrue("String values should be equal", "{\"key1\":\"value1\"}".equals(output)); - - List singleList = Collections.singletonList("entry1"); - output = JSONObject.valueToString(singleList); - assertTrue("String values should be equal", "[\"entry1\"]".equals(output)); - - int[] intArray = new int[] { 1, 2, 3 }; - output = JSONObject.valueToString(intArray); - assertTrue("String values should be equal", "[1,2,3]".equals(output)); - - output = JSONObject.valueToString(24); - assertTrue("String values should be equal", "24".equals(output)); - - output = JSONObject.valueToString("string value"); - assertTrue("String values should be equal", "\"string value\"".equals(output)); - - output = JSONObject.valueToString(true); - assertTrue("String values should be equal", "true".equals(output)); - - } - - /** - * Test what happens when toJSONString() returns a well-formed JSON value. - * This is the usual case. - */ - @Test - public void testJSONStringValue() throws Exception { - JSONStringValue jsonString = new JSONStringValue(); - JSONArray jsonArray = new JSONArray(); - - jsonArray.put(jsonString); - - StringWriter writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[\"the JSON string value\"]".equals(output)); - - output = JSONObject.valueToString(jsonString); - assertTrue("String values should be equal", "\"the JSON string value\"".equals(output)); - } finally { - writer.close(); - } - } - - /** - * Test what happens when toJSONString() returns null. In one case, - * use the object's toString() method. In the other, throw a JSONException. - */ - @Test - public void testJSONNullStringValue() throws Exception { - JSONNullStringValue jsonString = new JSONNullStringValue(); - JSONArray jsonArray = new JSONArray(); - - jsonArray.put(jsonString); - - StringWriter writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[\"the toString value\"]".equals(output)); - - // The only different between writeValue() and valueToString(): - // in this case, valueToString throws a JSONException - try { - output = JSONObject.valueToString(jsonString); - fail("Expected an exception, got a String value"); - } catch (Exception e) { - assertTrue("Expected JSONException", e instanceof JSONException); - assertTrue("Exception message does not match", "Bad value from toJSONString: null".equals(e.getMessage())); - } - } finally { - writer.close(); - } - } - - /** - * Test what happens when toJSONString() returns an exception. In both - * cases, a JSONException is thrown, with the cause and message set from - * the original exception. - */ - @Test - public void testJSONStringExceptionValue() { - JSONStringExceptionValue jsonString = new JSONStringExceptionValue(); - JSONArray jsonArray = new JSONArray(); - - jsonArray.put(jsonString); - - StringWriter writer = new StringWriter(); - try { - jsonArray.write(writer).toString(); - fail("Expected an exception, got a String value"); - } catch (JSONException e) { - assertEquals("Unable to write JSONArray value at index: 0", e.getMessage()); - } catch(Exception e) { - fail("Expected JSONException"); - } finally { - try { - writer.close(); - } catch (Exception e){} - } - - try { - JSONObject.valueToString(jsonString); - fail("Expected an exception, got a String value"); - } catch (JSONException e) { - assertTrue("Exception message does not match", "the exception value".equals(e.getMessage())); - } catch(Exception e) { - fail("Expected JSONException"); - } - } - - /** - * Test what happens when a Java object's toString() returns a String value. - * This is the usual case. - */ - @Test - public void testStringValue() throws Exception { - StringValue nonJsonString = new StringValue(); - JSONArray jsonArray = new JSONArray(); - - jsonArray.put(nonJsonString); - - StringWriter writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[\"the toString value for StringValue\"]".equals(output)); - - output = JSONObject.valueToString(nonJsonString); - assertTrue("String values should be equal", "\"the toString value for StringValue\"".equals(output)); - } finally { - writer.close(); - } - } - - /** - * Test what happens when a Java object's toString() returns null. - * Defaults to empty string. - */ - @Test - public void testNullStringValue() throws Exception { - NullStringValue nonJsonString = new NullStringValue(); - JSONArray jsonArray = new JSONArray(); - - jsonArray.put(nonJsonString); - - StringWriter writer = new StringWriter(); - try { - String output = jsonArray.write(writer).toString(); - assertTrue("String values should be equal", "[\"\"]".equals(output)); - - output = JSONObject.valueToString(nonJsonString); - assertTrue("String values should be equal", "\"\"".equals(output)); - } finally { - writer.close(); - } - } - - @Test - public void testEnumJSONString() { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("key", MyEnum.MY_ENUM); - assertEquals("{\"key\":\"myJsonString\"}", jsonObject.toString()); - } - - private enum MyEnum implements JSONString { - MY_ENUM; - - @Override - public String toJSONString() { - return "\"myJsonString\""; - } - } - - /** - * A JSONString that returns a valid JSON string value. - */ - private static final class JSONStringValue implements JSONString { - - @Override - public String toJSONString() { - return "\"the JSON string value\""; - } - - @Override - public String toString() { - return "the toString value for JSONStringValue"; - } - } - - /** - * A JSONString that returns null when calling toJSONString(). - */ - private static final class JSONNullStringValue implements JSONString { - - @Override - public String toJSONString() { - return null; - } - - @Override - public String toString() { - return "the toString value"; - } - } - - /** - * A JSONString that throw an exception when calling toJSONString(). - */ - private static final class JSONStringExceptionValue implements JSONString { - - @Override - public String toJSONString() { - throw new IllegalStateException("the exception value"); - } - - @Override - public String toString() { - return "the toString value for JSONStringExceptionValue"; - } - } - - public static final class StringValue { - - @Override - public String toString() { - return "the toString value for StringValue"; - } - } - - public static final class NullStringValue { - - @Override - public String toString() { - return null; - } - } -} diff --git a/src/test/java/org/json/junit/JSONStringerTest.java b/src/test/java/org/json/junit/JSONStringerTest.java deleted file mode 100644 index 0ecb9d662..000000000 --- a/src/test/java/org/json/junit/JSONStringerTest.java +++ /dev/null @@ -1,357 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.*; - -import java.math.BigDecimal; -import java.util.*; - -import org.json.*; -import org.junit.Test; - -import com.jayway.jsonpath.*; - - -/** - * Tests for JSON-Java JSONStringer and JSONWriter. - */ -public class JSONStringerTest { - - /** - * Object with a null key. - * Expects a JSONException. - */ - @Test - public void nullKeyException() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object(); - try { - jsonStringer.key(null); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Null key.". - equals(e.getMessage())); - } - } - - /** - * Add a key with no object. - * Expects a JSONException. - */ - @Test - public void outOfSequenceException() { - JSONStringer jsonStringer = new JSONStringer(); - try { - jsonStringer.key("hi"); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Misplaced key.". - equals(e.getMessage())); - } - } - - /** - * Missplace an array. - * Expects a JSONException - */ - @Test - public void missplacedArrayException() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object().endObject(); - try { - jsonStringer.array(); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Misplaced array.". - equals(e.getMessage())); - } - } - - /** - * Missplace an endErray. - * Expects a JSONException - */ - @Test - public void missplacedEndArrayException() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object(); - try { - jsonStringer.endArray(); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Misplaced endArray.". - equals(e.getMessage())); - } - } - - /** - * Missplace an endObject. - * Expects a JSONException - */ - @Test - public void missplacedEndObjectException() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.array(); - try { - jsonStringer.endObject(); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Misplaced endObject.". - equals(e.getMessage())); - } - } - - /** - * Missplace an object. - * Expects a JSONException. - */ - @Test - public void missplacedObjectException() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object().endObject(); - try { - jsonStringer.object(); - assertTrue("Expected an exception", false); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Misplaced object.". - equals(e.getMessage())); - } - } - - /** - * Exceeds implementation max nesting depth. - * Expects a JSONException - */ - @Test - public void exceedNestDepthException() { - try { - JSONStringer s = new JSONStringer(); - s.object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(); - s.key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(). - key("k").object().key("k").object().key("k").object().key("k").object().key("k").object(); - fail("Expected an exception message"); - } catch (JSONException e) { - assertTrue("Expected an exception message", - "Nesting too deep.". - equals(e.getMessage())); - } - } - - /** - * Build a JSON doc using JSONString API calls, - * then convert to JSONObject - */ - @Test - public void simpleObjectString() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object(); - jsonStringer.key("trueValue").value(true); - jsonStringer.key("falseValue").value(false); - jsonStringer.key("nullValue").value(null); - jsonStringer.key("stringValue").value("hello world!"); - jsonStringer.key("complexStringValue").value("h\be\tllo w\u1234orld!"); - jsonStringer.key("intValue").value(42); - jsonStringer.key("doubleValue").value(-23.45e67); - jsonStringer.endObject(); - String str = jsonStringer.toString(); - JSONObject jsonObject = new JSONObject(str); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 7 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 7); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/trueValue"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/falseValue"))); - assertTrue("expected null", JSONObject.NULL.equals(jsonObject.query("/nullValue"))); - assertTrue("expected hello world!", "hello world!".equals(jsonObject.query("/stringValue"))); - assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/complexStringValue"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonObject.query("/intValue"))); - assertTrue("expected -23.45e67", BigDecimal.valueOf(-23.45e67).equals(jsonObject.query("/doubleValue"))); - } - - /** - * Build a JSON doc using JSONString API calls, - * then convert to JSONArray - */ - @Test - public void simpleArrayString() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.array(); - jsonStringer.value(true); - jsonStringer.value(false); - jsonStringer.value(null); - jsonStringer.value("hello world!"); - jsonStringer.value(42); - jsonStringer.value(-23.45e67); - jsonStringer.endArray(); - String str = jsonStringer.toString(); - JSONArray jsonArray = new JSONArray(str); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonArray.toString()); - assertTrue("expected 6 top level items", ((List)(JsonPath.read(doc, "$"))).size() == 6); - assertTrue("expected true", Boolean.TRUE.equals(jsonArray.query("/0"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonArray.query("/1"))); - assertTrue("expected null", JSONObject.NULL.equals(jsonArray.query("/2"))); - assertTrue("expected hello world!", "hello world!".equals(jsonArray.query("/3"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonArray.query("/4"))); - assertTrue("expected -23.45e67", BigDecimal.valueOf(-23.45e67).equals(jsonArray.query("/5"))); - } - - /** - * Build a nested JSON doc using JSONString API calls, then convert to - * JSONObject. Will create a long cascade of output by reusing the - * returned values.. - */ - @Test - public void complexObjectString() { - JSONStringer jsonStringer = new JSONStringer(); - jsonStringer.object(). - key("trueValue").value(true). - key("falseValue").value(false). - key("nullValue").value(null). - key("stringValue").value("hello world!"). - key("object2").object(). - key("k1").value("v1"). - key("k2").value("v2"). - key("k3").value("v3"). - key("array1").array(). - value(1). - value(2). - object(). - key("k4").value("v4"). - key("k5").value("v5"). - key("k6").value("v6"). - key("array2").array(). - value(5). - value(6). - value(7). - value(8). - endArray(). - endObject(). - value(3). - value(4). - endArray(). - endObject(). - key("complexStringValue").value("h\be\tllo w\u1234orld!"). - key("intValue").value(42). - key("doubleValue").value(-23.45e67). - endObject(); - String str = jsonStringer.toString(); - JSONObject jsonObject = new JSONObject(str); - - // validate JSON content - Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); - assertTrue("expected 8 top level items", ((Map)(JsonPath.read(doc, "$"))).size() == 8); - assertTrue("expected 4 object2 items", ((Map)(JsonPath.read(doc, "$.object2"))).size() == 4); - assertTrue("expected 5 array1 items", ((List)(JsonPath.read(doc, "$.object2.array1"))).size() == 5); - assertTrue("expected 4 array[2] items", ((Map)(JsonPath.read(doc, "$.object2.array1[2]"))).size() == 4); - assertTrue("expected 4 array1[2].array2 items", ((List)(JsonPath.read(doc, "$.object2.array1[2].array2"))).size() == 4); - assertTrue("expected true", Boolean.TRUE.equals(jsonObject.query("/trueValue"))); - assertTrue("expected false", Boolean.FALSE.equals(jsonObject.query("/falseValue"))); - assertTrue("expected null", JSONObject.NULL.equals(jsonObject.query("/nullValue"))); - assertTrue("expected hello world!", "hello world!".equals(jsonObject.query("/stringValue"))); - assertTrue("expected 42", Integer.valueOf(42).equals(jsonObject.query("/intValue"))); - assertTrue("expected -23.45e67", BigDecimal.valueOf(-23.45e67).equals(jsonObject.query("/doubleValue"))); - assertTrue("expected h\be\tllo w\u1234orld!", "h\be\tllo w\u1234orld!".equals(jsonObject.query("/complexStringValue"))); - assertTrue("expected v1", "v1".equals(jsonObject.query("/object2/k1"))); - assertTrue("expected v2", "v2".equals(jsonObject.query("/object2/k2"))); - assertTrue("expected v3", "v3".equals(jsonObject.query("/object2/k3"))); - assertTrue("expected 1", Integer.valueOf(1).equals(jsonObject.query("/object2/array1/0"))); - assertTrue("expected 2", Integer.valueOf(2).equals(jsonObject.query("/object2/array1/1"))); - assertTrue("expected v4", "v4".equals(jsonObject.query("/object2/array1/2/k4"))); - assertTrue("expected v5", "v5".equals(jsonObject.query("/object2/array1/2/k5"))); - assertTrue("expected v6", "v6".equals(jsonObject.query("/object2/array1/2/k6"))); - assertTrue("expected 5", Integer.valueOf(5).equals(jsonObject.query("/object2/array1/2/array2/0"))); - assertTrue("expected 6", Integer.valueOf(6).equals(jsonObject.query("/object2/array1/2/array2/1"))); - assertTrue("expected 7", Integer.valueOf(7).equals(jsonObject.query("/object2/array1/2/array2/2"))); - assertTrue("expected 8", Integer.valueOf(8).equals(jsonObject.query("/object2/array1/2/array2/3"))); - assertTrue("expected 3", Integer.valueOf(3).equals(jsonObject.query("/object2/array1/3"))); - assertTrue("expected 4", Integer.valueOf(4).equals(jsonObject.query("/object2/array1/4"))); - } - -} diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java deleted file mode 100644 index 59ca6d8f6..000000000 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ /dev/null @@ -1,328 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; -import org.junit.Test; - -/** - * Test specific to the {@link org.json.JSONTokener} class. - * @author John Aylward - * - */ -public class JSONTokenerTest { - - /** - * verify that back() fails as expected. - * @throws IOException thrown if something unexpected happens. - */ - @Test - public void verifyBackFailureZeroIndex() throws IOException { - Reader reader = new StringReader("some test string"); - try { - final JSONTokener tokener = new JSONTokener(reader); - try { - // this should fail since the index is 0; - tokener.back(); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Stepping back two steps is not supported", e.getMessage()); - } catch (Exception e) { - fail("Unknown Exception type " + e.getClass().getCanonicalName()+" with message "+e.getMessage()); - } - - } finally { - reader.close(); - } - } - /** - * verify that back() fails as expected. - * @throws IOException thrown if something unexpected happens. - */ - @Test - public void verifyBackFailureDoubleBack() throws IOException { - Reader reader = new StringReader("some test string"); - try { - final JSONTokener tokener = new JSONTokener(reader); - tokener.next(); - tokener.back(); - try { - // this should fail since the index is 0; - tokener.back(); - fail("Expected an exception"); - } catch (JSONException e) { - assertEquals("Stepping back two steps is not supported", e.getMessage()); - } catch (Exception e) { - fail("Unknown Exception type " + e.getClass().getCanonicalName()+" with message "+e.getMessage()); - } - } finally { - reader.close(); - } - } - - @Test - public void testValid() { - checkValid("0",Number.class); - checkValid(" 0 ",Number.class); - checkValid("23",Number.class); - checkValid("23.5",Number.class); - checkValid(" 23.5 ",Number.class); - checkValid("null",null); - checkValid(" null ",null); - checkValid("true",Boolean.class); - checkValid(" true\n",Boolean.class); - checkValid("false",Boolean.class); - checkValid("\nfalse ",Boolean.class); - checkValid("{}",JSONObject.class); - checkValid(" {} ",JSONObject.class); - checkValid("{\"a\":1}",JSONObject.class); - checkValid(" {\"a\":1} ",JSONObject.class); - checkValid("[]",JSONArray.class); - checkValid(" [] ",JSONArray.class); - checkValid("[1,2]",JSONArray.class); - checkValid("\n\n[1,2]\n\n",JSONArray.class); - checkValid("1 2", String.class); - } - - @Test - public void testErrors() { - // Check that stream can detect that a value is found after - // the first one - checkError(" { \"a\":1 } 4 "); - checkError("null \"a\""); - checkError("{} true"); - } - - private Object checkValid(String testStr, Class aClass) { - Object result = nextValue(testStr); - - // Check class of object returned - if( null == aClass ) { - if(JSONObject.NULL.equals(result)) { - // OK - } else { - throw new JSONException("Unexpected class: "+result.getClass().getSimpleName()); - } - } else { - if( null == result ) { - throw new JSONException("Unexpected null result"); - } else if(!aClass.isAssignableFrom(result.getClass()) ) { - throw new JSONException("Unexpected class: "+result.getClass().getSimpleName()); - } - } - - return result; - } - - private void checkError(String testStr) { - try { - nextValue(testStr); - - fail("Error should be triggered: (\""+testStr+"\")"); - } catch (JSONException e) { - // OK - } - } - - /** - * Verifies that JSONTokener can read a stream that contains a value. After - * the reading is done, check that the stream is left in the correct state - * by reading the characters after. All valid cases should reach end of stream. - * @param testStr - * @return - * @throws Exception - */ - private Object nextValue(String testStr) throws JSONException { - StringReader sr = new StringReader(testStr); - try { - JSONTokener tokener = new JSONTokener(sr); - - Object result = tokener.nextValue(); - - if( result == null ) { - throw new JSONException("Unable to find value token in JSON stream: ("+tokener+"): "+testStr); - } - - char c = tokener.nextClean(); - if( 0 != c ) { - throw new JSONException("Unexpected character found at end of JSON stream: "+c+ " ("+tokener+"): "+testStr); - } - - return result; - } finally { - sr.close(); - } - - } - - /** - * Tests the failure of the skipTo method with a buffered reader. Preferably - * we'd like this not to fail but at this time we don't have a good recovery. - * - * @throws IOException thrown if something unexpected happens. - */ - @Test - public void testSkipToFailureWithBufferedReader() throws IOException { - final byte[] superLongBuffer = new byte[1000001]; - // fill our buffer - for(int i=0;i keys = jsonObject.keys(); - while (keys.hasNext()) { - String key = keys.next(); - Object value = jsonObject.get(key); - Object expectedValue = expectedJsonObject.get(key); - compareActualVsExpectedObjects(value, expectedValue); - } - } - - /** - * Compare two objects for equality. Might be JSONArray, JSONObject, - * or something else. - * @param value created by the code to be tested - * @param expectedValue created specifically for comparing - */ - private static void compareActualVsExpectedObjects(Object value, - Object expectedValue) { - if (value instanceof JSONObject && expectedValue instanceof JSONObject) { - // Compare JSONObjects - JSONObject jsonObject = (JSONObject)value; - JSONObject expectedJsonObject = (JSONObject)expectedValue; - compareActualVsExpectedJsonObjects( - jsonObject, expectedJsonObject); - } else if (value instanceof JSONArray && expectedValue instanceof JSONArray) { - // Compare JSONArrays - JSONArray jsonArray = (JSONArray)value; - JSONArray expectedJsonArray = (JSONArray)expectedValue; - compareActualVsExpectedJsonArrays( - jsonArray, expectedJsonArray); - } else { - /** - * Compare all other types using toString(). First, the types must - * also be equal, unless both are Number type. Certain helper - * classes (e.g. XML) may create Long instead of Integer for small - * int values. - */ - if (!(value instanceof Number && expectedValue instanceof Number)) { - // Non-Number and non-matching types - assertEquals("object types should be equal ", - expectedValue.getClass().toString(), - value.getClass().toString() - ); - } - /** - * Same types or both Numbers, compare by toString() - */ - assertEquals("values should be equal", - expectedValue.toString(), - value.toString() - ); - } - } - - /** - * Asserts that all JSONObject maps are the same as the default ctor - * @param jsonObjects list of objects to be tested - */ - public static void checkJSONObjectsMaps(List jsonObjects) { - if (jsonObjects == null || jsonObjects.size() == 0) { - return; - } - Class mapType = new JSONObject().getMapType(); - for (JSONObject jsonObject : jsonObjects) { - if (jsonObject != null) { - assertTrue(mapType == jsonObject.getMapType()); - checkJSONObjectMaps(jsonObject, mapType); - } - } - } - - /** - * Asserts that all JSONObject maps are the same as the default ctor - * @param jsonObject the object to be tested - */ - public static void checkJSONObjectMaps(JSONObject jsonObject) { - if (jsonObject != null) { - checkJSONObjectMaps(jsonObject, jsonObject.getMapType()); - } - } - - /** - * Asserts that all JSONObject maps are the same as mapType - * @param jsonObject object to be tested - * @param mapType mapType to test against - */ - public static void checkJSONObjectMaps(JSONObject jsonObject, Class mapType) { - if (mapType == null) { - mapType = new JSONObject().getMapType(); - } - Set keys = jsonObject.keySet(); - for (String key : keys) { - Object val = jsonObject.get(key); - if (val instanceof JSONObject) { - JSONObject jsonObjectVal = (JSONObject) val; - assertTrue(mapType == ((JSONObject) val).getMapType()); - checkJSONObjectMaps(jsonObjectVal, mapType); - } else if (val instanceof JSONArray) { - JSONArray jsonArrayVal = (JSONArray)val; - checkJSONArrayMaps(jsonArrayVal, mapType); - } - } - } - - /** - * Asserts that all JSONObject maps in the JSONArray object match the default map - * @param jsonArrays list of JSONArray objects to be tested - */ - public static void checkJSONArraysMaps(List jsonArrays) { - if (jsonArrays == null || jsonArrays.size() == 0) { - return; - } - Class mapType = new JSONObject().getMapType(); - for (JSONArray jsonArray : jsonArrays) { - if (jsonArray != null) { - checkJSONArrayMaps(jsonArray, mapType); - } - } - } - - /** - * Asserts that all JSONObject maps in the JSONArray object match mapType - * @param jsonArray object to be tested - * @param mapType map type to be tested against - */ - public static void checkJSONArrayMaps(JSONArray jsonArray, Class mapType) { - if (jsonArray == null) { - return; - } - if (mapType == null) { - mapType = new JSONObject().getMapType(); - } - Iterator it = jsonArray.iterator(); - while (it.hasNext()) { - Object val = it.next(); - if (val instanceof JSONObject) { - JSONObject jsonObjectVal = (JSONObject)val; - checkJSONObjectMaps(jsonObjectVal, mapType); - } else if (val instanceof JSONArray) { - JSONArray jsonArrayVal = (JSONArray)val; - checkJSONArrayMaps(jsonArrayVal, mapType); - } - } - } - - /** - * Asserts that all JSONObject maps nested in the JSONArray match - * the default mapType - * @param jsonArray the object to be tested - */ - public static void checkJSONArrayMaps(JSONArray jsonArray) { - if (jsonArray != null) { - checkJSONArrayMaps(jsonArray, null); - } - } -} diff --git a/src/test/java/org/json/junit/XMLConfigurationTest.java b/src/test/java/org/json/junit/XMLConfigurationTest.java deleted file mode 100755 index 92a109ad9..000000000 --- a/src/test/java/org/json/junit/XMLConfigurationTest.java +++ /dev/null @@ -1,1187 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.HashSet; -import java.util.Set; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.XML; -import org.json.XMLParserConfiguration; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.junit.Assert.*; - - -/** - * Tests for JSON-Java XML.java with XMLParserConfiguration.java - */ -public class XMLConfigurationTest { - /** - * JUnit supports temporary files and folders that are cleaned up after the test. - * https://garygregory.wordpress.com/2010/01/20/junit-tip-use-rules-to-manage-temporary-files-and-folders/ - */ - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - /** - * JSONObject from a null XML string. - * Expects a NullPointerException - */ - @Test(expected=NullPointerException.class) - public void shouldHandleNullXML() { - String xmlStr = null; - JSONObject jsonObject = - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - } - - /** - * Empty JSONObject from an empty XML string. - */ - @Test - public void shouldHandleEmptyXML() { - - String xmlStr = ""; - JSONObject jsonObject = - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - } - - /** - * Empty JSONObject from a non-XML string. - */ - @Test - public void shouldHandleNonXML() { - String xmlStr = "{ \"this is\": \"not xml\"}"; - JSONObject jsonObject = - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - assertTrue("xml string should be empty", jsonObject.isEmpty()); - } - - /** - * Invalid XML string (tag contains a frontslash). - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidSlashInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " abc street\n"+ - "
\n"+ - "
"; - try { - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped tag at 176 [character 14 line 4]", - e.getMessage()); - } - } - - /** - * Invalid XML string ('!' char in tag) - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidBangInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - "
\n"+ - "
"; - try { - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 214 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Invalid XML string ('!' char and no closing tag brace) - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidBangNoCloseInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 213 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Invalid XML string (no end brace for tag) - * Expects JSONException - */ - @Test - public void shouldHandleNoCloseStartTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - XML.toJSONObject(xmlStr, XMLParserConfiguration.KEEP_STRINGS); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misplaced '<' at 193 [character 4 line 6]", - e.getMessage()); - } - } - - /** - * Invalid XML string (partial CDATA chars in tag name) - * Expects JSONException - */ - @Test - public void shouldHandleInvalidCDATABangInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Joe Tester\n"+ - " \n"+ - "
\n"+ - "
"; - try { - XMLParserConfiguration config = - new XMLParserConfiguration().withcDataTagName("altContent"); - XML.toJSONObject(xmlStr, config); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected 'CDATA[' at 204 [character 11 line 5]", - e.getMessage()); - } - } - - /** - * Null JSONObject in XML.toString() - */ - @Test - public void shouldHandleNullJSONXML() { - JSONObject jsonObject= null; - String actualXml = XML.toString(jsonObject, null, - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("generated XML does not equal expected XML","\"null\"",actualXml); - } - - /** - * Empty JSONObject in XML.toString() - */ - @Test - public void shouldHandleEmptyJSONXML() { - JSONObject jsonObject= new JSONObject(); - String xmlStr = XML.toString(jsonObject, null, - XMLParserConfiguration.KEEP_STRINGS); - assertTrue("xml string should be empty", xmlStr.isEmpty()); - } - - /** - * No SML start tag. The ending tag ends up being treated as content. - */ - @Test - public void shouldHandleNoStartTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " >\n"+ - "
\n"+ - "
"; - String expectedStr = - "{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\",\""+ - "content\":\">\"},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+ - "xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}"; - JSONObject jsonObject = XML.toJSONObject(xmlStr, - XMLParserConfiguration.KEEP_STRINGS); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Valid XML to JSONObject - */ - @Test - public void shouldHandleSimpleXML() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Joe Tester\n"+ - " [CDATA[Baker street 5]\n"+ - " \n"+ - " true\n"+ - " false\n"+ - " null\n"+ - " 42\n"+ - " -23\n"+ - " -23.45\n"+ - " -23x.45\n"+ - " 1, 2, 3, 4.1, 5.2\n"+ - "
\n"+ - "
"; - - // TODO: This test failed in strictMode due to -23x.45 not being surrounded by quotes - // It should probably be split into two tests, one of which does not run in strictMode. - // TBD. - String expectedStr = - "{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+ - "\"name\":\"Joe Tester\",\"NothingHere\":\"\",\"TrueValue\":true,\n"+ - "\"FalseValue\":false,\"NullValue\":null,\"PositiveValue\":42,\n"+ - "\"NegativeValue\":-23,\"DoubleValue\":-23.45,\"Nan\":\"-23x.45\",\n"+ - "\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+ - "},\"xsi:noNamespaceSchemaLocation\":"+ - "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ - "XMLSchema-instance\"}}"; - - XMLParserConfiguration config = - new XMLParserConfiguration().withcDataTagName("altContent"); - compareStringToJSONObject(xmlStr, expectedStr, config); - compareReaderToJSONObject(xmlStr, expectedStr, config); - compareFileToJSONObject(xmlStr, expectedStr); - } - - /** - * Valid XML with comments to JSONObject - */ - @Test - public void shouldHandleCommentsInXML() { - - String xmlStr = - "\n"+ - "\n"+ - "\n"+ - "
\n"+ - " comment ]]>\n"+ - " Joe Tester\n"+ - " \n"+ - " Baker street 5\n"+ - "
\n"+ - "
"; - XMLParserConfiguration config = - new XMLParserConfiguration().withcDataTagName("altContent"); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - String expectedStr = "{\"addresses\":{\"address\":{\"street\":\"Baker "+ - "street 5\",\"name\":\"Joe Tester\",\"altContent\":\" this is -- "+ - " comment \"}}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Valid XML to XML.toString() - */ - @Test - public void shouldHandleToString() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " [CDATA[Joe & T > e < s " t ' er]]\n"+ - " Baker street 5\n"+ - " 1, 2, 3, 4.1, 5.2\n"+ - "
\n"+ - "
"; - - String expectedStr = - "{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+ - "\"name\":\"[CDATA[Joe & T > e < s \\\" t \\\' er]]\","+ - "\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+ - "},\"xsi:noNamespaceSchemaLocation\":"+ - "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ - "XMLSchema-instance\"}}"; - - JSONObject jsonObject = XML.toJSONObject(xmlStr, - XMLParserConfiguration.KEEP_STRINGS); - String xmlToStr = XML.toString(jsonObject, null, - XMLParserConfiguration.KEEP_STRINGS); - JSONObject finalJsonObject = XML.toJSONObject(xmlToStr, - XMLParserConfiguration.KEEP_STRINGS); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - /** - * Converting a JSON doc containing '>' content to JSONObject, then - * XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleContentNoArraytoString() { - String expectedStr = - "{\"addresses\":{\"altContent\":\">\"}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - XMLParserConfiguration config = new XMLParserConfiguration().withcDataTagName("altContent"); - String finalStr = XML.toString(expectedJsonObject, null, config); - String expectedFinalStr = ">"; - assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr.equals(finalStr)); - } - - /** - * Converting a JSON doc containing a 'content' array to JSONObject, then - * XML.toString() should result in valid XML. - * TODO: This is probably an error in how the 'content' keyword is used. - */ - @Test - public void shouldHandleContentArraytoString() { - String expectedStr = - "{\"addresses\":{\"altContent\":[1, 2, 3]}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - XMLParserConfiguration config = new XMLParserConfiguration().withcDataTagName("altContent"); - String finalStr = XML.toString(expectedJsonObject, null, config); - String expectedFinalStr = ""+ - "1\n2\n3"+ - ""; - assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr.equals(finalStr)); - } - - /** - * Converting a JSON doc containing a named array to JSONObject, then - * XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleArraytoString() { - String expectedStr = - "{\"addresses\":{"+ - "\"something\":[1, 2, 3]}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - String finalStr = XML.toString(expectedJsonObject, null, - XMLParserConfiguration.KEEP_STRINGS); - String expectedFinalStr = ""+ - "123"+ - ""; - assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr.equals(finalStr)); - } - - /** - * Tests that the XML output for empty arrays is consistent. - */ - @Test - public void shouldHandleEmptyArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("array",new Object[]{}); - final JSONObject jo2 = new JSONObject(); - jo2.put("array",new JSONArray()); - - final String expected = ""; - String output1 = XML.toString(jo1, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected an empty root tag", expected, output1); - String output2 = XML.toString(jo2, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected an empty root tag", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when an internal array is empty. - */ - @Test - public void shouldHandleEmptyMultiArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new Object[]{"One", new String[]{}, "Four"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new Object[]{"One", new JSONArray(new String[]{}), "Four"})); - - final String expected = "OneFour"; - String output1 = XML.toString(jo1, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected a matching array", expected, output1); - String output2 = XML.toString(jo2, "jo", - XMLParserConfiguration.KEEP_STRINGS); - - assertEquals("Expected a matching array", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when arrays are not empty. - */ - @Test - public void shouldHandleNonEmptyArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new String[]{"One", "Two", "Three"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new String[]{"One", "Two", "Three"})); - - final String expected = "OneTwoThree"; - String output1 = XML.toString(jo1, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected a non empty root tag", expected, output1); - String output2 = XML.toString(jo2, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected a non empty root tag", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when arrays are not empty and contain internal arrays. - */ - @Test - public void shouldHandleMultiArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new Object[]{"One", new String[]{"Two", "Three"}, "Four"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new Object[]{"One", new JSONArray(new String[]{"Two", "Three"}), "Four"})); - - final String expected = "OneTwoThreeFour"; - String output1 = XML.toString(jo1, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected a matching array", expected, output1); - String output2 = XML.toString(jo2, "jo", - XMLParserConfiguration.KEEP_STRINGS); - assertEquals("Expected a matching array", expected, output2); - } - - /** - * Converting a JSON doc containing a named array of nested arrays to - * JSONObject, then XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleNestedArraytoString() { - String xmlStr = - "{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\","+ - "\"outer\":[[1], [2], [3]]},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+ - "xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}"; - JSONObject jsonObject = new JSONObject(xmlStr); - String finalStr = XML.toString(jsonObject, null, - XMLParserConfiguration.ORIGINAL); - JSONObject finalJsonObject = XML.toJSONObject(finalStr); - String expectedStr = "
"+ - "12"+ - "3"+ - "
test.xsdhttp://www.w3.org/2001/XMLSche"+ - "ma-instance
"; - JSONObject expectedJsonObject = XML.toJSONObject(expectedStr, - XMLParserConfiguration.ORIGINAL); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - - /** - * Possible bug: - * Illegal node-names must be converted to legal XML-node-names. - * The given example shows 2 nodes which are valid for JSON, but not for XML. - * Therefore illegal arguments should be converted to e.g. an underscore (_). - */ - @Test - public void shouldHandleIllegalJSONNodeNames() - { - JSONObject inputJSON = new JSONObject(); - inputJSON.append("123IllegalNode", "someValue1"); - inputJSON.append("Illegal@node", "someValue2"); - - String result = XML.toString(inputJSON, null, - XMLParserConfiguration.KEEP_STRINGS); - - /* - * This is invalid XML. Names should not begin with digits or contain - * certain values, including '@'. One possible solution is to replace - * illegal chars with '_', in which case the expected output would be: - * <___IllegalNode>someValue1someValue2 - */ - String expected = "<123IllegalNode>someValue1someValue2"; - - assertEquals("Length", expected.length(), result.length()); - assertTrue("123IllegalNode", result.contains("<123IllegalNode>someValue1")); - assertTrue("Illegal@node", result.contains("someValue2")); - } - - /** - * JSONObject with NULL value, to XML.toString() - */ - @Test - public void shouldHandleNullNodeValue() - { - JSONObject inputJSON = new JSONObject(); - inputJSON.put("nullValue", JSONObject.NULL); - // This is a possible preferred result - // String expectedXML = ""; - /** - * This is the current behavior. JSONObject.NULL is emitted as - * the string, "null". - */ - String actualXML = "null"; - String resultXML = XML.toString(inputJSON, null, - XMLParserConfiguration.KEEP_STRINGS); - assertEquals(actualXML, resultXML); - } - - @Test - public void shouldHandleEmptyNodeValue() - { - JSONObject inputJSON = new JSONObject(); - inputJSON.put("Emptyness", ""); - String expectedXmlWithoutExplicitEndTag = ""; - String expectedXmlWithExplicitEndTag = ""; - assertEquals(expectedXmlWithoutExplicitEndTag, XML.toString(inputJSON, null, - new XMLParserConfiguration().withCloseEmptyTag(false))); - assertEquals(expectedXmlWithExplicitEndTag, XML.toString(inputJSON, null, - new XMLParserConfiguration().withCloseEmptyTag(true))); - } - - @Test - public void shouldKeepConfigurationIntactAndUpdateCloseEmptyTagChoice() - { - XMLParserConfiguration keepStrings = XMLParserConfiguration.KEEP_STRINGS; - XMLParserConfiguration keepStringsAndCloseEmptyTag = keepStrings.withCloseEmptyTag(true); - XMLParserConfiguration keepDigits = keepStringsAndCloseEmptyTag.withKeepStrings(false); - XMLParserConfiguration keepDigitsAndNoCloseEmptyTag = keepDigits.withCloseEmptyTag(false); - assertTrue(keepStrings.isKeepStrings()); - assertFalse(keepStrings.isCloseEmptyTag()); - assertTrue(keepStringsAndCloseEmptyTag.isKeepStrings()); - assertTrue(keepStringsAndCloseEmptyTag.isCloseEmptyTag()); - assertFalse(keepDigits.isKeepStrings()); - assertTrue(keepDigits.isCloseEmptyTag()); - assertFalse(keepDigitsAndNoCloseEmptyTag.isKeepStrings()); - assertFalse(keepDigitsAndNoCloseEmptyTag.isCloseEmptyTag()); - - } - - /** - * Investigate exactly how the "content" keyword works - */ - @Test - public void contentOperations() { - /* - * When a standalone 0) then return]]>"; - JSONObject jsonObject = XML.toJSONObject(xmlStr, - XMLParserConfiguration.KEEP_STRINGS); - assertTrue("1. 3 items", 3 == jsonObject.length()); - assertTrue("1. empty tag1", "".equals(jsonObject.get("tag1"))); - assertTrue("1. empty tag2", "".equals(jsonObject.get("tag2"))); - assertTrue("1. content found", "if (a < b && a > 0) then return".equals(jsonObject.get("content"))); - - // multiple consecutive standalone cdatas are accumulated into an array - xmlStr = " 0) then return]]>"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("2. 3 items", 3 == jsonObject.length()); - assertTrue("2. empty tag1", "".equals(jsonObject.get("tag1"))); - assertTrue("2. empty tag2", "".equals(jsonObject.get("tag2"))); - assertTrue("2. content array found", jsonObject.get("altContent") instanceof JSONArray); - JSONArray jsonArray = jsonObject.getJSONArray("altContent"); - assertTrue("2. array size", jsonArray.length() == 2); - assertTrue("2. content array entry 0", "if (a < b && a > 0) then return".equals(jsonArray.get(0))); - assertTrue("2. content array entry 1", "here is another cdata".equals(jsonArray.get(1))); - - /* - * text content is accumulated in a "content" inside a local JSONObject. - * If there is only one instance, it is saved in the context (a different JSONObject - * from the calling code. and the content element is discarded. - */ - xmlStr = "value 1"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("3. 2 items", 1 == jsonObject.length()); - assertTrue("3. value tag1", "value 1".equals(jsonObject.get("tag1"))); - - /* - * array-style text content (multiple tags with the same name) is - * accumulated in a local JSONObject with key="content" and value=JSONArray, - * saved in the context, and then the local JSONObject is discarded. - */ - xmlStr = "value 12true"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("4. 1 item", 1 == jsonObject.length()); - assertTrue("4. content array found", jsonObject.get("tag1") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("tag1"); - assertTrue("4. array size", jsonArray.length() == 3); - assertTrue("4. content array entry 0", "value 1".equals(jsonArray.get(0))); - assertTrue("4. content array entry 1", jsonArray.getInt(1) == 2); - assertTrue("4. content array entry 2", jsonArray.getBoolean(2) == true); - - /* - * Complex content is accumulated in a "content" field. For example, an element - * may contain a mix of child elements and text. Each text segment is - * accumulated to content. - */ - xmlStr = "val1val2"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("5. 1 item", 1 == jsonObject.length()); - assertTrue("5. jsonObject found", jsonObject.get("tag1") - instanceof JSONObject); - jsonObject = jsonObject.getJSONObject("tag1"); - assertTrue("5. 2 contained items", 2 == jsonObject.length()); - assertTrue("5. contained tag", "".equals(jsonObject.get("tag2"))); - assertTrue("5. contained content jsonArray found", - jsonObject.get("altContent") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("altContent"); - assertTrue("5. array size", jsonArray.length() == 2); - assertTrue("5. content array entry 0", "val1".equals(jsonArray.get(0))); - assertTrue("5. content array entry 1", "val2".equals(jsonArray.get(1))); - - /* - * If there is only 1 complex text content, then it is accumulated in a - * "content" field as a string. - */ - xmlStr = "val1"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("6. 1 item", 1 == jsonObject.length()); - assertTrue("6. jsonObject found", jsonObject.get("tag1") instanceof JSONObject); - jsonObject = jsonObject.getJSONObject("tag1"); - assertTrue("6. contained content found", - "val1".equals(jsonObject.get("altContent"))); - assertTrue("6. contained tag2", "".equals(jsonObject.get("tag2"))); - - /* - * In this corner case, the content sibling happens to have key=content - * We end up with an array within an array, and no content element. - * This is probably a bug. - */ - xmlStr = "val1"; - jsonObject = XML.toJSONObject(xmlStr, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - assertTrue("7. 1 item", 1 == jsonObject.length()); - assertTrue("7. jsonArray found", - jsonObject.get("tag1") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("tag1"); - assertTrue("array size 1", jsonArray.length() == 1); - assertTrue("7. contained array found", jsonArray.get(0) - instanceof JSONArray); - jsonArray = jsonArray.getJSONArray(0); - assertTrue("7. inner array size 2", jsonArray.length() == 2); - assertTrue("7. inner array item 0", "val1".equals(jsonArray.get(0))); - assertTrue("7. inner array item 1", "".equals(jsonArray.get(1))); - - /* - * Confirm behavior of original issue - */ - String jsonStr = - "{"+ - "\"Profile\": {"+ - "\"list\": {"+ - "\"history\": {"+ - "\"entries\": ["+ - "{"+ - "\"deviceId\": \"id\","+ - "\"altContent\": {"+ - "\"material\": ["+ - "{"+ - "\"stuff\": false"+ - "}"+ - "]"+ - "}"+ - "}"+ - "]"+ - "}"+ - "}"+ - "}"+ - "}"; - jsonObject = new JSONObject(jsonStr); - xmlStr = XML.toString(jsonObject, null, - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent")); - /* - * This is the created XML. Looks like content was mistaken for - * complex (child node + text) XML. - * - * - * - * - * id - * {"material":[{"stuff":false}]} - * - * - * - * - */ - assertTrue("nothing to test here, see comment on created XML, above", true); - } - - /** - * JSON string lost leading zero and converted "True" to true. - */ - @Test - public void testToJSONArray_jsonOutput() { - final String originalXml = "011000True"; - final JSONObject expected = new JSONObject("{\"root\":{\"item\":{\"id\":\"01\"},\"id\":[\"01\",1,\"00\",0],\"title\":true}}"); - final JSONObject actualJsonOutput = XML.toJSONObject(originalXml, - new XMLParserConfiguration().withKeepStrings(false)); - Util.compareActualVsExpectedJsonObjects(actualJsonOutput,expected); - } - - /** - * JSON string cannot be reverted to original xml. - */ - @Test - public void testToJSONArray_reversibility() { - final String originalXml = "011000True"; - XMLParserConfiguration config = new XMLParserConfiguration().withKeepStrings(false); - final String revertedXml = - XML.toString(XML.toJSONObject(originalXml, config), - null, config); - assertNotEquals(revertedXml, originalXml); - } - - /** - * test passes when using the new method toJsonArray. - */ - @Test - public void testToJsonXML() { - final String originalXml = "011000True"; - final JSONObject expected = new JSONObject("{\"root\":{\"item\":{\"id\":\"01\"},\"id\":[\"01\",\"1\",\"00\",\"0\"],\"title\":\"True\"}}"); - - final JSONObject json = XML.toJSONObject(originalXml, - new XMLParserConfiguration().withKeepStrings(true)); - Util.compareActualVsExpectedJsonObjects(json, expected); - - final String reverseXml = XML.toString(json); - // this reversal isn't exactly the same. use JSONML for an exact reversal - final String expectedReverseXml = "01011000True"; - - assertEquals("length",expectedReverseXml.length(), reverseXml.length()); - assertTrue("array contents", reverseXml.contains("011000")); - assertTrue("item contents", reverseXml.contains("01")); - assertTrue("title contents", reverseXml.contains("True")); - } - - /** - * test to validate certain conditions of XML unescaping. - */ - @Test - public void testUnescape() { - assertEquals("{\"xml\":\"Can cope <;\"}", - XML.toJSONObject("Can cope <; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope <; ", XML.unescape("Can cope <; ")); - - assertEquals("{\"xml\":\"Can cope & ;\"}", - XML.toJSONObject("Can cope & ; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope & ; ", XML.unescape("Can cope & ; ")); - - assertEquals("{\"xml\":\"Can cope &;\"}", - XML.toJSONObject("Can cope &; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope &; ", XML.unescape("Can cope &; ")); - - // unicode entity - assertEquals("{\"xml\":\"Can cope 4;\"}", - XML.toJSONObject("Can cope 4; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope 4; ", XML.unescape("Can cope 4; ")); - - // double escaped - assertEquals("{\"xml\":\"Can cope <\"}", - XML.toJSONObject("Can cope &lt; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope < ", XML.unescape("Can cope &lt; ")); - - assertEquals("{\"xml\":\"Can cope 4\"}", - XML.toJSONObject("Can cope &#x34; ", - XMLParserConfiguration.KEEP_STRINGS).toString()); - assertEquals("Can cope 4 ", XML.unescape("Can cope &#x34; ")); - - } - - /** - * Confirm XMLParserConfiguration functionality - */ - @Test - public void testConfig() { - /** - * 1st param is whether to keep the raw string, or call - * XML.stringToValue(), which may convert the token to - * boolean, null, or number. - * 2nd param is what JSON name to use for strings that are - * evaluated as xml content data in complex objects, e.g. - * - * value - * content data - * - */ - - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " content 1\n"+ - " Sherlock Holmes\n"+ - " content 2\n"+ - " Baker street 5\n"+ - " content 3\n"+ - " 1\n"+ - "
\n"+ - "
"; - - // keep strings, use the altContent tag - XMLParserConfiguration config = - new XMLParserConfiguration() - .withKeepStrings(true) - .withcDataTagName("altContent"); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - // num is parsed as a string - assertEquals(jsonObject.getJSONObject("addresses"). - getJSONObject("address").getString("num"), "1"); - // complex content is collected in an 'altContent' array - JSONArray jsonArray = jsonObject.getJSONObject("addresses"). - getJSONObject("address").getJSONArray("altContent"); - String expectedStr = "[\"content 1\", \"content 2\", \"content 3\"]"; - JSONArray expectedJsonArray = new JSONArray(expectedStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - - // keepstrings only - jsonObject = XML.toJSONObject(xmlStr, - XMLParserConfiguration.KEEP_STRINGS); - // num is parsed as a string - assertEquals(jsonObject.getJSONObject("addresses"). - getJSONObject("address").getString("num"), "1"); - // complex content is collected in an 'content' array - jsonArray = jsonObject.getJSONObject("addresses"). - getJSONObject("address").getJSONArray("content"); - expectedJsonArray = new JSONArray(expectedStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - - // use alternate content name - config = new XMLParserConfiguration().withcDataTagName("altContent"); - jsonObject = XML.toJSONObject(xmlStr, config); - // num is parsed as a number - assertEquals(jsonObject.getJSONObject("addresses"). - getJSONObject("address").getInt("num"), 1); - // complex content is collected in an 'altContent' array - jsonArray = jsonObject.getJSONObject("addresses"). - getJSONObject("address").getJSONArray("altContent"); - expectedJsonArray = new JSONArray(expectedStr); - Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray); - - } - - /** - * Test forceList parameter - */ - @Test - public void testSimpleForceList() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Sherlock Holmes\n"+ - "
\n"+ - "
"; - - String expectedStr = - "{\"addresses\":[{\"address\":{\"name\":\"Sherlock Holmes\"}}]}"; - - Set forceList = new HashSet(); - forceList.add("addresses"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - @Test - public void testLongForceList() { - String xmlStr = - ""+ - ""+ - "host1"+ - "Linux"+ - ""+ - ""+ - "em0"+ - "10.0.0.1"+ - ""+ - ""+ - ""+ - ""; - - String expectedStr = - "{"+ - "\"servers\": ["+ - "{"+ - "\"server\": {"+ - "\"name\": \"host1\","+ - "\"os\": \"Linux\","+ - "\"interfaces\": ["+ - "{"+ - "\"interface\": {"+ - "\"name\": \"em0\","+ - "\"ip_address\": \"10.0.0.1\""+ - "}}]}}]}"; - - Set forceList = new HashSet(); - forceList.add("servers"); - forceList.add("interfaces"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - @Test - public void testMultipleTagForceList() { - String xmlStr = - "\n"+ - "
\n"+ - " Sherlock Holmes\n"+ - " John H. Watson\n"+ - "
\n"+ - "
"; - - String expectedStr = - "{"+ - "\"addresses\":["+ - "{"+ - "\"address\":["+ - "{"+ - "\"name\":["+ - "\"Sherlock Holmes\","+ - "\"John H. Watson\""+ - "]"+ - "}"+ - "]"+ - "}"+ - "]"+ - "}"; - - Set forceList = new HashSet(); - forceList.add("addresses"); - forceList.add("address"); - forceList.add("name"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - @Test - public void testEmptyForceList() { - String xmlStr = - ""; - - String expectedStr = - "{\"addresses\":[]}"; - - Set forceList = new HashSet(); - forceList.add("addresses"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - @Test - public void testContentForceList() { - String xmlStr = - "Baker Street"; - - String expectedStr = - "{\"addresses\":[\"Baker Street\"]}"; - - Set forceList = new HashSet(); - forceList.add("addresses"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - @Test - public void testEmptyTagForceList() { - String xmlStr = - ""; - - String expectedStr = - "{\"addresses\":[]}"; - - Set forceList = new HashSet(); - forceList.add("addresses"); - - XMLParserConfiguration config = - new XMLParserConfiguration() - .withForceList(forceList); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - JSONObject expetedJsonObject = new JSONObject(expectedStr); - - Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject); - } - - @Test - public void testMaxNestingDepthIsSet() { - XMLParserConfiguration xmlParserConfiguration = XMLParserConfiguration.ORIGINAL; - - assertEquals(xmlParserConfiguration.getMaxNestingDepth(), XMLParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH); - - xmlParserConfiguration = xmlParserConfiguration.withMaxNestingDepth(42); - - assertEquals(xmlParserConfiguration.getMaxNestingDepth(), 42); - - xmlParserConfiguration = xmlParserConfiguration.withMaxNestingDepth(0); - - assertEquals(xmlParserConfiguration.getMaxNestingDepth(), 0); - - xmlParserConfiguration = xmlParserConfiguration.withMaxNestingDepth(-31415926); - - assertEquals(xmlParserConfiguration.getMaxNestingDepth(), XMLParserConfiguration.UNDEFINED_MAXIMUM_NESTING_DEPTH); - - xmlParserConfiguration = xmlParserConfiguration.withMaxNestingDepth(Integer.MIN_VALUE); - - assertEquals(xmlParserConfiguration.getMaxNestingDepth(), XMLParserConfiguration.UNDEFINED_MAXIMUM_NESTING_DEPTH); - } - - /** - * Convenience method, given an input string and expected result, - * convert to JSONObject and compare actual to expected result. - * @param xmlStr the string to parse - * @param expectedStr the expected JSON string - * @param config provides more flexible XML parsing - * flexible XML parsing. - */ - private void compareStringToJSONObject(String xmlStr, String expectedStr, - XMLParserConfiguration config) { - JSONObject expectedJsonObject = new JSONObject(expectedStr); - JSONObject jsonObject = XML.toJSONObject(xmlStr, config); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Convenience method, given an input string and expected result, - * convert to JSONObject via reader and compare actual to expected result. - * @param xmlStr the string to parse - * @param expectedStr the expected JSON string - * @param config provides more flexible XML parsing - */ - private void compareReaderToJSONObject(String xmlStr, String expectedStr, - XMLParserConfiguration config) { - /* - * Commenting out this method until the JSON-java code is updated - * to support XML.toJSONObject(reader) - */ - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Reader reader = new StringReader(xmlStr); - try { - JSONObject jsonObject = XML.toJSONObject(reader, config); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } catch (Exception e) { - assertTrue("Reader error: " +e.getMessage(), false); - } finally { - try { - reader.close(); - } catch (Exception e) {} - } - } - - /** - * Convenience method, given an input string and expected result, convert to - * JSONObject via file and compare actual to expected result. - * - * @param xmlStr - * the string to parse - * @param expectedStr - * the expected JSON string - * @throws IOException - */ - private void compareFileToJSONObject(String xmlStr, String expectedStr) { - /* - * Commenting out this method until the JSON-java code is updated - * to support XML.toJSONObject(reader) - */ - try { - JSONObject expectedJsonObject = new JSONObject(expectedStr); - File tempFile = this.testFolder.newFile("fileToJSONObject.xml"); - FileWriter fileWriter = new FileWriter(tempFile); - try { - fileWriter.write(xmlStr); - } finally { - fileWriter.close(); - } - - Reader reader = new FileReader(tempFile); - try { - JSONObject jsonObject = XML.toJSONObject(reader); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } finally { - reader.close(); - } - } catch (IOException e) { - assertTrue("Error: " +e.getMessage(), false); - } - } -} diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java deleted file mode 100644 index be478643c..000000000 --- a/src/test/java/org/json/junit/XMLTest.java +++ /dev/null @@ -1,1434 +0,0 @@ -package org.json.junit; - -/* -Public Domain. -*/ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; - -import org.json.*; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - - -/** - * Tests for JSON-Java XML.java - * Note: noSpace() will be tested by JSONMLTest - */ -public class XMLTest { - /** - * JUnit supports temporary files and folders that are cleaned up after the test. - * https://garygregory.wordpress.com/2010/01/20/junit-tip-use-rules-to-manage-temporary-files-and-folders/ - */ - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - - /** - * JSONObject from a null XML string. - * Expects a NullPointerException - */ - @Test(expected=NullPointerException.class) - public void shouldHandleNullXML() { - String xmlStr = null; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - } - - /** - * Empty JSONObject from an empty XML string. - */ - @Test - public void shouldHandleEmptyXML() { - - String xmlStr = ""; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - assertTrue("jsonObject should be empty", jsonObject.isEmpty()); - } - - /** - * Empty JSONObject from a non-XML string. - */ - @Test - public void shouldHandleNonXML() { - String xmlStr = "{ \"this is\": \"not xml\"}"; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - assertTrue("xml string should be empty", jsonObject.isEmpty()); - } - - /** - * Invalid XML string (tag contains a frontslash). - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidSlashInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " abc street\n"+ - "
\n"+ - "
"; - try { - XML.toJSONObject(xmlStr); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped tag at 176 [character 14 line 4]", - e.getMessage()); - } - } - - /** - * Invalid XML string ('!' char in tag) - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidBangInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - "
\n"+ - "
"; - try { - XML.toJSONObject(xmlStr); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 214 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Invalid XML string ('!' char and no closing tag brace) - * Expects a JSONException - */ - @Test - public void shouldHandleInvalidBangNoCloseInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - XML.toJSONObject(xmlStr); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misshaped meta tag at 213 [character 12 line 7]", - e.getMessage()); - } - } - - /** - * Invalid XML string (no end brace for tag) - * Expects JSONException - */ - @Test - public void shouldHandleNoCloseStartTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " \n"+ - ""; - try { - XML.toJSONObject(xmlStr); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Misplaced '<' at 193 [character 4 line 6]", - e.getMessage()); - } - } - - /** - * Invalid XML string (partial CDATA chars in tag name) - * Expects JSONException - */ - @Test - public void shouldHandleInvalidCDATABangInTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Joe Tester\n"+ - " \n"+ - "
\n"+ - "
"; - try { - XML.toJSONObject(xmlStr); - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertEquals("Expecting an exception message", - "Expected 'CDATA[' at 204 [character 11 line 5]", - e.getMessage()); - } - } - - /** - * Null JSONObject in XML.toString() - */ - @Test - public void shouldHandleNullJSONXML() { - JSONObject jsonObject= null; - String actualXml=XML.toString(jsonObject); - assertEquals("generated XML does not equal expected XML","\"null\"",actualXml); - } - - /** - * Empty JSONObject in XML.toString() - */ - @Test - public void shouldHandleEmptyJSONXML() { - JSONObject jsonObject= new JSONObject(); - String xmlStr = XML.toString(jsonObject); - assertTrue("xml string should be empty", xmlStr.isEmpty()); - } - - /** - * No SML start tag. The ending tag ends up being treated as content. - */ - @Test - public void shouldHandleNoStartTag() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " >\n"+ - "
\n"+ - "
"; - String expectedStr = - "{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\",\""+ - "content\":\">\"},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+ - "xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}"; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Valid XML to JSONObject - */ - @Test - public void shouldHandleSimpleXML() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " Joe Tester\n"+ - " [CDATA[Baker street 5]\n"+ - " \n"+ - " true\n"+ - " false\n"+ - " null\n"+ - " 42\n"+ - " -23\n"+ - " -23.45\n"+ - " -23x.45\n"+ - " 1, 2, 3, 4.1, 5.2\n"+ - "
\n"+ - "
"; - - // TODO: fails in strict mode because -23x.45 was not surrounded by quotes. - // Should be split into a strictMode test, and a similar non-strictMode test - String expectedStr = - "{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+ - "\"name\":\"Joe Tester\",\"NothingHere\":\"\",\"TrueValue\":true,\n"+ - "\"FalseValue\":false,\"NullValue\":null,\"PositiveValue\":42,\n"+ - "\"NegativeValue\":-23,\"DoubleValue\":-23.45,\"Nan\":\"-23x.45\",\n"+ - "\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+ - "},\"xsi:noNamespaceSchemaLocation\":"+ - "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ - "XMLSchema-instance\"}}"; - - compareStringToJSONObject(xmlStr, expectedStr); - compareReaderToJSONObject(xmlStr, expectedStr); - compareFileToJSONObject(xmlStr, expectedStr); - } - - /** - * Tests to verify that supported escapes in XML are converted to actual values. - */ - @Test - public void testXmlEscapeToJson(){ - String xmlStr = - "\n"+ - ""+ - "\""+ - "A €33"+ - "A €22€"+ - "some text ©"+ - "" " & ' < >"+ - "𝄢 𐅥" + - ""; - String expectedStr = - "{\"root\":{" + - "\"rawQuote\":\"\\\"\"," + - "\"euro\":\"A €33\"," + - "\"euroX\":\"A €22€\"," + - "\"unknown\":\"some text ©\"," + - "\"known\":\"\\\" \\\" & ' < >\"," + - "\"high\":\"𝄢 𐅥\""+ - "}}"; - - compareStringToJSONObject(xmlStr, expectedStr); - compareReaderToJSONObject(xmlStr, expectedStr); - compareFileToJSONObject(xmlStr, expectedStr); - } - - /** - * Tests that control characters are escaped. - */ - @Test - public void testJsonToXmlEscape(){ - final String jsonSrc = "{\"amount\":\"10,00 €\"," - + "\"description\":\"Ação Válida\u0085\"," - + "\"xmlEntities\":\"\\\" ' & < >\"" - + "}"; - JSONObject json = new JSONObject(jsonSrc); - String xml = XML.toString(json); - //test control character not existing - assertFalse("Escaping \u0085 failed. Found in XML output.", xml.contains("\u0085")); - assertTrue("Escaping \u0085 failed. Entity not found in XML output.", xml.contains("…")); - // test normal unicode existing - assertTrue("Escaping € failed. Not found in XML output.", xml.contains("€")); - assertTrue("Escaping ç failed. Not found in XML output.", xml.contains("ç")); - assertTrue("Escaping ã failed. Not found in XML output.", xml.contains("ã")); - assertTrue("Escaping á failed. Not found in XML output.", xml.contains("á")); - // test XML Entities converted - assertTrue("Escaping \" failed. Not found in XML output.", xml.contains(""")); - assertTrue("Escaping ' failed. Not found in XML output.", xml.contains("'")); - assertTrue("Escaping & failed. Not found in XML output.", xml.contains("&")); - assertTrue("Escaping < failed. Not found in XML output.", xml.contains("<")); - assertTrue("Escaping > failed. Not found in XML output.", xml.contains(">")); - } - - /** - * Valid XML with comments to JSONObject - */ - @Test - public void shouldHandleCommentsInXML() { - - String xmlStr = - "\n"+ - "\n"+ - "\n"+ - "
\n"+ - " comment ]]>\n"+ - " Joe Tester\n"+ - " \n"+ - " Baker street 5\n"+ - "
\n"+ - "
"; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - String expectedStr = "{\"addresses\":{\"address\":{\"street\":\"Baker "+ - "street 5\",\"name\":\"Joe Tester\",\"content\":\" this is -- "+ - " comment \"}}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Valid XML to XML.toString() - */ - @Test - public void shouldHandleToString() { - String xmlStr = - "\n"+ - "\n"+ - "
\n"+ - " [CDATA[Joe & T > e < s " t ' er]]\n"+ - " Baker street 5\n"+ - " 1, 2, 3, 4.1, 5.2\n"+ - "
\n"+ - "
"; - - String expectedStr = - "{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+ - "\"name\":\"[CDATA[Joe & T > e < s \\\" t \\\' er]]\","+ - "\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+ - "},\"xsi:noNamespaceSchemaLocation\":"+ - "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ - "XMLSchema-instance\"}}"; - - JSONObject jsonObject = XML.toJSONObject(xmlStr); - String xmlToStr = XML.toString(jsonObject); - JSONObject finalJsonObject = XML.toJSONObject(xmlToStr); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - /** - * Converting a JSON doc containing '>' content to JSONObject, then - * XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleContentNoArraytoString() { - String expectedStr = "{\"addresses\":{\"content\":\">\"}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - String finalStr = XML.toString(expectedJsonObject); - String expectedFinalStr = ">"; - assertEquals("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr, finalStr); - } - - /** - * Converting a JSON doc containing a 'content' array to JSONObject, then - * XML.toString() should result in valid XML. - * TODO: This is probably an error in how the 'content' keyword is used. - */ - @Test - public void shouldHandleContentArraytoString() { - String expectedStr = - "{\"addresses\":{" + - "\"content\":[1, 2, 3]}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - String finalStr = XML.toString(expectedJsonObject); - String expectedFinalStr = ""+ - "1\n2\n3"; - assertEquals("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr, finalStr); - } - - /** - * Converting a JSON doc containing a named array to JSONObject, then - * XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleArraytoString() { - String expectedStr = - "{\"addresses\":{"+ - "\"something\":[1, 2, 3]}}"; - JSONObject expectedJsonObject = new JSONObject(expectedStr); - String finalStr = XML.toString(expectedJsonObject); - String expectedFinalStr = ""+ - "123"+ - ""; - assertEquals("Should handle expectedFinal: ["+expectedStr+"] final: ["+ - finalStr+"]", expectedFinalStr, finalStr); - } - - /** - * Tests that the XML output for empty arrays is consistent. - */ - @Test - public void shouldHandleEmptyArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("array",new Object[]{}); - final JSONObject jo2 = new JSONObject(); - jo2.put("array",new JSONArray()); - - final String expected = ""; - String output1 = XML.toString(jo1,"jo"); - assertEquals("Expected an empty root tag", expected, output1); - String output2 = XML.toString(jo2,"jo"); - assertEquals("Expected an empty root tag", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when an internal array is empty. - */ - @Test - public void shouldHandleEmptyMultiArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new Object[]{"One", new String[]{}, "Four"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new Object[]{"One", new JSONArray(new String[]{}), "Four"})); - - final String expected = "OneFour"; - String output1 = XML.toString(jo1,"jo"); - assertEquals("Expected a matching array", expected, output1); - String output2 = XML.toString(jo2,"jo"); - assertEquals("Expected a matching array", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when arrays are not empty. - */ - @Test - public void shouldHandleNonEmptyArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new String[]{"One", "Two", "Three"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new String[]{"One", "Two", "Three"})); - - final String expected = "OneTwoThree"; - String output1 = XML.toString(jo1,"jo"); - assertEquals("Expected a non empty root tag", expected, output1); - String output2 = XML.toString(jo2,"jo"); - assertEquals("Expected a non empty root tag", expected, output2); - } - - /** - * Tests that the XML output for arrays is consistent when arrays are not empty and contain internal arrays. - */ - @Test - public void shouldHandleMultiArray(){ - final JSONObject jo1 = new JSONObject(); - jo1.put("arr",new Object[]{"One", new String[]{"Two", "Three"}, "Four"}); - final JSONObject jo2 = new JSONObject(); - jo2.put("arr",new JSONArray(new Object[]{"One", new JSONArray(new String[]{"Two", "Three"}), "Four"})); - - final String expected = "OneTwoThreeFour"; - String output1 = XML.toString(jo1,"jo"); - assertEquals("Expected a matching array", expected, output1); - String output2 = XML.toString(jo2,"jo"); - assertEquals("Expected a matching array", expected, output2); - } - - /** - * Converting a JSON doc containing a named array of nested arrays to - * JSONObject, then XML.toString() should result in valid XML. - */ - @Test - public void shouldHandleNestedArraytoString() { - String xmlStr = - "{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\","+ - "\"outer\":[[1], [2], [3]]},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+ - "xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}"; - JSONObject jsonObject = new JSONObject(xmlStr); - String finalStr = XML.toString(jsonObject); - JSONObject finalJsonObject = XML.toJSONObject(finalStr); - String expectedStr = "
"+ - "12"+ - "3"+ - "
test.xsdhttp://www.w3.org/2001/XMLSche"+ - "ma-instance
"; - JSONObject expectedJsonObject = XML.toJSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject); - } - - - /** - * Possible bug: - * Illegal node-names must be converted to legal XML-node-names. - * The given example shows 2 nodes which are valid for JSON, but not for XML. - * Therefore illegal arguments should be converted to e.g. an underscore (_). - */ - @Test - public void shouldHandleIllegalJSONNodeNames() - { - JSONObject inputJSON = new JSONObject(); - inputJSON.append("123IllegalNode", "someValue1"); - inputJSON.append("Illegal@node", "someValue2"); - - String result = XML.toString(inputJSON); - - /* - * This is invalid XML. Names should not begin with digits or contain - * certain values, including '@'. One possible solution is to replace - * illegal chars with '_', in which case the expected output would be: - * <___IllegalNode>someValue1someValue2 - */ - String expected = "<123IllegalNode>someValue1someValue2"; - - assertEquals("length",expected.length(), result.length()); - assertTrue("123IllegalNode",result.contains("<123IllegalNode>someValue1")); - assertTrue("Illegal@node",result.contains("someValue2")); - } - - /** - * JSONObject with NULL value, to XML.toString() - */ - @Test - public void shouldHandleNullNodeValue() - { - JSONObject inputJSON = new JSONObject(); - inputJSON.put("nullValue", JSONObject.NULL); - // This is a possible preferred result - // String expectedXML = ""; - /** - * This is the current behavior. JSONObject.NULL is emitted as - * the string, "null". - */ - String actualXML = "null"; - String resultXML = XML.toString(inputJSON); - assertEquals(actualXML, resultXML); - } - - /** - * Investigate exactly how the "content" keyword works - */ - @Test - public void contentOperations() { - /* - * When a standalone 0) then return]]>"; - JSONObject jsonObject = XML.toJSONObject(xmlStr); - assertTrue("1. 3 items", 3 == jsonObject.length()); - assertTrue("1. empty tag1", "".equals(jsonObject.get("tag1"))); - assertTrue("1. empty tag2", "".equals(jsonObject.get("tag2"))); - assertTrue("1. content found", "if (a < b && a > 0) then return".equals(jsonObject.get("content"))); - - // multiple consecutive standalone cdatas are accumulated into an array - xmlStr = " 0) then return]]>"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("2. 3 items", 3 == jsonObject.length()); - assertTrue("2. empty tag1", "".equals(jsonObject.get("tag1"))); - assertTrue("2. empty tag2", "".equals(jsonObject.get("tag2"))); - assertTrue("2. content array found", jsonObject.get("content") instanceof JSONArray); - JSONArray jsonArray = jsonObject.getJSONArray("content"); - assertTrue("2. array size", jsonArray.length() == 2); - assertTrue("2. content array entry 0", "if (a < b && a > 0) then return".equals(jsonArray.get(0))); - assertTrue("2. content array entry 1", "here is another cdata".equals(jsonArray.get(1))); - - /* - * text content is accumulated in a "content" inside a local JSONObject. - * If there is only one instance, it is saved in the context (a different JSONObject - * from the calling code. and the content element is discarded. - */ - xmlStr = "value 1"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("3. 2 items", 1 == jsonObject.length()); - assertTrue("3. value tag1", "value 1".equals(jsonObject.get("tag1"))); - - /* - * array-style text content (multiple tags with the same name) is - * accumulated in a local JSONObject with key="content" and value=JSONArray, - * saved in the context, and then the local JSONObject is discarded. - */ - xmlStr = "value 12true"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("4. 1 item", 1 == jsonObject.length()); - assertTrue("4. content array found", jsonObject.get("tag1") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("tag1"); - assertTrue("4. array size", jsonArray.length() == 3); - assertTrue("4. content array entry 0", "value 1".equals(jsonArray.get(0))); - assertTrue("4. content array entry 1", jsonArray.getInt(1) == 2); - assertTrue("4. content array entry 2", jsonArray.getBoolean(2) == true); - - /* - * Complex content is accumulated in a "content" field. For example, an element - * may contain a mix of child elements and text. Each text segment is - * accumulated to content. - */ - xmlStr = "val1val2"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("5. 1 item", 1 == jsonObject.length()); - assertTrue("5. jsonObject found", jsonObject.get("tag1") instanceof JSONObject); - jsonObject = jsonObject.getJSONObject("tag1"); - assertTrue("5. 2 contained items", 2 == jsonObject.length()); - assertTrue("5. contained tag", "".equals(jsonObject.get("tag2"))); - assertTrue("5. contained content jsonArray found", jsonObject.get("content") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("content"); - assertTrue("5. array size", jsonArray.length() == 2); - assertTrue("5. content array entry 0", "val1".equals(jsonArray.get(0))); - assertTrue("5. content array entry 1", "val2".equals(jsonArray.get(1))); - - /* - * If there is only 1 complex text content, then it is accumulated in a - * "content" field as a string. - */ - xmlStr = "val1"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("6. 1 item", 1 == jsonObject.length()); - assertTrue("6. jsonObject found", jsonObject.get("tag1") instanceof JSONObject); - jsonObject = jsonObject.getJSONObject("tag1"); - assertTrue("6. contained content found", "val1".equals(jsonObject.get("content"))); - assertTrue("6. contained tag2", "".equals(jsonObject.get("tag2"))); - - /* - * In this corner case, the content sibling happens to have key=content - * We end up with an array within an array, and no content element. - * This is probably a bug. - */ - xmlStr = "val1"; - jsonObject = XML.toJSONObject(xmlStr); - assertTrue("7. 1 item", 1 == jsonObject.length()); - assertTrue("7. jsonArray found", jsonObject.get("tag1") instanceof JSONArray); - jsonArray = jsonObject.getJSONArray("tag1"); - assertTrue("array size 1", jsonArray.length() == 1); - assertTrue("7. contained array found", jsonArray.get(0) instanceof JSONArray); - jsonArray = jsonArray.getJSONArray(0); - assertTrue("7. inner array size 2", jsonArray.length() == 2); - assertTrue("7. inner array item 0", "val1".equals(jsonArray.get(0))); - assertTrue("7. inner array item 1", "".equals(jsonArray.get(1))); - - /* - * Confirm behavior of original issue - */ - String jsonStr = - "{"+ - "\"Profile\": {"+ - "\"list\": {"+ - "\"history\": {"+ - "\"entries\": ["+ - "{"+ - "\"deviceId\": \"id\","+ - "\"content\": {"+ - "\"material\": ["+ - "{"+ - "\"stuff\": false"+ - "}"+ - "]"+ - "}"+ - "}"+ - "]"+ - "}"+ - "}"+ - "}"+ - "}"; - jsonObject = new JSONObject(jsonStr); - xmlStr = XML.toString(jsonObject); - /* - * This is the created XML. Looks like content was mistaken for - * complex (child node + text) XML. - * - * - * - * - * id - * {"material":[{"stuff":false}]} - * - * - * - * - */ - assertTrue("nothing to test here, see comment on created XML, above", true); - } - - /** - * Convenience method, given an input string and expected result, - * convert to JSONObject and compare actual to expected result. - * @param xmlStr the string to parse - * @param expectedStr the expected JSON string - */ - private void compareStringToJSONObject(String xmlStr, String expectedStr) { - JSONObject jsonObject = XML.toJSONObject(xmlStr); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Convenience method, given an input string and expected result, - * convert to JSONObject via reader and compare actual to expected result. - * @param xmlStr the string to parse - * @param expectedStr the expected JSON string - */ - private void compareReaderToJSONObject(String xmlStr, String expectedStr) { - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Reader reader = new StringReader(xmlStr); - JSONObject jsonObject = XML.toJSONObject(reader); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } - - /** - * Convenience method, given an input string and expected result, convert to - * JSONObject via file and compare actual to expected result. - * - * @param xmlStr - * the string to parse - * @param expectedStr - * the expected JSON string - * @throws IOException - */ - private void compareFileToJSONObject(String xmlStr, String expectedStr) { - try { - JSONObject expectedJsonObject = new JSONObject(expectedStr); - File tempFile = this.testFolder.newFile("fileToJSONObject.xml"); - FileWriter fileWriter = new FileWriter(tempFile); - try { - fileWriter.write(xmlStr); - } finally { - fileWriter.close(); - } - - Reader reader = new FileReader(tempFile); - try { - JSONObject jsonObject = XML.toJSONObject(reader); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); - } finally { - reader.close(); - } - } catch (IOException e) { - fail("Error: " +e.getMessage()); - } - } - - /** - * JSON string lost leading zero and converted "True" to true. - */ - @Test - public void testToJSONArray_jsonOutput() { - final String originalXml = "011000True"; - final JSONObject expectedJson = new JSONObject("{\"root\":{\"item\":{\"id\":\"01\"},\"id\":[\"01\",1,\"00\",0],\"title\":true}}"); - final JSONObject actualJsonOutput = XML.toJSONObject(originalXml, false); - - Util.compareActualVsExpectedJsonObjects(actualJsonOutput,expectedJson); - } - - /** - * JSON string cannot be reverted to original xml. - */ - @Test - public void testToJSONArray_reversibility() { - final String originalXml = "011000True"; - final String revertedXml = XML.toString(XML.toJSONObject(originalXml, false)); - - assertNotEquals(revertedXml, originalXml); - } - - /** - * test passes when using the new method toJsonArray. - */ - @Test - public void testToJsonXML() { - final String originalXml = "011000True"; - final JSONObject expected = new JSONObject("{\"root\":{\"item\":{\"id\":\"01\"},\"id\":[\"01\",\"1\",\"00\",\"0\"],\"title\":\"True\"}}"); - - final JSONObject actual = XML.toJSONObject(originalXml,true); - - Util.compareActualVsExpectedJsonObjects(actual, expected); - - final String reverseXml = XML.toString(actual); - // this reversal isn't exactly the same. use JSONML for an exact reversal - // the order of the elements may be differnet as well. - final String expectedReverseXml = "01011000True"; - - assertEquals("length",expectedReverseXml.length(), reverseXml.length()); - assertTrue("array contents", reverseXml.contains("011000")); - assertTrue("item contents", reverseXml.contains("01")); - assertTrue("title contents", reverseXml.contains("True")); - } - - /** - * test to validate certain conditions of XML unescaping. - */ - @Test - public void testUnescape() { - assertEquals("{\"xml\":\"Can cope <;\"}", - XML.toJSONObject("Can cope <; ").toString()); - assertEquals("Can cope <; ", XML.unescape("Can cope <; ")); - - assertEquals("{\"xml\":\"Can cope & ;\"}", - XML.toJSONObject("Can cope & ; ").toString()); - assertEquals("Can cope & ; ", XML.unescape("Can cope & ; ")); - - assertEquals("{\"xml\":\"Can cope &;\"}", - XML.toJSONObject("Can cope &; ").toString()); - assertEquals("Can cope &; ", XML.unescape("Can cope &; ")); - - // unicode entity - assertEquals("{\"xml\":\"Can cope 4;\"}", - XML.toJSONObject("Can cope 4; ").toString()); - assertEquals("Can cope 4; ", XML.unescape("Can cope 4; ")); - - // double escaped - assertEquals("{\"xml\":\"Can cope <\"}", - XML.toJSONObject("Can cope &lt; ").toString()); - assertEquals("Can cope < ", XML.unescape("Can cope &lt; ")); - - assertEquals("{\"xml\":\"Can cope 4\"}", - XML.toJSONObject("Can cope &#x34; ").toString()); - assertEquals("Can cope 4 ", XML.unescape("Can cope &#x34; ")); - - } - - /** - * test passes when xsi:nil="true" converting to null (JSON specification-like nil conversion enabled) - */ - @Test - public void testToJsonWithNullWhenNilConversionEnabled() { - final String originalXml = ""; - final String expectedJsonString = "{\"root\":{\"id\":null}}"; - - final JSONObject json = XML.toJSONObject(originalXml, - new XMLParserConfiguration() - .withKeepStrings(false) - .withcDataTagName("content") - .withConvertNilAttributeToNull(true)); - assertEquals(expectedJsonString, json.toString()); - } - - /** - * test passes when xsi:nil="true" not converting to null (JSON specification-like nil conversion disabled) - */ - @Test - public void testToJsonWithNullWhenNilConversionDisabled() { - final String originalXml = ""; - final String expectedJsonString = "{\"root\":{\"id\":{\"xsi:nil\":true}}}"; - - final JSONObject json = XML.toJSONObject(originalXml, new XMLParserConfiguration()); - assertEquals(expectedJsonString, json.toString()); - } - - /** - * Tests to verify that supported escapes in XML are converted to actual values. - */ - @Test - public void testIssue537CaseSensitiveHexEscapeMinimal(){ - String xmlStr = - "\n"+ - "Neutrophils.Hypersegmented | Bld-Ser-Plas"; - String expectedStr = - "{\"root\":\"Neutrophils.Hypersegmented | Bld-Ser-Plas\"}"; - JSONObject xmlJSONObj = XML.toJSONObject(xmlStr, true); - JSONObject expected = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(xmlJSONObj, expected); - } - - /** - * Tests to verify that supported escapes in XML are converted to actual values. - */ - @Test - public void testIssue537CaseSensitiveHexEscapeFullFile(){ - try { - InputStream xmlStream = null; - try { - xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue537.xml"); - Reader xmlReader = new InputStreamReader(xmlStream, Charset.forName("UTF-8")); - JSONObject actual = XML.toJSONObject(xmlReader, true); - InputStream jsonStream = null; - try { - jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue537.json"); - final JSONObject expected = new JSONObject(new JSONTokener(jsonStream)); - Util.compareActualVsExpectedJsonObjects(actual,expected); - } finally { - if (jsonStream != null) { - jsonStream.close(); - } - } - } finally { - if (xmlStream != null) { - xmlStream.close(); - } - } - } catch (IOException e) { - fail("file writer error: " +e.getMessage()); - } - } - - /** - * Tests to verify that supported escapes in XML are converted to actual values. - */ - @Test - public void testIssue537CaseSensitiveHexUnEscapeDirect(){ - String origStr = - "Neutrophils.Hypersegmented | Bld-Ser-Plas"; - String expectedStr = - "Neutrophils.Hypersegmented | Bld-Ser-Plas"; - String actualStr = XML.unescape(origStr); - - assertEquals("Case insensitive Entity unescape", expectedStr, actualStr); - } - - /** - * test passes when xsi:type="java.lang.String" not converting to string - */ - @Test - public void testToJsonWithTypeWhenTypeConversionDisabled() { - String originalXml = "1234"; - String expectedJsonString = "{\"root\":{\"id\":{\"xsi:type\":\"string\",\"content\":1234}}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration()); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - - /** - * test passes when xsi:type="java.lang.String" converting to String - */ - @Test - public void testToJsonWithTypeWhenTypeConversionEnabled() { - String originalXml = "1234" - + "1234"; - String expectedJsonString = "{\"root\":{\"id2\":1234,\"id1\":\"1234\"}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Map> xsiTypeMap = new HashMap>(); - xsiTypeMap.put("string", new XMLXsiTypeConverter() { - @Override public String convert(final String value) { - return value; - } - }); - xsiTypeMap.put("integer", new XMLXsiTypeConverter() { - @Override public Integer convert(final String value) { - return Integer.valueOf(value); - } - }); - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withXsiTypeMap(xsiTypeMap)); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - - @Test - public void testToJsonWithXSITypeWhenTypeConversionEnabled() { - String originalXml = "1234554321"; - String expectedJsonString = "{\"root\":{\"asString\":\"12345\",\"asInt\":54321}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Map> xsiTypeMap = new HashMap>(); - xsiTypeMap.put("string", new XMLXsiTypeConverter() { - @Override public String convert(final String value) { - return value; - } - }); - xsiTypeMap.put("integer", new XMLXsiTypeConverter() { - @Override public Integer convert(final String value) { - return Integer.valueOf(value); - } - }); - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withXsiTypeMap(xsiTypeMap)); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - - @Test - public void testToJsonWithXSITypeWhenTypeConversionNotEnabledOnOne() { - String originalXml = "1234554321"; - String expectedJsonString = "{\"root\":{\"asString\":\"12345\",\"asInt\":54321}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Map> xsiTypeMap = new HashMap>(); - xsiTypeMap.put("string", new XMLXsiTypeConverter() { - @Override public String convert(final String value) { - return value; - } - }); - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withXsiTypeMap(xsiTypeMap)); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - - @Test - public void testXSITypeMapNotModifiable() { - Map> xsiTypeMap = new HashMap>(); - XMLParserConfiguration config = new XMLParserConfiguration().withXsiTypeMap(xsiTypeMap); - xsiTypeMap.put("string", new XMLXsiTypeConverter() { - @Override public String convert(final String value) { - return value; - } - }); - assertEquals("Config Conversion Map size is expected to be 0", 0, config.getXsiTypeMap().size()); - - try { - config.getXsiTypeMap().put("boolean", new XMLXsiTypeConverter() { - @Override public Boolean convert(final String value) { - return Boolean.valueOf(value); - } - }); - fail("Expected to be unable to modify the config"); - } catch (Exception ignored) { } - } - - @Test - public void testIndentComplicatedJsonObject(){ - String str = "{\n" + - " \"success\": true,\n" + - " \"error\": null,\n" + - " \"response\": [\n" + - " {\n" + - " \"timestamp\": 1664917200,\n" + - " \"dateTimeISO\": \"2022-10-05T00:00:00+03:00\",\n" + - " \"loc\": {\n" + - " \"lat\": 39.91987,\n" + - " \"long\": 32.85427\n" + - " },\n" + - " \"place\": {\n" + - " \"name\": \"ankara\",\n" + - " \"state\": \"an\",\n" + - " \"country\": \"tr\"\n" + - " },\n" + - " \"profile\": {\n" + - " \"tz\": \"Europe/Istanbul\"\n" + - " },\n" + - " \"sun\": {\n" + - " \"rise\": 1664941721,\n" + - " \"riseISO\": \"2022-10-05T06:48:41+03:00\",\n" + - " \"set\": 1664983521,\n" + - " \"setISO\": \"2022-10-05T18:25:21+03:00\",\n" + - " \"transit\": 1664962621,\n" + - " \"transitISO\": \"2022-10-05T12:37:01+03:00\",\n" + - " \"midnightSun\": false,\n" + - " \"polarNight\": false,\n" + - " \"twilight\": {\n" + - " \"civilBegin\": 1664940106,\n" + - " \"civilBeginISO\": \"2022-10-05T06:21:46+03:00\",\n" + - " \"civilEnd\": 1664985136,\n" + - " \"civilEndISO\": \"2022-10-05T18:52:16+03:00\",\n" + - " \"nauticalBegin\": 1664938227,\n" + - " \"nauticalBeginISO\": \"2022-10-05T05:50:27+03:00\",\n" + - " \"nauticalEnd\": 1664987015,\n" + - " \"nauticalEndISO\": \"2022-10-05T19:23:35+03:00\",\n" + - " \"astronomicalBegin\": 1664936337,\n" + - " \"astronomicalBeginISO\": \"2022-10-05T05:18:57+03:00\",\n" + - " \"astronomicalEnd\": 1664988905,\n" + - " \"astronomicalEndISO\": \"2022-10-05T19:55:05+03:00\"\n" + - " }\n" + - " },\n" + - " \"moon\": {\n" + - " \"rise\": 1664976480,\n" + - " \"riseISO\": \"2022-10-05T16:28:00+03:00\",\n" + - " \"set\": 1664921520,\n" + - " \"setISO\": \"2022-10-05T01:12:00+03:00\",\n" + - " \"transit\": 1664994240,\n" + - " \"transitISO\": \"2022-10-05T21:24:00+03:00\",\n" + - " \"underfoot\": 1664949360,\n" + - " \"underfootISO\": \"2022-10-05T08:56:00+03:00\",\n" + - " \"phase\": {\n" + - " \"phase\": 0.3186,\n" + - " \"name\": \"waxing gibbous\",\n" + - " \"illum\": 71,\n" + - " \"age\": 9.41,\n" + - " \"angle\": 0.55\n" + - " }\n" + - " }\n" + - " }\n" + - " ]\n" + - "}" ; - JSONObject jsonObject = new JSONObject(str); - String actualIndentedXmlString = XML.toString(jsonObject, 1); - JSONObject actualJsonObject = XML.toJSONObject(actualIndentedXmlString); - String expected = "true\n" + - "\n" + - " 2022-10-05T00:00:00+03:00\n" + - " \n" + - " 39.91987\n" + - " 32.85427\n" + - " \n" + - " \n" + - " \n" + - " 0.3186\n" + - " waxing gibbous\n" + - " 0.55\n" + - " 71\n" + - " 9.41\n" + - " \n" + - " 2022-10-05T01:12:00+03:00\n" + - " 1664949360\n" + - " 1664921520\n" + - " 1664994240\n" + - " 2022-10-05T21:24:00+03:00\n" + - " 2022-10-05T16:28:00+03:00\n" + - " 1664976480\n" + - " 2022-10-05T08:56:00+03:00\n" + - " \n" + - " \n" + - " Europe/Istanbul\n" + - " \n" + - " \n" + - " tr\n" + - " ankara\n" + - " an\n" + - " \n" + - " \n" + - " 2022-10-05T18:25:21+03:00\n" + - " false\n" + - " 1664983521\n" + - " 1664962621\n" + - " false\n" + - " 2022-10-05T12:37:01+03:00\n" + - " 2022-10-05T06:48:41+03:00\n" + - " 1664941721\n" + - " \n" + - " 1664985136\n" + - " 1664936337\n" + - " 1664988905\n" + - " 2022-10-05T05:18:57+03:00\n" + - " 1664940106\n" + - " 2022-10-05T19:23:35+03:00\n" + - " 2022-10-05T19:55:05+03:00\n" + - " 1664938227\n" + - " 1664987015\n" + - " 2022-10-05T05:50:27+03:00\n" + - " 2022-10-05T06:21:46+03:00\n" + - " 2022-10-05T18:52:16+03:00\n" + - " \n" + - " \n" + - " 1664917200\n" + - "\n" + - "null\n"; - JSONObject expectedJsonObject = XML.toJSONObject(expected); - assertTrue(expectedJsonObject.similar(actualJsonObject)); - - - } - - @Test - public void shouldCreateExplicitEndTagWithEmptyValueWhenConfigured(){ - String jsonString = "{\"outer\":{\"innerOne\":\"\", \"innerTwo\":\"two\"}}"; - JSONObject jsonObject = new JSONObject(jsonString); - String expectedXmlString = "two"; - String xmlForm = XML.toString(jsonObject,"encloser", new XMLParserConfiguration().withCloseEmptyTag(true)); - JSONObject actualJsonObject = XML.toJSONObject(xmlForm); - JSONObject expectedJsonObject = XML.toJSONObject(expectedXmlString); - assertTrue(expectedJsonObject.similar(actualJsonObject)); - } - - @Test - public void shouldNotCreateExplicitEndTagWithEmptyValueWhenNotConfigured(){ - String jsonString = "{\"outer\":{\"innerOne\":\"\", \"innerTwo\":\"two\"}}"; - JSONObject jsonObject = new JSONObject(jsonString); - String expectedXmlString = "two"; - String xmlForm = XML.toString(jsonObject,"encloser", new XMLParserConfiguration().withCloseEmptyTag(false)); - JSONObject actualJsonObject = XML.toJSONObject(xmlForm); - JSONObject expectedJsonObject = XML.toJSONObject(expectedXmlString); - assertTrue(expectedJsonObject.similar(actualJsonObject)); - } - - - @Test - public void testIndentSimpleJsonObject(){ - String str = "{ \"employee\": { \n" + - " \"name\": \"sonoo\", \n" + - " \"salary\": 56000, \n" + - " \"married\": true \n" + - " }}"; - JSONObject jsonObject = new JSONObject(str); - String actual = XML.toString(jsonObject, "Test", 2); - JSONObject actualJsonObject = XML.toJSONObject(actual); - String expected = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - JSONObject expectedJsonObject = XML.toJSONObject(expected); - assertTrue(expectedJsonObject.similar(actualJsonObject)); - } - - @Test - public void testIndentSimpleJsonArray(){ - String str = "[ \n" + - " {\"name\":\"Ram\", \"email\":\"Ram@gmail.com\"}, \n" + - " {\"name\":\"Bob\", \"email\":\"bob32@gmail.com\"} \n" + - "] "; - JSONArray jsonObject = new JSONArray(str); - String actual = XML.toString(jsonObject, 2); - JSONObject actualJsonObject = XML.toJSONObject(actual); - String expected = "\n" + - " Ram\n" + - " Ram@gmail.com\n" + - "\n" + - "\n" + - " Bob\n" + - " bob32@gmail.com\n" + - "\n"; - JSONObject expectedJsonObject = XML.toJSONObject(expected); - assertTrue(expectedJsonObject.similar(actualJsonObject)); - - - } - - @Test - public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){ - try (InputStream jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json")) { - final JSONObject object = new JSONObject(new JSONTokener(jsonStream)); - String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS, 2); - try (InputStream xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml")) { - int bufferSize = 1024; - char[] buffer = new char[bufferSize]; - StringBuilder expected = new StringBuilder(); - Reader in = new InputStreamReader(xmlStream, "UTF-8"); - for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) { - expected.append(buffer, 0, numRead); - } - assertTrue(XML.toJSONObject(expected.toString()).similar(XML.toJSONObject(actualString))); - } - } catch (IOException e) { - fail("file writer error: " +e.getMessage()); - } - } - - @Test - public void testMaxNestingDepthOf42IsRespected() { - final String wayTooLongMalformedXML = new String(new char[6000]).replace("\0", ""); - - final int maxNestingDepth = 42; - - try { - XML.toJSONObject(wayTooLongMalformedXML, XMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - @Test - public void testMaxNestingDepthIsRespectedWithValidXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 1; - - try { - XML.toJSONObject(perfectlyFineXML, XMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - - fail("Expecting a JSONException"); - } catch (JSONException e) { - assertTrue("Wrong throwable thrown: not expecting message <" + e.getMessage() + ">", - e.getMessage().startsWith("Maximum nesting depth of " + maxNestingDepth)); - } - } - - @Test - public void testMaxNestingDepthWithValidFittingXML() { - final String perfectlyFineXML = "\n" + - " \n" + - " sonoo\n" + - " 56000\n" + - " true\n" + - " \n" + - "\n"; - - final int maxNestingDepth = 3; - - try { - XML.toJSONObject(perfectlyFineXML, XMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth)); - } catch (JSONException e) { - e.printStackTrace(); - fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " + - "parameter of the XMLParserConfiguration used"); - } - } - @Test - public void testWithWhitespaceTrimmingDisabled() { - String originalXml = " Test Whitespace String \t "; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withShouldTrimWhitespace(false)); - String expectedJsonString = "{\"testXml\":\" Test Whitespace String \t \"}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - @Test - public void testNestedWithWhitespaceTrimmingDisabled() { - String originalXml = - "\n"+ - "\n"+ - "
\n"+ - " Sherlock Holmes \n"+ - "
\n"+ - "
"; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withShouldTrimWhitespace(false)); - String expectedJsonString = "{\"addresses\":{\"address\":{\"name\":\" Sherlock Holmes \"}}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - @Test - public void shouldTrimWhitespaceDoesNotSupportTagsEqualingCDataTagName() { - // When using withShouldTrimWhitespace = true, input containing tags with same name as cDataTagName is unsupported and should not be used in conjunction - String originalXml = - "\n"+ - "\n"+ - "
\n"+ - " Sherlock Holmes \n"+ - "
\n"+ - "
"; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withShouldTrimWhitespace(false).withcDataTagName("content")); - String expectedJsonString = "{\"addresses\":{\"address\":[[\"\\n \",\" Sherlock Holmes \",\"\\n \"]]}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - @Test - public void shouldTrimWhitespaceEnabledDropsTagsEqualingCDataTagNameButValueRemains() { - String originalXml = - "\n"+ - "\n"+ - "
\n"+ - " Sherlock Holmes \n"+ - "
\n"+ - "
"; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withShouldTrimWhitespace(true).withcDataTagName("content")); - String expectedJsonString = "{\"addresses\":{\"address\":\"Sherlock Holmes\"}}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - @Test - public void testWithWhitespaceTrimmingEnabled() { - String originalXml = " Test Whitespace String \t "; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration().withShouldTrimWhitespace(true)); - String expectedJsonString = "{\"testXml\":\"Test Whitespace String\"}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - @Test - public void testWithWhitespaceTrimmingEnabledByDefault() { - String originalXml = " Test Whitespace String \t "; - - JSONObject actualJson = XML.toJSONObject(originalXml, new XMLParserConfiguration()); - String expectedJsonString = "{\"testXml\":\"Test Whitespace String\"}"; - JSONObject expectedJson = new JSONObject(expectedJsonString); - Util.compareActualVsExpectedJsonObjects(actualJson,expectedJson); - } - - @Test - public void clarifyCurrentBehavior() { - - // Behavior documented in #826 - // After reverting the code, amount is stored as numeric, and phone is stored as string - String str1 = - " \n" + - " 0123456789\n" + - " 0.1230\n" + - " true\n" + - " "; - JSONObject jsonObject1 = XML.toJSONObject(str1, - new XMLParserConfiguration().withKeepStrings(false)); - assertEquals(jsonObject1.getJSONObject("datatypes").getFloat("amount"), 0.123, .1); - assertEquals(jsonObject1.getJSONObject("datatypes").getString("telephone"), "0123456789"); - - - // Behavior documented in #852 - // After reverting the code, value is still stored as a number. This is due to how XML.isDecimalNotation() works - // and is probably a bug. JSONObject has a similar problem. - String str2 = " primary 008E97 "; - JSONObject jsonObject2 = XML.toJSONObject(str2); - assertEquals(jsonObject2.getJSONObject("color").getLong("value"), 0e897, .1); - - // Workaround for now is to use keepStrings - JSONObject jsonObject3 = XML.toJSONObject(str2, new XMLParserConfiguration().withKeepStrings(true)); - assertEquals(jsonObject3.getJSONObject("color").getString("value"), "008E97"); - } - -} - - - diff --git a/src/test/java/org/json/junit/data/BrokenToString.java b/src/test/java/org/json/junit/data/BrokenToString.java deleted file mode 100644 index 585d7518a..000000000 --- a/src/test/java/org/json/junit/data/BrokenToString.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.json.junit.data; - -/** - * test class for verifying write errors. - * @author John Aylward - * - */ -public class BrokenToString { - @Override - public String toString() { - throw new IllegalStateException("Something went horribly wrong!"); - } -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/ExceptionalBean.java b/src/test/java/org/json/junit/data/ExceptionalBean.java deleted file mode 100644 index 91067b86b..000000000 --- a/src/test/java/org/json/junit/data/ExceptionalBean.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * - */ -package org.json.junit.data; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; - -/** - * Object for testing the exception handling in {@link org.json.JSONObject#populateMap}. - * - * @author John Aylward - */ -public class ExceptionalBean { - /** - * @return a closeable. - */ - public Closeable getCloseable() { - // anonymous inner class did not work... - return new MyCloseable(); - } - - /** - * @return Nothing really. Just can't be void. - * @throws IllegalAccessException - * always thrown - */ - public int getIllegalAccessException() throws IllegalAccessException { - throw new IllegalAccessException("Yup, it's illegal"); - } - - /** - * @return Nothing really. Just can't be void. - * @throws IllegalArgumentException - * always thrown - */ - public int getIllegalArgumentException() throws IllegalArgumentException { - throw new IllegalArgumentException("Yup, it's illegal"); - } - - /** - * @return Nothing really. Just can't be void. - * @throws InvocationTargetException - * always thrown - */ - public int getInvocationTargetException() throws InvocationTargetException { - throw new InvocationTargetException(new Exception("Yup, it's illegal")); - } - - /** My closeable class. */ - public static final class MyCloseable implements Closeable { - - /** - * @return a string - */ - public String getString() { - return "Yup, it's closeable"; - } - - @Override - public void close() throws IOException { - throw new IOException("Closing is too hard!"); - } - } -} diff --git a/src/test/java/org/json/junit/data/Fraction.java b/src/test/java/org/json/junit/data/Fraction.java deleted file mode 100644 index c418179f9..000000000 --- a/src/test/java/org/json/junit/data/Fraction.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.json.junit.data; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.math.RoundingMode; - -/** - * basic fraction class, no frills. - * @author John Aylward - * - */ -public class Fraction extends Number implements Comparable { - /** - * serial id. - */ - private static final long serialVersionUID = 1L; - - /** - * value as a big decimal. - */ - private final BigDecimal bigDecimal; - - /** - * value of the denominator. - */ - private final BigInteger denominator; - /** - * value of the numerator. - */ - private final BigInteger numerator; - - /** - * @param numerator - * numerator - * @param denominator - * denominator - */ - public Fraction(final BigInteger numerator, final BigInteger denominator) { - super(); - if (numerator == null || denominator == null) { - throw new IllegalArgumentException("All values must be non-null"); - } - if (denominator.compareTo(BigInteger.ZERO)==0) { - throw new IllegalArgumentException("Divide by zero"); - } - - final BigInteger n; - final BigInteger d; - // normalize fraction - if (denominator.signum()<0) { - n = numerator.negate(); - d = denominator.negate(); - } else { - n = numerator; - d = denominator; - } - this.numerator = n; - this.denominator = d; - if (n.compareTo(BigInteger.ZERO)==0) { - this.bigDecimal = BigDecimal.ZERO; - } else if (n.compareTo(d)==0) {// i.e. 4/4, 10/10 - this.bigDecimal = BigDecimal.ONE; - } else { - this.bigDecimal = new BigDecimal(this.numerator).divide(new BigDecimal(this.denominator), - RoundingMode.HALF_EVEN); - } - } - - /** - * @param numerator - * numerator - * @param denominator - * denominator - */ - public Fraction(final long numerator, final long denominator) { - this(BigInteger.valueOf(numerator),BigInteger.valueOf(denominator)); - } - - /** - * @return the decimal - */ - public BigDecimal bigDecimalValue() { - return this.bigDecimal; - } - - @Override - public int compareTo(final Fraction o) { - // .equals call this, so no .equals compare allowed - - // if they are the same reference, just return equals - if (this == o) { - return 0; - } - - // if my denominators are already equal, just compare the numerators - if (this.denominator.compareTo(o.denominator)==0) { - return this.numerator.compareTo(o.numerator); - } - - // get numerators of common denominators - // a x ay xb - // --- --- = ---- ---- - // b y by yb - final BigInteger thisN = this.numerator.multiply(o.denominator); - final BigInteger otherN = o.numerator.multiply(this.denominator); - - return thisN.compareTo(otherN); - } - - @Override - public double doubleValue() { - return this.bigDecimal.doubleValue(); - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } - final Fraction other = (Fraction) obj; - return this.compareTo(other) == 0; - } - - @Override - public float floatValue() { - return this.bigDecimal.floatValue(); - } - - /** - * @return the denominator - */ - public BigInteger getDenominator() { - return this.denominator; - } - - /** - * @return the numerator - */ - public BigInteger getNumerator() { - return this.numerator; - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (this.bigDecimal == null ? 0 : this.bigDecimal.hashCode()); - return result; - } - - @Override - public int intValue() { - return this.bigDecimal.intValue(); - } - - @Override - public long longValue() { - return this.bigDecimal.longValue(); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return this.numerator + "/" + this.denominator; - } -} diff --git a/src/test/java/org/json/junit/data/GenericBean.java b/src/test/java/org/json/junit/data/GenericBean.java deleted file mode 100644 index dd46b88e6..000000000 --- a/src/test/java/org/json/junit/data/GenericBean.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.json.junit.data; - -import java.io.StringReader; - -/** - * - * @author John Aylward - * - * @param - * generic number value - */ -public class GenericBean implements MyBean { - /** - * @param genericValue - * value to initiate with - */ - public GenericBean(T genericValue) { - super(); - this.genericValue = genericValue; - } - - /** */ - protected T genericValue; - /** to be used by the calling test to see how often the getter is called */ - public int genericGetCounter; - /** to be used by the calling test to see how often the setter is called */ - public int genericSetCounter; - - /** @return the genericValue */ - public T getGenericValue() { - this.genericGetCounter++; - return this.genericValue; - } - - /** - * @param genericValue - * generic value to set - */ - public void setGenericValue(T genericValue) { - this.genericSetCounter++; - this.genericValue = genericValue; - } - - @Override - public Integer getIntKey() { - return Integer.valueOf(42); - } - - @Override - public Double getDoubleKey() { - return Double.valueOf(4.2); - } - - @Override - public String getStringKey() { - return "MyString Key"; - } - - @Override - public String getEscapeStringKey() { - return "\"My String with \"s"; - } - - @Override - public Boolean isTrueKey() { - return Boolean.TRUE; - } - - @Override - public Boolean isFalseKey() { - return Boolean.FALSE; - } - - @Override - public StringReader getStringReaderKey() { - return new StringReader("Some String Value in a reader"); - } - -} diff --git a/src/test/java/org/json/junit/data/GenericBeanInt.java b/src/test/java/org/json/junit/data/GenericBeanInt.java deleted file mode 100644 index 505661162..000000000 --- a/src/test/java/org/json/junit/data/GenericBeanInt.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - */ -package org.json.junit.data; - -/** - * @author john - * - */ -public class GenericBeanInt extends GenericBean { - /** */ - final char a = 'A'; - - /** @return the a */ - public char getA() { - return this.a; - } - - /** - * Should not be beanable - * - * @return false - */ - public boolean getable() { - return false; - } - - /** - * Should not be beanable - * - * @return false - */ - public boolean get() { - return false; - } - - /** - * Should not be beanable - * - * @return false - */ - public boolean is() { - return false; - } - - /** - * Should be beanable - * - * @return false - */ - public boolean isB() { - return this.genericValue.equals((Integer.valueOf(this.a+1))); - } - - /** - * @param genericValue - * the value to initiate with. - */ - public GenericBeanInt(Integer genericValue) { - super(genericValue); - } - - /** override to generate a bridge method */ - @Override - public Integer getGenericValue() { - return super.getGenericValue(); - } - -} diff --git a/src/test/java/org/json/junit/data/MyBean.java b/src/test/java/org/json/junit/data/MyBean.java deleted file mode 100644 index 31909810f..000000000 --- a/src/test/java/org/json/junit/data/MyBean.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.json.junit.data; - -import java.io.*; - -/** - * Used in testing when Bean behavior is needed - */ -public interface MyBean { - public Integer getIntKey(); - public Double getDoubleKey(); - public String getStringKey(); - public String getEscapeStringKey(); - public Boolean isTrueKey(); - public Boolean isFalseKey(); - public StringReader getStringReaderKey(); -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/MyBeanCustomName.java b/src/test/java/org/json/junit/data/MyBeanCustomName.java deleted file mode 100644 index 56756c2b3..000000000 --- a/src/test/java/org/json/junit/data/MyBeanCustomName.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.json.junit.data; - -import org.json.JSONPropertyName; - -/** - * Test bean for the {@link JSONPropertyName} annotation. - */ -public class MyBeanCustomName implements MyBeanCustomNameInterface { - public int getSomeInt() { return 42; } - @JSONPropertyName("") - public long getSomeLong() { return 42L; } - @JSONPropertyName("myStringField") - public String getSomeString() { return "someStringValue"; } - @JSONPropertyName("Some Weird NAme that Normally Wouldn't be possible!") - public double getMyDouble() { return 0.0d; } - @Override - public float getSomeFloat() { return 2.0f; } - @Override - public int getIgnoredInt() { return 40; } -} diff --git a/src/test/java/org/json/junit/data/MyBeanCustomNameInterface.java b/src/test/java/org/json/junit/data/MyBeanCustomNameInterface.java deleted file mode 100644 index b25b57873..000000000 --- a/src/test/java/org/json/junit/data/MyBeanCustomNameInterface.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.json.junit.data; - -import org.json.JSONPropertyIgnore; -import org.json.JSONPropertyName; - -public interface MyBeanCustomNameInterface { - @JSONPropertyName("InterfaceField") - float getSomeFloat(); - @JSONPropertyIgnore - int getIgnoredInt(); -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/MyBeanCustomNameSubClass.java b/src/test/java/org/json/junit/data/MyBeanCustomNameSubClass.java deleted file mode 100644 index 8f0500cce..000000000 --- a/src/test/java/org/json/junit/data/MyBeanCustomNameSubClass.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - */ -package org.json.junit.data; - -import org.json.JSONPropertyIgnore; -import org.json.JSONPropertyName; - -/** - * Test bean to verify that the {@link org.json.JSONPropertyName} annotation - * is inherited. - */ -public class MyBeanCustomNameSubClass extends MyBeanCustomName { - @Override - @JSONPropertyName("forcedInt") - public int getIgnoredInt() { return 42*42; } - @Override - @JSONPropertyName("newIntFieldName") - public int getSomeInt() { return 43; } - @Override - public String getSomeString() { return "subClassString"; } - @Override - @JSONPropertyName("AMoreNormalName") - public double getMyDouble() { return 1.0d; } - @Override - public float getSomeFloat() { return 3.0f; } - @JSONPropertyIgnore - @JSONPropertyName("ShouldBeIgnored") - public boolean getShouldNotBeJSON() { return true; } - @JSONPropertyName("Getable") - public boolean getable() { return true; } -} diff --git a/src/test/java/org/json/junit/data/MyBigNumberBean.java b/src/test/java/org/json/junit/data/MyBigNumberBean.java deleted file mode 100644 index 934dfee03..000000000 --- a/src/test/java/org/json/junit/data/MyBigNumberBean.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.json.junit.data; - -import java.math.*; - -/** - * Used in testing when a Bean containing big numbers is needed - */ -public interface MyBigNumberBean { - public BigInteger getBigInteger(); - public BigDecimal getBigDecimal(); -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/MyEnum.java b/src/test/java/org/json/junit/data/MyEnum.java deleted file mode 100644 index 50d9a4faa..000000000 --- a/src/test/java/org/json/junit/data/MyEnum.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.json.junit.data; - -/** - * An enum with no methods or data - */ -public enum MyEnum { - VAL1, - VAL2, - VAL3; -} diff --git a/src/test/java/org/json/junit/data/MyEnumClass.java b/src/test/java/org/json/junit/data/MyEnumClass.java deleted file mode 100644 index 048669410..000000000 --- a/src/test/java/org/json/junit/data/MyEnumClass.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.json.junit.data; - -/** - * this is simply a class that contains some enum instances - */ -public class MyEnumClass { - private MyEnum myEnum; - private MyEnumField myEnumField; - - public MyEnum getMyEnum() { - return this.myEnum; - } - public void setMyEnum(MyEnum myEnum) { - this.myEnum = myEnum; - } - public MyEnumField getMyEnumField() { - return this.myEnumField; - } - public void setMyEnumField(MyEnumField myEnumField) { - this.myEnumField = myEnumField; - } -} diff --git a/src/test/java/org/json/junit/data/MyEnumField.java b/src/test/java/org/json/junit/data/MyEnumField.java deleted file mode 100644 index 60e89de23..000000000 --- a/src/test/java/org/json/junit/data/MyEnumField.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.json.junit.data; - -/** - * An enum that contains getters and some internal fields - */ -@SuppressWarnings("boxing") -public enum MyEnumField { - VAL1(1, "val 1"), - VAL2(2, "val 2"), - VAL3(3, "val 3"); - - private String value; - private Integer intVal; - private MyEnumField(Integer intVal, String value) { - this.value = value; - this.intVal = intVal; - } - public String getValue() { - return this.value; - } - public Integer getIntVal() { - return this.intVal; - } - @Override - public String toString(){ - return this.value; - } -} diff --git a/src/test/java/org/json/junit/data/MyJsonString.java b/src/test/java/org/json/junit/data/MyJsonString.java deleted file mode 100644 index 4ddde5385..000000000 --- a/src/test/java/org/json/junit/data/MyJsonString.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.json.junit.data; - -import org.json.*; - -/** - * Used in testing when a JSONString is needed - */ -public class MyJsonString implements JSONString { - - @Override - public String toJSONString() { - return "my string"; - } -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/MyLocaleBean.java b/src/test/java/org/json/junit/data/MyLocaleBean.java deleted file mode 100755 index 5d3cb5297..000000000 --- a/src/test/java/org/json/junit/data/MyLocaleBean.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.json.junit.data; - -public class MyLocaleBean { - private final String id = "beanId"; - private final String i = "beanI"; - public String getId() { - return this.id; - } - public String getI() { - return this.i; - } -} diff --git a/src/test/java/org/json/junit/data/MyNumber.java b/src/test/java/org/json/junit/data/MyNumber.java deleted file mode 100644 index 4b625affc..000000000 --- a/src/test/java/org/json/junit/data/MyNumber.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.json.junit.data; - -import java.math.BigDecimal; - -/** - * Number override for testing. Number overrides should always override - * toString, hashCode, and Equals. - * - * @see
The - * Numbers Classes - * @see Formatting - * Numeric Print Output - * - * @author John Aylward - */ -public class MyNumber extends Number { - private Number number = BigDecimal.valueOf(42); - /** - */ - private static final long serialVersionUID = 1L; - - /** - * @return number! - */ - public Number getNumber() { - return this.number; - } - - @Override - public int intValue() { - return getNumber().intValue(); - } - - @Override - public long longValue() { - return getNumber().longValue(); - } - - @Override - public float floatValue() { - return getNumber().floatValue(); - } - - @Override - public double doubleValue() { - return getNumber().doubleValue(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - * - * Number overrides should in general always override the toString method. - */ - @Override - public String toString() { - return getNumber().toString(); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.number == null) ? 0 : this.number.hashCode()); - return result; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof MyNumber)) { - return false; - } - MyNumber other = (MyNumber) obj; - if (this.number == null) { - if (other.number != null) { - return false; - } - } else if (!this.number.equals(other.number)) { - return false; - } - return true; - } - -} diff --git a/src/test/java/org/json/junit/data/MyNumberContainer.java b/src/test/java/org/json/junit/data/MyNumberContainer.java deleted file mode 100644 index 65276529b..000000000 --- a/src/test/java/org/json/junit/data/MyNumberContainer.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.json.junit.data; - -/** - * Class that holds our MyNumber override as a property. - * @author John Aylward - */ -public class MyNumberContainer { - private MyNumber myNumber = new MyNumber(); - /** - * @return a MyNumber. - */ - public Number getMyNumber() {return this.myNumber;} -} diff --git a/src/test/java/org/json/junit/data/MyPublicClass.java b/src/test/java/org/json/junit/data/MyPublicClass.java deleted file mode 100644 index 1f303860c..000000000 --- a/src/test/java/org/json/junit/data/MyPublicClass.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.json.junit.data; - -/** - * Need a class with some public data members for testing - */ -@SuppressWarnings("boxing") -public class MyPublicClass { - public Integer publicInt = 42; - public String publicString = "abc"; -} diff --git a/src/test/java/org/json/junit/data/RecursiveBean.java b/src/test/java/org/json/junit/data/RecursiveBean.java deleted file mode 100644 index dad6e7a65..000000000 --- a/src/test/java/org/json/junit/data/RecursiveBean.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.json.junit.data; - -/** - * test class for verifying if recursively defined bean can be correctly identified - * @author Zetmas - * - */ -public class RecursiveBean { - private String name; - private Object reference; - private Object reference2; - public String getName() { return name; } - public Object getRef() {return reference;} - public Object getRef2() {return reference2;} - public void setRef(Object refObj) {reference = refObj;} - public void setRef2(Object refObj) {reference2 = refObj;} - - public RecursiveBean(String name) { - this.name = name; - reference = null; - reference2 = null; - } -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/RecursiveBeanEquals.java b/src/test/java/org/json/junit/data/RecursiveBeanEquals.java deleted file mode 100644 index 10166481e..000000000 --- a/src/test/java/org/json/junit/data/RecursiveBeanEquals.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.json.junit.data; - -/** test class for verifying if recursively defined bean can be correctly identified */ -public class RecursiveBeanEquals { - private final String name; - private Object reference; - - public RecursiveBeanEquals(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public Object getRef() { - return reference; - } - - public void setRef(Object refObj) { - reference = refObj; - } - - @Override - public boolean equals(Object other) { - return other instanceof RecursiveBeanEquals && name.equals(((RecursiveBeanEquals) other).name); - } - - @Override - public int hashCode() { - return name.hashCode(); - } -} diff --git a/src/test/java/org/json/junit/data/Singleton.java b/src/test/java/org/json/junit/data/Singleton.java deleted file mode 100644 index 224b48a5c..000000000 --- a/src/test/java/org/json/junit/data/Singleton.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.json.junit.data; - -/** - * Sample singleton for use with bean testing. - * - * @author John Aylward - * - */ -public final class Singleton { - /** */ - private int someInt; - /** */ - private String someString; - /** single instance. */ - private static final Singleton INSTANCE = new Singleton(); - - /** @return the singleton instance. */ - public static final Singleton getInstance() { - return INSTANCE; - } - - /** */ - private Singleton() { - if (INSTANCE != null) { - throw new IllegalStateException("Already instantiated"); - } - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return INSTANCE; - } - - /** @return someInt */ - public int getSomeInt() { - return this.someInt; - } - - /** - * sets someInt. - * - * @param someInt - * the someInt to set - */ - public void setSomeInt(int someInt) { - this.someInt = someInt; - } - - /** @return someString */ - public String getSomeString() { - return this.someString; - } - - /** - * sets someString. - * - * @param someString - * the someString to set - */ - public void setSomeString(String someString) { - this.someString = someString; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this.someInt; - result = prime * result + ((this.someString == null) ? 0 : this.someString.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Singleton other = (Singleton) obj; - if (this.someInt != other.someInt) - return false; - if (this.someString == null) { - if (other.someString != null) - return false; - } else if (!this.someString.equals(other.someString)) - return false; - return true; - } -} diff --git a/src/test/java/org/json/junit/data/SingletonEnum.java b/src/test/java/org/json/junit/data/SingletonEnum.java deleted file mode 100644 index 3dd030939..000000000 --- a/src/test/java/org/json/junit/data/SingletonEnum.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.json.junit.data; - -/** - * Sample singleton done as an Enum for use with bean testing. - * - * @author John Aylward - * - */ -public enum SingletonEnum { - /** - * the singleton instance. - */ - INSTANCE; - /** */ - private int someInt; - /** */ - private String someString; - - /** single instance. */ - - /** - * @return the singleton instance. In a real application, I'd hope no one did - * this to an enum singleton. - */ - public static final SingletonEnum getInstance() { - return INSTANCE; - } - - /** */ - private SingletonEnum() { - } - - /** @return someInt */ - public int getSomeInt() { - return this.someInt; - } - - /** - * sets someInt. - * - * @param someInt - * the someInt to set - */ - public void setSomeInt(int someInt) { - this.someInt = someInt; - } - - /** @return someString */ - public String getSomeString() { - return this.someString; - } - - /** - * sets someString. - * - * @param someString - * the someString to set - */ - public void setSomeString(String someString) { - this.someString = someString; - } -} diff --git a/src/test/java/org/json/junit/data/StringsResourceBundle.java b/src/test/java/org/json/junit/data/StringsResourceBundle.java deleted file mode 100644 index 4479350ec..000000000 --- a/src/test/java/org/json/junit/data/StringsResourceBundle.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.json.junit.data; - -import java.util.*; - -/** - * A resource bundle class - */ -public class StringsResourceBundle extends ListResourceBundle { - @Override - public Object[][] getContents() { - return contents; - } - static final Object[][] contents = { - {"greetings.hello", "Hello, "}, - {"greetings.world", "World!"}, - {"farewells.later", "Later, "}, - {"farewells.gator", "Alligator!"} - }; -} \ No newline at end of file diff --git a/src/test/java/org/json/junit/data/WeirdList.java b/src/test/java/org/json/junit/data/WeirdList.java deleted file mode 100644 index 35605863a..000000000 --- a/src/test/java/org/json/junit/data/WeirdList.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - */ -package org.json.junit.data; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author John Aylward - */ -public class WeirdList { - /** */ - private final List list = new ArrayList<>(); - - /** - * @param vals - */ - public WeirdList(Integer... vals) { - this.list.addAll(Arrays.asList(vals)); - } - - /** - * @return a copy of the list - */ - public List get() { - return new ArrayList<>(this.list); - } - - /** - * @return a copy of the list - */ - public List getALL() { - return new ArrayList<>(this.list); - } - - /** - * get a value at an index. - * - * @param i - * index to get - * @return the value at the index - */ - public Integer get(int i) { - return this.list.get(i); - } - - /** - * get a value at an index. - * - * @param i - * index to get - * @return the value at the index - */ - @SuppressWarnings("boxing") - public int getInt(int i) { - return this.list.get(i); - } - - /** - * @param value - * new value to add to the end of the list - */ - public void add(Integer value) { - this.list.add(value); - } -} \ No newline at end of file diff --git a/src/test/resources/Issue537.json b/src/test/resources/Issue537.json deleted file mode 100644 index b3c82feb1..000000000 --- a/src/test/resources/Issue537.json +++ /dev/null @@ -1,189 +0,0 @@ -{ - "clinical_study": { - "brief_summary": { - "textblock": "CLEAR SYNERGY is an international multi center 2x2 randomized placebo controlled trial of" - }, - "brief_title": "CLEAR SYNERGY Neutrophil Substudy", - "overall_status": "Recruiting", - "eligibility": { - "study_pop": { - "textblock": "Patients who are randomized to the drug RCT portion of the CLEAR SYNERGY (OASIS 9) trial" - }, - "minimum_age": "19 Years", - "sampling_method": "Non-Probability Sample", - "gender": "All", - "criteria": { - "textblock": "Inclusion Criteria:" - }, - "healthy_volunteers": "No", - "maximum_age": "110 Years" - }, - "number_of_groups": "2", - "source": "NYU Langone Health", - "location_countries": { - "country": "United States" - }, - "study_design_info": { - "time_perspective": "Prospective", - "observational_model": "Other" - }, - "last_update_submitted_qc": "September 10, 2019", - "intervention_browse": { - "mesh_term": "Colchicine" - }, - "official_title": "Studies on the Effects of Colchicine on Neutrophil Biology in Acute Myocardial Infarction: A Substudy of the CLEAR SYNERGY (OASIS 9) Trial", - "primary_completion_date": { - "type": "Anticipated", - "content": "February 1, 2021" - }, - "sponsors": { - "lead_sponsor": { - "agency_class": "Other", - "agency": "NYU Langone Health" - }, - "collaborator": [ - { - "agency_class": "Other", - "agency": "Population Health Research Institute" - }, - { - "agency_class": "NIH", - "agency": "National Heart, Lung, and Blood Institute (NHLBI)" - } - ] - }, - "overall_official": { - "role": "Principal Investigator", - "affiliation": "NYU School of Medicine", - "last_name": "Binita Shah, MD" - }, - "overall_contact_backup": { - "last_name": "Binita Shah, MD" - }, - "condition_browse": { - "mesh_term": [ - "Myocardial Infarction", - "ST Elevation Myocardial Infarction", - "Infarction" - ] - }, - "overall_contact": { - "phone": "646-501-9648", - "last_name": "Fatmira Curovic", - "email": "fatmira.curovic@nyumc.org" - }, - "responsible_party": { - "responsible_party_type": "Principal Investigator", - "investigator_title": "Assistant Professor of Medicine", - "investigator_full_name": "Binita Shah", - "investigator_affiliation": "NYU Langone Health" - }, - "study_first_submitted_qc": "March 12, 2019", - "start_date": { - "type": "Actual", - "content": "March 4, 2019" - }, - "has_expanded_access": "No", - "study_first_posted": { - "type": "Actual", - "content": "March 14, 2019" - }, - "arm_group": [ - { - "arm_group_label": "Colchicine" - }, - { - "arm_group_label": "Placebo" - } - ], - "primary_outcome": { - "measure": "soluble L-selectin", - "time_frame": "between baseline and 3 months", - "description": "Change in soluble L-selectin between baseline and 3 mo after STEMI in the placebo vs. colchicine groups." - }, - "secondary_outcome": [ - { - "measure": "Other soluble markers of neutrophil activity", - "time_frame": "between baseline and 3 months", - "description": "Other markers of neutrophil activity will be evaluated at baseline and 3 months after STEMI (myeloperoxidase, matrix metalloproteinase-9, neutrophil gelatinase-associated lipocalin, neutrophil elastase, intercellular/vascular cellular adhesion molecules)" - }, - { - "measure": "Markers of systemic inflammation", - "time_frame": "between baseline and 3 months", - "description": "Markers of systemic inflammation will be evaluated at baseline and 3 months after STEMI (high sensitive CRP, IL-1β)" - }, - { - "measure": "Neutrophil-driven responses that may further propagate injury", - "time_frame": "between baseline and 3 months", - "description": "Neutrophil-driven responses that may further propagate injury will be evaluated at baseline and 3 months after STEMI (neutrophil extracellular traps, neutrophil-derived microparticles)" - } - ], - "oversight_info": { - "is_fda_regulated_drug": "No", - "is_fda_regulated_device": "No", - "has_dmc": "No" - }, - "last_update_posted": { - "type": "Actual", - "content": "September 12, 2019" - }, - "id_info": { - "nct_id": "NCT03874338", - "org_study_id": "18-01323", - "secondary_id": "1R01HL146206" - }, - "enrollment": { - "type": "Anticipated", - "content": "670" - }, - "study_first_submitted": "March 12, 2019", - "condition": [ - "Neutrophils.Hypersegmented | Bld-Ser-Plas", - "STEMI - ST Elevation Myocardial Infarction" - ], - "study_type": "Observational", - "required_header": { - "download_date": "ClinicalTrials.gov processed this data on July 19, 2020", - "link_text": "Link to the current ClinicalTrials.gov record.", - "url": "https://clinicaltrials.gov/show/NCT03874338" - }, - "last_update_submitted": "September 10, 2019", - "completion_date": { - "type": "Anticipated", - "content": "February 1, 2022" - }, - "location": { - "contact": { - "phone": "646-501-9648", - "last_name": "Fatmira Curovic", - "email": "fatmira.curovic@nyumc.org" - }, - "facility": { - "address": { - "zip": "10016", - "country": "United States", - "city": "New York", - "state": "New York" - }, - "name": "NYU School of Medicine" - }, - "status": "Recruiting", - "contact_backup": { - "last_name": "Binita Shah, MD" - } - }, - "intervention": { - "intervention_type": "Drug", - "arm_group_label": [ - "Colchicine", - "Placebo" - ], - "description": "Participants in the main CLEAR SYNERGY trial are randomized to colchicine/spironolactone versus placebo in a 2x2 factorial design. The substudy is interested in the evaluation of biospecimens obtained from patients in the colchicine vs placebo group.", - "intervention_name": "Colchicine Pill" - }, - "patient_data": { - "sharing_ipd": "No" - }, - "verification_date": "September 2019" - } -} \ No newline at end of file diff --git a/src/test/resources/Issue537.xml b/src/test/resources/Issue537.xml deleted file mode 100644 index bf78f3b39..000000000 --- a/src/test/resources/Issue537.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - ClinicalTrials.gov processed this data on July 19, 2020 - Link to the current ClinicalTrials.gov record. - https://clinicaltrials.gov/show/NCT03874338 - - - 18-01323 - 1R01HL146206 - NCT03874338 - - CLEAR SYNERGY Neutrophil Substudy - Studies on the Effects of Colchicine on Neutrophil Biology in Acute Myocardial Infarction: A Substudy of the CLEAR SYNERGY (OASIS 9) Trial - - - NYU Langone Health - Other - - - Population Health Research Institute - Other - - - National Heart, Lung, and Blood Institute (NHLBI) - NIH - - - NYU Langone Health - - No - No - No - - - - CLEAR SYNERGY is an international multi center 2x2 randomized placebo controlled trial of - - - Recruiting - March 4, 2019 - February 1, 2022 - February 1, 2021 - Observational - No - - Other - Prospective - - - soluble L-selectin - between baseline and 3 months - Change in soluble L-selectin between baseline and 3 mo after STEMI in the placebo vs. colchicine groups. - - - Other soluble markers of neutrophil activity - between baseline and 3 months - Other markers of neutrophil activity will be evaluated at baseline and 3 months after STEMI (myeloperoxidase, matrix metalloproteinase-9, neutrophil gelatinase-associated lipocalin, neutrophil elastase, intercellular/vascular cellular adhesion molecules) - - - Markers of systemic inflammation - between baseline and 3 months - Markers of systemic inflammation will be evaluated at baseline and 3 months after STEMI (high sensitive CRP, IL-1β) - - - Neutrophil-driven responses that may further propagate injury - between baseline and 3 months - Neutrophil-driven responses that may further propagate injury will be evaluated at baseline and 3 months after STEMI (neutrophil extracellular traps, neutrophil-derived microparticles) - - 2 - 670 - Neutrophils.Hypersegmented | Bld-Ser-Plas - STEMI - ST Elevation Myocardial Infarction - - Colchicine - - - Placebo - - - Drug - Colchicine Pill - Participants in the main CLEAR SYNERGY trial are randomized to colchicine/spironolactone versus placebo in a 2x2 factorial design. The substudy is interested in the evaluation of biospecimens obtained from patients in the colchicine vs placebo group. - Colchicine - Placebo - - - - - Patients who are randomized to the drug RCT portion of the CLEAR SYNERGY (OASIS 9) trial - - - Non-Probability Sample - - - Inclusion Criteria: - - - All - 19 Years - 110 Years - No - - - Binita Shah, MD - Principal Investigator - NYU School of Medicine - - - Fatmira Curovic - 646-501-9648 - fatmira.curovic@nyumc.org - - - Binita Shah, MD - - - - NYU School of Medicine -
- New York - New York - 10016 - United States -
-
- Recruiting - - Fatmira Curovic - 646-501-9648 - fatmira.curovic@nyumc.org - - - Binita Shah, MD - -
- - United States - - September 2019 - March 12, 2019 - March 12, 2019 - March 14, 2019 - September 10, 2019 - September 10, 2019 - September 12, 2019 - - Principal Investigator - NYU Langone Health - Binita Shah - Assistant Professor of Medicine - - - - Myocardial Infarction - ST Elevation Myocardial Infarction - Infarction - - - - Colchicine - - - No - - -
diff --git a/src/test/resources/Issue593.json b/src/test/resources/Issue593.json deleted file mode 100644 index 213625af2..000000000 --- a/src/test/resources/Issue593.json +++ /dev/null @@ -1,704 +0,0 @@ -{ - "success": true, - "error": null, - "response": [ - { - "loc": { - "long": 31.25, - "lat": 30.063 - }, - "interval": "day", - "place": { - "name": "cairo", - "state": "qh", - "country": "eg" - }, - "periods": [ - { - "timestamp": 1665032400, - "validTime": "2022-10-06T07:00:00+02:00", - "dateTimeISO": "2022-10-06T07:00:00+02:00", - "maxTempC": 32, - "maxTempF": 90, - "minTempC": 19, - "minTempF": 66, - "avgTempC": 25, - "avgTempF": 78, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 32, - "maxFeelslikeF": 89, - "minFeelslikeC": 21, - "minFeelslikeF": 70, - "avgFeelslikeC": 26, - "avgFeelslikeF": 80, - "feelslikeC": 21, - "feelslikeF": 70, - "maxDewpointC": 17, - "maxDewpointF": 63, - "minDewpointC": 11, - "minDewpointF": 52, - "avgDewpointC": 14, - "avgDewpointF": 58, - "dewpointC": 17, - "dewpointF": 63, - "maxHumidity": 77, - "minHumidity": 29, - "humidity": 77, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1015, - "pressureIN": 29.97, - "windDir": "N", - "windDirDEG": 353, - "windSpeedKTS": 5, - "windSpeedKPH": 9, - "windSpeedMPH": 6, - "windGustKTS": 21, - "windGustKPH": 40, - "windGustMPH": 25, - "windDirMax": "NNW", - "windDirMaxDEG": 342, - "windSpeedMaxKTS": 9, - "windSpeedMaxKPH": 16, - "windSpeedMaxMPH": 10, - "windDirMin": "N", - "windDirMinDEG": 353, - "windSpeedMinKTS": 1, - "windSpeedMinKPH": 2, - "windSpeedMinMPH": 1, - "windDir80m": "N", - "windDir80mDEG": 11, - "windSpeed80mKTS": 12, - "windSpeed80mKPH": 22, - "windSpeed80mMPH": 13, - "windGust80mKTS": 22, - "windGust80mKPH": 41, - "windGust80mMPH": 25, - "windDirMax80m": "NNW", - "windDirMax80mDEG": 343, - "windSpeedMax80mKTS": 22, - "windSpeedMax80mKPH": 41, - "windSpeedMax80mMPH": 25, - "windDirMin80m": "E", - "windDirMin80mDEG": 95, - "windSpeedMin80mKTS": 8, - "windSpeedMin80mKPH": 15, - "windSpeedMin80mMPH": 10, - "sky": 22, - "cloudsCoded": "FW", - "weather": "Mostly Sunny", - "weatherCoded": [], - "weatherPrimary": "Mostly Sunny", - "weatherPrimaryCoded": "::FW", - "icon": "fair.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": 6, - "solradWM2": 5608, - "solradMinWM2": 0, - "solradMaxWM2": 778, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665028274, - "sunset": 1665070502, - "sunriseISO": "2022-10-06T05:51:14+02:00", - "sunsetISO": "2022-10-06T17:35:02+02:00" - }, - { - "timestamp": 1665118800, - "validTime": "2022-10-07T07:00:00+02:00", - "dateTimeISO": "2022-10-07T07:00:00+02:00", - "maxTempC": 30, - "maxTempF": 86, - "minTempC": 19, - "minTempF": 66, - "avgTempC": 24, - "avgTempF": 76, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 29, - "maxFeelslikeF": 85, - "minFeelslikeC": 19, - "minFeelslikeF": 67, - "avgFeelslikeC": 24, - "avgFeelslikeF": 76, - "feelslikeC": 19, - "feelslikeF": 67, - "maxDewpointC": 15, - "maxDewpointF": 60, - "minDewpointC": 10, - "minDewpointF": 50, - "avgDewpointC": 12, - "avgDewpointF": 54, - "dewpointC": 15, - "dewpointF": 60, - "maxHumidity": 77, - "minHumidity": 30, - "humidity": 77, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1014, - "pressureIN": 29.95, - "windDir": "NW", - "windDirDEG": 325, - "windSpeedKTS": 1, - "windSpeedKPH": 2, - "windSpeedMPH": 1, - "windGustKTS": 16, - "windGustKPH": 29, - "windGustMPH": 18, - "windDirMax": "WNW", - "windDirMaxDEG": 298, - "windSpeedMaxKTS": 7, - "windSpeedMaxKPH": 13, - "windSpeedMaxMPH": 8, - "windDirMin": "NW", - "windDirMinDEG": 325, - "windSpeedMinKTS": 1, - "windSpeedMinKPH": 2, - "windSpeedMinMPH": 1, - "windDir80m": "NNW", - "windDir80mDEG": 347, - "windSpeed80mKTS": 6, - "windSpeed80mKPH": 10, - "windSpeed80mMPH": 6, - "windGust80mKTS": 20, - "windGust80mKPH": 37, - "windGust80mMPH": 23, - "windDirMax80m": "NW", - "windDirMax80mDEG": 316, - "windSpeedMax80mKTS": 20, - "windSpeedMax80mKPH": 37, - "windSpeedMax80mMPH": 23, - "windDirMin80m": "NNW", - "windDirMin80mDEG": 347, - "windSpeedMin80mKTS": 6, - "windSpeedMin80mKPH": 10, - "windSpeedMin80mMPH": 6, - "sky": 30, - "cloudsCoded": "FW", - "weather": "Mostly Sunny", - "weatherCoded": [], - "weatherPrimary": "Mostly Sunny", - "weatherPrimaryCoded": "::FW", - "icon": "fair.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": 6, - "solradWM2": 5486, - "solradMinWM2": 0, - "solradMaxWM2": 742, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665114710, - "sunset": 1665156831, - "sunriseISO": "2022-10-07T05:51:50+02:00", - "sunsetISO": "2022-10-07T17:33:51+02:00" - }, - { - "timestamp": 1665205200, - "validTime": "2022-10-08T07:00:00+02:00", - "dateTimeISO": "2022-10-08T07:00:00+02:00", - "maxTempC": 30, - "maxTempF": 87, - "minTempC": 19, - "minTempF": 66, - "avgTempC": 25, - "avgTempF": 76, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 30, - "maxFeelslikeF": 86, - "minFeelslikeC": 19, - "minFeelslikeF": 67, - "avgFeelslikeC": 25, - "avgFeelslikeF": 76, - "feelslikeC": 19, - "feelslikeF": 67, - "maxDewpointC": 15, - "maxDewpointF": 59, - "minDewpointC": 11, - "minDewpointF": 52, - "avgDewpointC": 13, - "avgDewpointF": 56, - "dewpointC": 15, - "dewpointF": 59, - "maxHumidity": 76, - "minHumidity": 32, - "humidity": 76, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1014, - "pressureIN": 29.94, - "windDir": "NNE", - "windDirDEG": 21, - "windSpeedKTS": 1, - "windSpeedKPH": 2, - "windSpeedMPH": 1, - "windGustKTS": 17, - "windGustKPH": 32, - "windGustMPH": 20, - "windDirMax": "WNW", - "windDirMaxDEG": 301, - "windSpeedMaxKTS": 7, - "windSpeedMaxKPH": 13, - "windSpeedMaxMPH": 8, - "windDirMin": "NNE", - "windDirMinDEG": 21, - "windSpeedMinKTS": 1, - "windSpeedMinKPH": 2, - "windSpeedMinMPH": 1, - "windDir80m": "NW", - "windDir80mDEG": 309, - "windSpeed80mKTS": 5, - "windSpeed80mKPH": 9, - "windSpeed80mMPH": 5, - "windGust80mKTS": 17, - "windGust80mKPH": 31, - "windGust80mMPH": 19, - "windDirMax80m": "NW", - "windDirMax80mDEG": 322, - "windSpeedMax80mKTS": 17, - "windSpeedMax80mKPH": 31, - "windSpeedMax80mMPH": 19, - "windDirMin80m": "NW", - "windDirMin80mDEG": 309, - "windSpeedMin80mKTS": 5, - "windSpeedMin80mKPH": 9, - "windSpeedMin80mMPH": 5, - "sky": 47, - "cloudsCoded": "SC", - "weather": "Partly Cloudy", - "weatherCoded": [], - "weatherPrimary": "Partly Cloudy", - "weatherPrimaryCoded": "::SC", - "icon": "pcloudy.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": 7, - "solradWM2": 4785, - "solradMinWM2": 0, - "solradMaxWM2": 682, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665201146, - "sunset": 1665243161, - "sunriseISO": "2022-10-08T05:52:26+02:00", - "sunsetISO": "2022-10-08T17:32:41+02:00" - }, - { - "timestamp": 1665291600, - "validTime": "2022-10-09T07:00:00+02:00", - "dateTimeISO": "2022-10-09T07:00:00+02:00", - "maxTempC": 31, - "maxTempF": 87, - "minTempC": 19, - "minTempF": 67, - "avgTempC": 25, - "avgTempF": 77, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 30, - "maxFeelslikeF": 86, - "minFeelslikeC": 20, - "minFeelslikeF": 67, - "avgFeelslikeC": 25, - "avgFeelslikeF": 77, - "feelslikeC": 20, - "feelslikeF": 67, - "maxDewpointC": 17, - "maxDewpointF": 63, - "minDewpointC": 11, - "minDewpointF": 52, - "avgDewpointC": 14, - "avgDewpointF": 57, - "dewpointC": 17, - "dewpointF": 63, - "maxHumidity": 86, - "minHumidity": 31, - "humidity": 86, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1016, - "pressureIN": 29.99, - "windDir": "N", - "windDirDEG": 356, - "windSpeedKTS": 2, - "windSpeedKPH": 4, - "windSpeedMPH": 2, - "windGustKTS": 19, - "windGustKPH": 36, - "windGustMPH": 22, - "windDirMax": "NNW", - "windDirMaxDEG": 343, - "windSpeedMaxKTS": 8, - "windSpeedMaxKPH": 14, - "windSpeedMaxMPH": 9, - "windDirMin": "N", - "windDirMinDEG": 356, - "windSpeedMinKTS": 2, - "windSpeedMinKPH": 4, - "windSpeedMinMPH": 2, - "windDir80m": "NW", - "windDir80mDEG": 316, - "windSpeed80mKTS": 5, - "windSpeed80mKPH": 9, - "windSpeed80mMPH": 6, - "windGust80mKTS": 20, - "windGust80mKPH": 36, - "windGust80mMPH": 23, - "windDirMax80m": "N", - "windDirMax80mDEG": 354, - "windSpeedMax80mKTS": 20, - "windSpeedMax80mKPH": 36, - "windSpeedMax80mMPH": 23, - "windDirMin80m": "NW", - "windDirMin80mDEG": 316, - "windSpeedMin80mKTS": 5, - "windSpeedMin80mKPH": 9, - "windSpeedMin80mMPH": 6, - "sky": 47, - "cloudsCoded": "SC", - "weather": "Partly Cloudy", - "weatherCoded": [], - "weatherPrimary": "Partly Cloudy", - "weatherPrimaryCoded": "::SC", - "icon": "pcloudy.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": 7, - "solradWM2": 4768, - "solradMinWM2": 0, - "solradMaxWM2": 726, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665287583, - "sunset": 1665329491, - "sunriseISO": "2022-10-09T05:53:03+02:00", - "sunsetISO": "2022-10-09T17:31:31+02:00" - }, - { - "timestamp": 1665378000, - "validTime": "2022-10-10T07:00:00+02:00", - "dateTimeISO": "2022-10-10T07:00:00+02:00", - "maxTempC": 31, - "maxTempF": 87, - "minTempC": 21, - "minTempF": 70, - "avgTempC": 26, - "avgTempF": 78, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 30, - "maxFeelslikeF": 86, - "minFeelslikeC": 21, - "minFeelslikeF": 69, - "avgFeelslikeC": 25, - "avgFeelslikeF": 78, - "feelslikeC": 21, - "feelslikeF": 69, - "maxDewpointC": 16, - "maxDewpointF": 61, - "minDewpointC": 13, - "minDewpointF": 55, - "avgDewpointC": 14, - "avgDewpointF": 58, - "dewpointC": 16, - "dewpointF": 61, - "maxHumidity": 75, - "minHumidity": 35, - "humidity": 75, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1017, - "pressureIN": 30.03, - "windDir": "N", - "windDirDEG": 358, - "windSpeedKTS": 2, - "windSpeedKPH": 4, - "windSpeedMPH": 2, - "windGustKTS": 16, - "windGustKPH": 30, - "windGustMPH": 19, - "windDirMax": "N", - "windDirMaxDEG": 10, - "windSpeedMaxKTS": 8, - "windSpeedMaxKPH": 15, - "windSpeedMaxMPH": 9, - "windDirMin": "N", - "windDirMinDEG": 358, - "windSpeedMinKTS": 2, - "windSpeedMinKPH": 4, - "windSpeedMinMPH": 2, - "windDir80m": "N", - "windDir80mDEG": 8, - "windSpeed80mKTS": 7, - "windSpeed80mKPH": 13, - "windSpeed80mMPH": 8, - "windGust80mKTS": 19, - "windGust80mKPH": 36, - "windGust80mMPH": 22, - "windDirMax80m": "N", - "windDirMax80mDEG": 10, - "windSpeedMax80mKTS": 19, - "windSpeedMax80mKPH": 36, - "windSpeedMax80mMPH": 22, - "windDirMin80m": "E", - "windDirMin80mDEG": 91, - "windSpeedMin80mKTS": 7, - "windSpeedMin80mKPH": 13, - "windSpeedMin80mMPH": 8, - "sky": 64, - "cloudsCoded": "SC", - "weather": "Partly Cloudy", - "weatherCoded": [], - "weatherPrimary": "Partly Cloudy", - "weatherPrimaryCoded": "::SC", - "icon": "pcloudy.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": 6, - "solradWM2": 4494, - "solradMinWM2": 0, - "solradMaxWM2": 597, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665374020, - "sunset": 1665415821, - "sunriseISO": "2022-10-10T05:53:40+02:00", - "sunsetISO": "2022-10-10T17:30:21+02:00" - }, - { - "timestamp": 1665464400, - "validTime": "2022-10-11T07:00:00+02:00", - "dateTimeISO": "2022-10-11T07:00:00+02:00", - "maxTempC": 31, - "maxTempF": 87, - "minTempC": 21, - "minTempF": 70, - "avgTempC": 26, - "avgTempF": 78, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 31, - "maxFeelslikeF": 87, - "minFeelslikeC": 22, - "minFeelslikeF": 72, - "avgFeelslikeC": 26, - "avgFeelslikeF": 79, - "feelslikeC": 22, - "feelslikeF": 72, - "maxDewpointC": 17, - "maxDewpointF": 62, - "minDewpointC": 11, - "minDewpointF": 51, - "avgDewpointC": 13, - "avgDewpointF": 55, - "dewpointC": 17, - "dewpointF": 62, - "maxHumidity": 71, - "minHumidity": 30, - "humidity": 71, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1015, - "pressureIN": 29.98, - "windDir": "NNE", - "windDirDEG": 13, - "windSpeedKTS": 8, - "windSpeedKPH": 15, - "windSpeedMPH": 9, - "windGustKTS": 15, - "windGustKPH": 28, - "windGustMPH": 17, - "windDirMax": "NNE", - "windDirMaxDEG": 28, - "windSpeedMaxKTS": 15, - "windSpeedMaxKPH": 28, - "windSpeedMaxMPH": 18, - "windDirMin": "NNE", - "windDirMinDEG": 14, - "windSpeedMinKTS": 7, - "windSpeedMinKPH": 14, - "windSpeedMinMPH": 8, - "windDir80m": "NNE", - "windDir80mDEG": 16, - "windSpeed80mKTS": 10, - "windSpeed80mKPH": 19, - "windSpeed80mMPH": 12, - "windGust80mKTS": 17, - "windGust80mKPH": 31, - "windGust80mMPH": 19, - "windDirMax80m": "NNE", - "windDirMax80mDEG": 28, - "windSpeedMax80mKTS": 17, - "windSpeedMax80mKPH": 31, - "windSpeedMax80mMPH": 19, - "windDirMin80m": "NNE", - "windDirMin80mDEG": 13, - "windSpeedMin80mKTS": 9, - "windSpeedMin80mKPH": 18, - "windSpeedMin80mMPH": 11, - "sky": 0, - "cloudsCoded": "CL", - "weather": "Sunny", - "weatherCoded": [], - "weatherPrimary": "Sunny", - "weatherPrimaryCoded": "::CL", - "icon": "sunny.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": null, - "solradWM2": 5450, - "solradMinWM2": 0, - "solradMaxWM2": 758, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665460458, - "sunset": 1665502153, - "sunriseISO": "2022-10-11T05:54:18+02:00", - "sunsetISO": "2022-10-11T17:29:13+02:00" - }, - { - "timestamp": 1665550800, - "validTime": "2022-10-12T07:00:00+02:00", - "dateTimeISO": "2022-10-12T07:00:00+02:00", - "maxTempC": 31, - "maxTempF": 88, - "minTempC": 21, - "minTempF": 69, - "avgTempC": 26, - "avgTempF": 79, - "tempC": null, - "tempF": null, - "maxFeelslikeC": 31, - "maxFeelslikeF": 88, - "minFeelslikeC": 22, - "minFeelslikeF": 72, - "avgFeelslikeC": 26, - "avgFeelslikeF": 80, - "feelslikeC": 22, - "feelslikeF": 72, - "maxDewpointC": 16, - "maxDewpointF": 60, - "minDewpointC": 11, - "minDewpointF": 51, - "avgDewpointC": 13, - "avgDewpointF": 55, - "dewpointC": 16, - "dewpointF": 60, - "maxHumidity": 68, - "minHumidity": 29, - "humidity": 68, - "pop": 0, - "precipMM": 0, - "precipIN": 0, - "iceaccum": null, - "iceaccumMM": null, - "iceaccumIN": null, - "snowCM": 0, - "snowIN": 0, - "pressureMB": 1014, - "pressureIN": 29.95, - "windDir": "NNE", - "windDirDEG": 12, - "windSpeedKTS": 8, - "windSpeedKPH": 15, - "windSpeedMPH": 9, - "windGustKTS": 15, - "windGustKPH": 28, - "windGustMPH": 17, - "windDirMax": "E", - "windDirMaxDEG": 96, - "windSpeedMaxKTS": 14, - "windSpeedMaxKPH": 26, - "windSpeedMaxMPH": 16, - "windDirMin": "NNE", - "windDirMinDEG": 12, - "windSpeedMinKTS": 7, - "windSpeedMinKPH": 13, - "windSpeedMinMPH": 8, - "windDir80m": "NNE", - "windDir80mDEG": 15, - "windSpeed80mKTS": 10, - "windSpeed80mKPH": 19, - "windSpeed80mMPH": 12, - "windGust80mKTS": 18, - "windGust80mKPH": 33, - "windGust80mMPH": 21, - "windDirMax80m": "E", - "windDirMax80mDEG": 96, - "windSpeedMax80mKTS": 18, - "windSpeedMax80mKPH": 33, - "windSpeedMax80mMPH": 21, - "windDirMin80m": "NNE", - "windDirMin80mDEG": 15, - "windSpeedMin80mKTS": 10, - "windSpeedMin80mKPH": 18, - "windSpeedMin80mMPH": 11, - "sky": 27, - "cloudsCoded": "FW", - "weather": "Mostly Sunny", - "weatherCoded": [], - "weatherPrimary": "Mostly Sunny", - "weatherPrimaryCoded": "::FW", - "icon": "fair.png", - "visibilityKM": 24.135, - "visibilityMI": 15, - "uvi": null, - "solradWM2": 4740, - "solradMinWM2": 0, - "solradMaxWM2": 743, - "isDay": true, - "maxCoverage": "", - "sunrise": 1665546895, - "sunset": 1665588484, - "sunriseISO": "2022-10-12T05:54:55+02:00", - "sunsetISO": "2022-10-12T17:28:04+02:00" - } - ], - "profile": { - "tz": "Africa/Cairo", - "elevM": 23, - "elevFT": 75 - } - } - ] -} \ No newline at end of file diff --git a/src/test/resources/Issue593.xml b/src/test/resources/Issue593.xml deleted file mode 100644 index 0c6c038b6..000000000 --- a/src/test/resources/Issue593.xml +++ /dev/null @@ -1,691 +0,0 @@ -true - - - 31.25 - 30.063 - - - 23 - Africa/Cairo - 75 - - - 2022-10-06T07:00:00+02:00 - E - 95 - 21 - 15 - 10 - 353 - N - 2022-10-06T05:51:14+02:00 - null - 9 - null - 66 - 0 - Mostly Sunny - 2022-10-06T17:35:02+02:00 - 32 - 77 - N - 89 - 0 - 22 - 25 - 25 - Mostly Sunny - 41 - 58 - 41 - 22 - 14 - 0 - 22 - 353 - 16 - 8 - 70 - 2022-10-06T07:00:00+02:00 - 10 - 778 - 25 - 15 - ::FW - 1665028274 - 78 - N - - fair.png - 21 - 17 - FW - 70 - 29 - 63 - 12 - 0 - 0 - NNW - 13 - 22 - 11 - 32 - 1015 - 24.135 - 1665032400 - 90 - null - 11 - 0 - 1 - 343 - 21 - 2 - 63 - 1 - 26 - 6 - NNW - 17 - 29.97 - 80 - null - true - 19 - 52 - 5 - 1665070502 - 5608 - 9 - 25 - 77 - 6 - 40 - 342 - null - - - 2022-10-07T07:00:00+02:00 - NNW - 347 - 19 - 15 - 8 - 325 - NW - 2022-10-07T05:51:50+02:00 - null - 7 - null - 66 - 0 - Mostly Sunny - 2022-10-07T17:33:51+02:00 - 29 - 77 - NNW - 85 - 0 - 30 - 23 - 23 - Mostly Sunny - 37 - 54 - 37 - 20 - 12 - 0 - 20 - 325 - 13 - 6 - 67 - 2022-10-07T07:00:00+02:00 - 6 - 742 - 24 - 10 - ::FW - 1665114710 - 76 - NW - - fair.png - 19 - 15 - FW - 67 - 30 - 60 - 6 - 0 - 0 - WNW - 6 - 10 - 347 - 30 - 1014 - 24.135 - 1665118800 - 86 - null - 10 - 0 - 1 - 316 - 16 - 2 - 60 - 1 - 24 - 6 - NW - 15 - 29.95 - 76 - null - true - 19 - 50 - 1 - 1665156831 - 5486 - 2 - 18 - 77 - 1 - 29 - 298 - null - - - 2022-10-08T07:00:00+02:00 - NW - 309 - 19 - 15 - 8 - 21 - NNE - 2022-10-08T05:52:26+02:00 - null - 7 - null - 66 - 0 - Partly Cloudy - 2022-10-08T17:32:41+02:00 - 30 - 76 - NW - 86 - 0 - 47 - 19 - 19 - Partly Cloudy - 31 - 56 - 31 - 17 - 13 - 0 - 17 - 21 - 13 - 5 - 67 - 2022-10-08T07:00:00+02:00 - 5 - 682 - 25 - 9 - ::SC - 1665201146 - 76 - NNE - - pcloudy.png - 19 - 15 - SC - 67 - 32 - 59 - 5 - 0 - 0 - WNW - 5 - 9 - 309 - 30 - 1014 - 24.135 - 1665205200 - 87 - null - 11 - 0 - 1 - 322 - 17 - 2 - 59 - 1 - 25 - 7 - NW - 15 - 29.94 - 76 - null - true - 19 - 52 - 1 - 1665243161 - 4785 - 2 - 20 - 76 - 1 - 32 - 301 - null - - - 2022-10-09T07:00:00+02:00 - NW - 316 - 20 - 15 - 9 - 356 - N - 2022-10-09T05:53:03+02:00 - null - 8 - null - 67 - 0 - Partly Cloudy - 2022-10-09T17:31:31+02:00 - 30 - 86 - NW - 86 - 0 - 47 - 23 - 23 - Partly Cloudy - 36 - 57 - 36 - 20 - 14 - 0 - 20 - 356 - 14 - 5 - 67 - 2022-10-09T07:00:00+02:00 - 6 - 726 - 25 - 9 - ::SC - 1665287583 - 77 - N - - pcloudy.png - 20 - 17 - SC - 67 - 31 - 63 - 5 - 0 - 0 - NNW - 6 - 9 - 316 - 31 - 1016 - 24.135 - 1665291600 - 87 - null - 11 - 0 - 2 - 354 - 19 - 4 - 63 - 2 - 25 - 7 - N - 17 - 29.99 - 77 - null - true - 19 - 52 - 2 - 1665329491 - 4768 - 4 - 22 - 86 - 2 - 36 - 343 - null - - - 2022-10-10T07:00:00+02:00 - E - 91 - 21 - 15 - 9 - 358 - N - 2022-10-10T05:53:40+02:00 - null - 8 - null - 70 - 0 - Partly Cloudy - 2022-10-10T17:30:21+02:00 - 30 - 75 - N - 86 - 0 - 64 - 22 - 22 - Partly Cloudy - 36 - 58 - 36 - 19 - 14 - 0 - 19 - 358 - 15 - 7 - 69 - 2022-10-10T07:00:00+02:00 - 8 - 597 - 26 - 13 - ::SC - 1665374020 - 78 - N - - pcloudy.png - 21 - 16 - SC - 69 - 35 - 61 - 7 - 0 - 0 - N - 8 - 13 - 8 - 31 - 1017 - 24.135 - 1665378000 - 87 - null - 13 - 0 - 2 - 10 - 16 - 4 - 61 - 2 - 25 - 6 - N - 16 - 30.03 - 78 - null - true - 21 - 55 - 2 - 1665415821 - 4494 - 4 - 19 - 75 - 2 - 30 - 10 - null - - - 2022-10-11T07:00:00+02:00 - NNE - 13 - 22 - 15 - 18 - 13 - NNE - 2022-10-11T05:54:18+02:00 - null - 15 - null - 70 - 0 - Sunny - 2022-10-11T17:29:13+02:00 - 31 - 71 - NNE - 87 - 0 - 0 - 19 - 19 - Sunny - 31 - 55 - 31 - 17 - 13 - 0 - 17 - 14 - 28 - 9 - 72 - 2022-10-11T07:00:00+02:00 - 11 - 758 - 26 - 18 - ::CL - 1665460458 - 78 - NNE - - sunny.png - 22 - 17 - CL - 72 - 30 - 62 - 10 - 0 - 0 - NNE - 12 - 19 - 16 - 31 - 1015 - 24.135 - 1665464400 - 87 - null - 11 - 0 - 7 - 28 - 15 - 14 - 62 - 8 - 26 - null - NNE - 17 - 29.98 - 79 - null - true - 21 - 51 - 8 - 1665502153 - 5450 - 15 - 17 - 71 - 9 - 28 - 28 - null - - - 2022-10-12T07:00:00+02:00 - NNE - 15 - 22 - 15 - 16 - 12 - NNE - 2022-10-12T05:54:55+02:00 - null - 14 - null - 69 - 0 - Mostly Sunny - 2022-10-12T17:28:04+02:00 - 31 - 68 - NNE - 88 - 0 - 27 - 21 - 21 - Mostly Sunny - 33 - 55 - 33 - 18 - 13 - 0 - 18 - 12 - 26 - 10 - 72 - 2022-10-12T07:00:00+02:00 - 11 - 743 - 26 - 18 - ::FW - 1665546895 - 79 - NNE - - fair.png - 22 - 16 - FW - 72 - 29 - 60 - 10 - 0 - 0 - E - 12 - 19 - 15 - 31 - 1014 - 24.135 - 1665550800 - 88 - null - 11 - 0 - 7 - 96 - 15 - 13 - 60 - 8 - 26 - null - E - 16 - 29.95 - 80 - null - true - 21 - 51 - 8 - 1665588484 - 4740 - 15 - 17 - 68 - 9 - 28 - 96 - null - - day - - eg - cairo - qh - - -null diff --git a/src/test/resources/Issue654WellFormedArray.json b/src/test/resources/Issue654WellFormedArray.json deleted file mode 100644 index 513e1b460..000000000 --- a/src/test/resources/Issue654WellFormedArray.json +++ /dev/null @@ -1,822 +0,0 @@ -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a", -["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",["a",[] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]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]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] -]]]]]]]]]]]] diff --git a/src/test/resources/Issue654WellFormedObject.json b/src/test/resources/Issue654WellFormedObject.json deleted file mode 100644 index 70344c145..000000000 --- a/src/test/resources/Issue654WellFormedObject.json +++ /dev/null @@ -1,822 +0,0 @@ -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a": -{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{"a":{} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}}}}}}} -}}}}}}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ayExpectedTestCaseForToJsonArrayTest.json b/src/test/resources/JSONArrayExpectedTestCaseForToJsonArrayTest.json deleted file mode 100644 index 6ce0864a2..000000000 --- a/src/test/resources/JSONArrayExpectedTestCaseForToJsonArrayTest.json +++ /dev/null @@ -1,91 +0,0 @@ -[ - "addresses", - { - "xsi:noNamespaceSchemaLocation": "test.xsd", - "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance" - }, - [ - "address", - { - "addrType": "my address" - }, - [ - "name", - { - "nameType": "my name" - }, - "Joe Tester" - ], - [ - "street", - "Baker street 5" - ], - [ - "NothingHere", - { - "except": "an attribute" - } - ], - [ - "TrueValue", - true - ], - [ - "FalseValue", - false - ], - [ - "NullValue", - null - ], - [ - "PositiveValue", - 42 - ], - [ - "NegativeValue", - -23 - ], - [ - "DoubleValue", - -23.45 - ], - [ - "Nan", - "-23x.45" - ], - [ - "ArrayOfNum", - [ - "value", - 1 - ], - [ - "value", - 2 - ], - [ - "value", - [ - "subValue", - { - "svAttr": "svValue" - }, - "abc" - ] - ], - [ - "value", - 3 - ], - [ - "value", - 4.1 - ], - [ - "value", - 5.2 - ] - ] - ] -] diff --git a/src/test/resources/XmlTestCaseTestToJsonArray.xml b/src/test/resources/XmlTestCaseTestToJsonArray.xml deleted file mode 100644 index dfcf9d90c..000000000 --- a/src/test/resources/XmlTestCaseTestToJsonArray.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - -
- Joe Tester - - - true - false - null - 42 - -23 - -23.45 - -23x.45 - - 1 - 2 - - abc - - 3 - 4.1 - 5.2 - -
-
\ No newline at end of file diff --git a/src/test/resources/compliantJsonArray.json b/src/test/resources/compliantJsonArray.json deleted file mode 100644 index c37369027..000000000 --- a/src/test/resources/compliantJsonArray.json +++ /dev/null @@ -1,317 +0,0 @@ -[ - { - "_id": "6606c27d2ab4a0102d49420a", - "index": 0, - "guid": "441331fb-84d1-4873-a649-3814621a0370", - "isActive": true, - "balance": "$2,691.63", - "picture": "http://example.abc/32x32", - "age": 26, - "eyeColor": "blue", - "name": "abc", - "gender": "female", - "company": "example", - "email": "abc@def.com", - "phone": "+1 (123) 456-7890", - "address": "123 Main St", - "about": "Laborum magna tempor officia irure cillum nulla incididunt Lorem dolor veniam elit cupidatat amet. Veniam veniam exercitation nulla consectetur officia esse ex sunt nulla nisi ea cillum nisi reprehenderit. Qui aliquip reprehenderit aliqua aliquip aliquip anim sit magna nostrud dolore veniam velit elit aliquip.\r\n", - "registered": "2016-07-22T03:18:11 -01:00", - "latitude": -21.544934, - "longitude": 72.765495, - "tags": [ - "consectetur", - "minim", - "sunt", - "in", - "ut", - "velit", - "anim" - ], - "friends": [ - { - "id": 0, - "name": "abc def" - }, - { - "id": 1, - "name": "ghi jkl" - }, - { - "id": 2, - "name": "mno pqr" - } - ], - "greeting": "Hello, abc! You have 10 unread messages.", - "favoriteFruit": "banana" - }, - { - "_id": "6606c27d0a45df5121fb765f", - "index": 1, - "guid": "fd774715-de85-44b9-b498-c214d8f68d9f", - "isActive": true, - "balance": "$2,713.96", - "picture": "http://placehold.it/32x32", - "age": 27, - "eyeColor": "green", - "name": "def", - "gender": "female", - "company": "sample", - "email": "def@abc.com", - "phone": "+1 (123) 456-78910", - "address": "1234 Main St", - "about": "Ea id cupidatat eiusmod culpa. Nulla consequat esse elit enim et pariatur eiusmod ipsum. Consequat eu non reprehenderit in.\r\n", - "registered": "2015-04-06T07:54:22 -01:00", - "latitude": 83.512347, - "longitude": -9.368739, - "tags": [ - "excepteur", - "non", - "nostrud", - "laboris", - "laboris", - "qui", - "aute" - ], - "friends": [ - { - "id": 0, - "name": "sample example" - }, - { - "id": 1, - "name": "test name" - }, - { - "id": 2, - "name": "aaa aaaa" - } - ], - "greeting": "Hello, test! You have 7 unread messages.", - "favoriteFruit": "apple" - }, - { - "_id": "6606c27dfb3a0e4e7e7183d3", - "index": 2, - "guid": "688b0c36-98e0-4ee7-86b8-863638d79b5f", - "isActive": false, - "balance": "$3,514.35", - "picture": "http://placehold.it/32x32", - "age": 32, - "eyeColor": "green", - "name": "test", - "gender": "female", - "company": "test", - "email": "test@test.com", - "phone": "+1 (123) 456-7890", - "address": "123 Main St", - "about": "Mollit officia adipisicing ex nisi non Lorem sunt quis est. Irure exercitation duis ipsum qui ullamco eu ea commodo occaecat minim proident. Incididunt nostrud ex cupidatat eiusmod mollit anim irure culpa. Labore voluptate voluptate labore nisi sit eu. Dolor sit proident velit dolor deserunt labore sit ipsum incididunt eiusmod reprehenderit voluptate. Duis anim velit officia laboris consequat officia dolor sint dolor nisi ex.\r\n", - "registered": "2021-11-02T12:50:05 -00:00", - "latitude": -82.969939, - "longitude": 86.415645, - "tags": [ - "aliquip", - "et", - "est", - "nulla", - "nulla", - "tempor", - "adipisicing" - ], - "friends": [ - { - "id": 0, - "name": "test" - }, - { - "id": 1, - "name": "sample" - }, - { - "id": 2, - "name": "example" - } - ], - "greeting": "Hello, test! You have 1 unread messages.", - "favoriteFruit": "strawberry" - }, - { - "_id": "6606c27d204bc2327fc9ba23", - "index": 3, - "guid": "be970cba-306e-4cbd-be08-c265a43a61fa", - "isActive": true, - "balance": "$3,691.63", - "picture": "http://placehold.it/32x32", - "age": 35, - "eyeColor": "brown", - "name": "another test", - "gender": "male", - "company": "TEST", - "email": "anothertest@anothertest.com", - "phone": "+1 (321) 987-6543", - "address": "123 Example Main St", - "about": "Do proident consectetur minim quis. In adipisicing culpa Lorem fugiat cillum exercitation velit velit. Non voluptate laboris deserunt veniam et sint consectetur irure aliqua quis eiusmod consectetur elit id. Ex sint do anim Lorem excepteur eu nulla.\r\n", - "registered": "2020-06-25T04:55:25 -01:00", - "latitude": 63.614955, - "longitude": -109.299405, - "tags": [ - "irure", - "esse", - "non", - "mollit", - "laborum", - "adipisicing", - "ad" - ], - "friends": [ - { - "id": 0, - "name": "test" - }, - { - "id": 1, - "name": "sample" - }, - { - "id": 2, - "name": "example" - } - ], - "greeting": "Hello, another test! You have 5 unread messages.", - "favoriteFruit": "apple" - }, - { - "_id": "6606c27df63eb5f390cb9989", - "index": 4, - "guid": "2c3e5115-758d-468e-99c5-c9afa26e1f9f", - "isActive": true, - "balance": "$1,047.20", - "picture": "http://test.it/32x32", - "age": 30, - "eyeColor": "green", - "name": "Test Name", - "gender": "female", - "company": "test", - "email": "testname@testname.com", - "phone": "+1 (999) 999-9999", - "address": "999 Test Main St", - "about": "Voluptate exercitation tempor consectetur velit magna ea occaecat cupidatat consectetur anim aute. Aliquip est aute ipsum laboris non irure qui consectetur tempor quis do ea Lorem. Cupidatat exercitation ad culpa aliqua amet commodo mollit reprehenderit exercitation adipisicing amet et laborum pariatur.\r\n", - "registered": "2023-01-19T02:43:18 -00:00", - "latitude": 14.15208, - "longitude": 170.411535, - "tags": [ - "dolor", - "qui", - "cupidatat", - "aliqua", - "laboris", - "reprehenderit", - "sint" - ], - "friends": [ - { - "id": 0, - "name": "test" - }, - { - "id": 1, - "name": "sample" - }, - { - "id": 2, - "name": "example" - } - ], - "greeting": "Hello, test! You have 6 unread messages.", - "favoriteFruit": "apple" - }, - { - "_id": "6606c27d01d19fa29853d59c", - "index": 5, - "guid": "816cda74-5d4b-498f-9724-20f340d5f5bf", - "isActive": false, - "balance": "$2,628.74", - "picture": "http://testing.it/32x32", - "age": 28, - "eyeColor": "green", - "name": "Testing", - "gender": "female", - "company": "test", - "email": "testing@testing.com", - "phone": "+1 (888) 888-8888", - "address": "123 Main St", - "about": "Cupidatat non ut nulla qui excepteur in minim non et nulla fugiat. Dolor quis laborum occaecat veniam dolor ullamco deserunt amet veniam dolor quis proident tempor laboris. In cillum duis ut quis. Aliqua cupidatat magna proident velit tempor veniam et consequat laborum ex dolore qui. Incididunt deserunt magna minim Lorem consectetur.\r\n", - "registered": "2017-10-14T11:14:08 -01:00", - "latitude": -5.345728, - "longitude": -9.706491, - "tags": [ - "officia", - "velit", - "laboris", - "qui", - "cupidatat", - "cupidatat", - "ad" - ], - "friends": [ - { - "id": 0, - "name": "test" - }, - { - "id": 1, - "name": "sample" - }, - { - "id": 2, - "name": "example" - } - ], - "greeting": "Hello, testing! You have 2 unread messages.", - "favoriteFruit": "strawberry" - }, - { - "_id": "6606c27d803003cede1d6deb", - "index": 6, - "guid": "4ee550bc-0920-4104-b3ce-ebf9db6a803f", - "isActive": true, - "balance": "$1,709.31", - "picture": "http://sample.it/32x32", - "age": 31, - "eyeColor": "blue", - "name": "Sample Name", - "gender": "female", - "company": "Sample", - "email": "sample@sample.com", - "phone": "+1 (777) 777-7777", - "address": "123 Main St", - "about": "Lorem ex proident ipsum ullamco velit sit nisi eiusmod cillum. Id tempor irure culpa nisi sit non qui veniam non ut. Aliquip reprehenderit excepteur mollit quis excepteur ex sit. Quis do eu veniam do ullamco occaecat eu cupidatat nisi laborum tempor minim fugiat pariatur. Ex in nulla ex velit.\r\n", - "registered": "2019-04-08T03:54:36 -01:00", - "latitude": -70.660321, - "longitude": 71.547525, - "tags": [ - "consequat", - "veniam", - "pariatur", - "aliqua", - "cillum", - "eu", - "officia" - ], - "friends": [ - { - "id": 0, - "name": "Test" - }, - { - "id": 1, - "name": "Sample" - }, - { - "id": 2, - "name": "Example" - } - ], - "greeting": "Hello, Sample! You have 6 unread messages.", - "favoriteFruit": "apple" - } -] \ No newline at end of file diff --git a/src/test/resources/jsonpointer-testdoc.json b/src/test/resources/jsonpointer-testdoc.json deleted file mode 100644 index 657ccdd34..000000000 --- a/src/test/resources/jsonpointer-testdoc.json +++ /dev/null @@ -1,28 +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, - "obj" : { - "key" : "value", - "other~key" : { - "another/key" : [ - "val" - ] - }, - "" : { - "" : "empty key of an object with an empty key", - "subKey" : "Some other value" - } - } -} \ No newline at end of file From dad0cd189a0897a9788ae30990cbb83423b7bfdc Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:29:51 +0800 Subject: [PATCH 2/8] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E7=B1=BB=E4=B8=94=E6=9B=B4=E6=96=B0get()=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E5=85=81=E8=AE=B8null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 112 +- jitpack.yml | 6 + pom.xml | 172 +-- src/main/java/org/json/CDL.java | 382 ------ src/main/java/org/json/Cookie.java | 210 ---- src/main/java/org/json/CookieList.java | 72 -- src/main/java/org/json/HTTP.java | 148 --- src/main/java/org/json/HTTPTokener.java | 57 - src/main/java/org/json/JSONArray.java | 6 +- src/main/java/org/json/JSONException.java | 3 + src/main/java/org/json/JSONML.java | 653 ----------- .../org/json/JSONMLParserConfiguration.java | 69 -- src/main/java/org/json/JSONObject.java | 6 +- src/main/java/org/json/Property.java | 62 - src/main/java/org/json/XML.java | 1040 ----------------- .../java/org/json/XMLParserConfiguration.java | 372 ------ src/main/java/org/json/XMLTokener.java | 410 ------- .../java/org/json/XMLXsiTypeConverter.java | 53 - 18 files changed, 17 insertions(+), 3816 deletions(-) create mode 100644 jitpack.yml delete mode 100644 src/main/java/org/json/CDL.java delete mode 100644 src/main/java/org/json/Cookie.java delete mode 100644 src/main/java/org/json/CookieList.java delete mode 100644 src/main/java/org/json/HTTP.java delete mode 100644 src/main/java/org/json/HTTPTokener.java delete mode 100644 src/main/java/org/json/JSONML.java delete mode 100644 src/main/java/org/json/JSONMLParserConfiguration.java delete mode 100644 src/main/java/org/json/Property.java delete mode 100644 src/main/java/org/json/XML.java delete mode 100644 src/main/java/org/json/XMLParserConfiguration.java delete mode 100644 src/main/java/org/json/XMLTokener.java delete mode 100644 src/main/java/org/json/XMLXsiTypeConverter.java diff --git a/README.md b/README.md index 78920a180..2c9872ec0 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,2 @@ -![Json-Java logo](https://github.com/stleary/JSON-java/blob/master/images/JsonJava.png?raw=true) - -image credit: Ismael Pérez Ortiz - - -JSON in Java [package org.json] -=============================== - -[![Maven Central](https://img.shields.io/maven-central/v/org.json/json.svg)](https://mvnrepository.com/artifact/org.json/json) -[![Java CI with Maven](https://github.com/stleary/JSON-java/actions/workflows/pipeline.yml/badge.svg)](https://github.com/stleary/JSON-java/actions/workflows/pipeline.yml) -[![CodeQL](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml) - -**[Click here if you just want the latest release jar file.](https://search.maven.org/remotecontent?filepath=org/json/json/20240303/json-20240303.jar)** - - -# Overview - -[JSON](http://www.JSON.org/) is a light-weight language-independent data interchange format. - -The JSON-Java package is a reference implementation that demonstrates how to parse JSON documents into Java objects and how to generate new JSON documents from the Java classes. - -Project goals include: -* Reliable and consistent results -* Adherence to the JSON specification -* Easy to build, use, and include in other projects -* No external dependencies -* Fast execution and low memory footprint -* Maintain backward compatibility -* Designed and tested to use on Java versions 1.6 - 21 - - -The files in this package implement JSON encoders and decoders. The package can also convert between JSON and XML, HTTP headers, Cookies, and CDL. - -# If you would like to contribute to this project - -For more information on contributions, please see [CONTRIBUTING.md](https://github.com/stleary/JSON-java/blob/master/docs/CONTRIBUTING.md) - -Bug fixes, code improvements, and unit test coverage changes are welcome! Because this project is currently in the maintenance phase, the kinds of changes that can be accepted are limited. For more information, please read the [FAQ](https://github.com/stleary/JSON-java/wiki/FAQ). - -# Build Instructions - -The org.json package can be built from the command line, Maven, and Gradle. The unit tests can be executed from Maven, Gradle, or individually in an IDE e.g. Eclipse. - -**Building from the command line** - -*Build the class files from the package root directory src/main/java* -```shell -javac org/json/*.java -``` - -*Create the jar file in the current directory* -```shell -jar cf json-java.jar org/json/*.class -``` - -*Compile a program that uses the jar (see example code below)* -```shell -javac -cp .;json-java.jar Test.java (Windows) -javac -cp .:json-java.jar Test.java (Unix Systems) -``` - -*Test file contents* - -```java -import org.json.JSONObject; -public class Test { - public static void main(String args[]){ - JSONObject jo = new JSONObject("{ \"abc\" : \"def\" }"); - System.out.println(jo); - } -} -``` - -*Execute the Test file* -```shell -java -cp .;json-java.jar Test (Windows) -java -cp .:json-java.jar Test (Unix Systems) -``` - -*Expected output* - -```json -{"abc":"def"} -``` - - -**Tools to build the package and execute the unit tests** - -Execute the test suite with Maven: -```shell -mvn clean test -``` - -Execute the test suite with Gradlew: - -```shell -gradlew clean build test -``` - -# Notes - -For more information, please see [NOTES.md](https://github.com/stleary/JSON-java/blob/master/docs/NOTES.md) - -# Files - -For more information on files, please see [FILES.md](https://github.com/stleary/JSON-java/blob/master/docs/FILES.md) - -# Release history: - -For the release history, please see [RELEASES.md](https://github.com/stleary/JSON-java/blob/master/docs/RELEASES.md) +A fork from JSON-JAVA +You shouldn't use it. \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 000000000..d2d01527d --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,6 @@ +before_install: + - sdk install java 17.0.5-zulu + - sdk use java 17.0.5-zulu + +jdk: + - openjdk17 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7b102433b..75c21aa25 100644 --- a/pom.xml +++ b/pom.xml @@ -3,112 +3,19 @@ org.json json - 20240303 - bundle + qs-fork-3.1.1 + jar JSON in Java - - JSON is a light-weight, language independent, data interchange format. - See http://www.JSON.org/ - - The files in this package implement JSON encoders/decoders in Java. - It also includes the capability to convert between JSON and XML, HTTP - headers, Cookies, and CDL. - - This is a reference implementation. There are a large number of JSON packages - in Java. Perhaps someday the Java community will standardize on one. Until - then, choose carefully. - - https://github.com/douglascrockford/JSON-java - - - https://github.com/douglascrockford/JSON-java.git - scm:git:git://github.com/douglascrockford/JSON-java.git - scm:git:git@github.com:douglascrockford/JSON-java.git - - - - - Public Domain - https://github.com/stleary/JSON-java/blob/master/LICENSE - repo - - - - - - Douglas Crockford - douglas@crockford.com - - UTF-8 + 17 + 17 - - - - ossrh - Central Repository OSSRH - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - - - - junit - junit - 4.13.2 - test - - - com.jayway.jsonpath - json-path - 2.4.0 - test - - - org.mockito - mockito-core - 4.2.0 - test - - - - - org.apache.felix - maven-bundle-plugin - 5.1.9 - true - - - - org.json - - ${project.artifactId} - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - 1.8 - 1.8 - - -Xlint:unchecked - - - org.apache.maven.plugins maven-source-plugin @@ -122,77 +29,6 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 3.5.0 - - - attach-javadocs - - jar - - - -Xdoclint:none - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - false - - - - org.moditect - moditect-maven-plugin - 1.0.0.Final - - - add-module-infos - package - - add-module-info - - - 9 - - - module org.json { - exports org.json; - } - - - - - - org.apache.maven.plugins maven-jar-plugin diff --git a/src/main/java/org/json/CDL.java b/src/main/java/org/json/CDL.java deleted file mode 100644 index b495de12b..000000000 --- a/src/main/java/org/json/CDL.java +++ /dev/null @@ -1,382 +0,0 @@ -package org.json; - -/* -Public Domain. - */ - -/** - * This provides static methods to convert comma (or otherwise) delimited text into a - * JSONArray, and to convert a JSONArray into comma (or otherwise) delimited text. Comma - * delimited text is a very popular format for data interchange. It is - * understood by most database, spreadsheet, and organizer programs. - *

- * Each row of text represents a row in a table or a data record. Each row - * ends with a NEWLINE character. Each row contains one or more values. - * Values are separated by commas. A value can contain any character except - * for comma, unless it is wrapped in single quotes or double quotes. - *

- * The first row usually contains the names of the columns. - *

- * A comma delimited list can be converted into a JSONArray of JSONObjects. - * The names for the elements in the JSONObjects can be taken from the names - * in the first row. - * @author JSON.org - * @version 2016-05-01 - */ -public class CDL { - - /** - * Constructs a new CDL object. - */ - public CDL() { - } - - /** - * Get the next value. The value can be wrapped in quotes. The value can - * be empty. - * @param x A JSONTokener of the source text. - * @param delimiter used in the file - * @return The value string, or null if empty. - * @throws JSONException if the quoted string is badly formed. - */ - private static String getValue(JSONTokener x, char delimiter) throws JSONException { - char c; - char q; - StringBuilder sb; - do { - c = x.next(); - } while (c == ' ' || c == '\t'); - if (c == 0) { - return null; - } else if (c == '"' || c == '\'') { - q = c; - sb = new StringBuilder(); - for (;;) { - c = x.next(); - if (c == q) { - //Handle escaped double-quote - char nextC = x.next(); - if (nextC != '\"') { - // if our quote was the end of the file, don't step - if (nextC > 0) { - x.back(); - } - break; - } - } - if (c == 0 || c == '\n' || c == '\r') { - throw x.syntaxError("Missing close quote '" + q + "'."); - } - sb.append(c); - } - return sb.toString(); - } else if (c == delimiter) { - x.back(); - return ""; - } - x.back(); - return x.nextTo(delimiter); - } - - /** - * Produce a JSONArray of strings from a row of comma delimited values. - * @param x A JSONTokener of the source text. - * @return A JSONArray of strings. - * @throws JSONException if a called function fails - */ - public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { - return rowToJSONArray(x, ','); - } - - /** - * Produce a JSONArray of strings from a row of comma delimited values. - * @param x A JSONTokener of the source text. - * @param delimiter custom delimiter char - * @return A JSONArray of strings. - * @throws JSONException if a called function fails - */ - public static JSONArray rowToJSONArray(JSONTokener x, char delimiter) throws JSONException { - JSONArray ja = new JSONArray(); - for (;;) { - String value = getValue(x,delimiter); - char c = x.next(); - if (value == null || - (ja.length() == 0 && value.length() == 0 && c != delimiter)) { - return null; - } - ja.put(value); - for (;;) { - if (c == delimiter) { - break; - } - if (c != ' ') { - if (c == '\n' || c == '\r' || c == 0) { - return ja; - } - throw x.syntaxError("Bad character '" + c + "' (" + - (int)c + ")."); - } - c = x.next(); - } - } - } - - /** - * Produce a JSONObject from a row of comma delimited text, using a - * parallel JSONArray of strings to provides the names of the elements. - * @param names A JSONArray of names. This is commonly obtained from the - * first row of a comma delimited text file using the rowToJSONArray - * method. - * @param x A JSONTokener of the source text. - * @return A JSONObject combining the names and values. - * @throws JSONException if a called function fails - */ - public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws JSONException { - return rowToJSONObject(names, x, ','); - } - - /** - * Produce a JSONObject from a row of comma delimited text, using a - * parallel JSONArray of strings to provides the names of the elements. - * @param names A JSONArray of names. This is commonly obtained from the - * first row of a comma delimited text file using the rowToJSONArray - * method. - * @param x A JSONTokener of the source text. - * @param delimiter custom delimiter char - * @return A JSONObject combining the names and values. - * @throws JSONException if a called function fails - */ - public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x, char delimiter) throws JSONException { - JSONArray ja = rowToJSONArray(x, delimiter); - return ja != null ? ja.toJSONObject(names) : null; - } - - /** - * Produce a comma delimited text row from a JSONArray. Values containing - * the comma character will be quoted. Troublesome characters may be - * removed. - * @param ja A JSONArray of strings. - * @return A string ending in NEWLINE. - */ - public static String rowToString(JSONArray ja) { - return rowToString(ja, ','); - } - - /** - * Produce a comma delimited text row from a JSONArray. Values containing - * the comma character will be quoted. Troublesome characters may be - * removed. - * @param ja A JSONArray of strings. - * @param delimiter custom delimiter char - * @return A string ending in NEWLINE. - */ - public static String rowToString(JSONArray ja, char delimiter) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ja.length(); i += 1) { - if (i > 0) { - sb.append(delimiter); - } - Object object = ja.opt(i); - if (object != null) { - String string = object.toString(); - if (string.length() > 0 && (string.indexOf(delimiter) >= 0 || - string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 || - string.indexOf(0) >= 0 || string.charAt(0) == '"')) { - sb.append('"'); - int length = string.length(); - for (int j = 0; j < length; j += 1) { - char c = string.charAt(j); - if (c >= ' ' && c != '"') { - sb.append(c); - } - } - sb.append('"'); - } else { - sb.append(string); - } - } - } - sb.append('\n'); - return sb.toString(); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string, - * using the first row as a source of names. - * @param string The comma delimited text. - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(String string) throws JSONException { - return toJSONArray(string, ','); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string, - * using the first row as a source of names. - * @param string The comma delimited text. - * @param delimiter custom delimiter char - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(String string, char delimiter) throws JSONException { - return toJSONArray(new JSONTokener(string), delimiter); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string, - * using the first row as a source of names. - * @param x The JSONTokener containing the comma delimited text. - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONTokener x) throws JSONException { - return toJSONArray(x, ','); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string, - * using the first row as a source of names. - * @param x The JSONTokener containing the comma delimited text. - * @param delimiter custom delimiter char - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONTokener x, char delimiter) throws JSONException { - return toJSONArray(rowToJSONArray(x, delimiter), x, delimiter); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string - * using a supplied JSONArray as the source of element names. - * @param names A JSONArray of strings. - * @param string The comma delimited text. - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { - return toJSONArray(names, string, ','); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string - * using a supplied JSONArray as the source of element names. - * @param names A JSONArray of strings. - * @param string The comma delimited text. - * @param delimiter custom delimiter char - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONArray names, String string, char delimiter) throws JSONException { - return toJSONArray(names, new JSONTokener(string), delimiter); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string - * using a supplied JSONArray as the source of element names. - * @param names A JSONArray of strings. - * @param x A JSONTokener of the source text. - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException { - return toJSONArray(names, x, ','); - } - - /** - * Produce a JSONArray of JSONObjects from a comma delimited text string - * using a supplied JSONArray as the source of element names. - * @param names A JSONArray of strings. - * @param x A JSONTokener of the source text. - * @param delimiter custom delimiter char - * @return A JSONArray of JSONObjects. - * @throws JSONException if a called function fails - */ - public static JSONArray toJSONArray(JSONArray names, JSONTokener x, char delimiter) throws JSONException { - if (names == null || names.length() == 0) { - return null; - } - JSONArray ja = new JSONArray(); - for (;;) { - JSONObject jo = rowToJSONObject(names, x, delimiter); - if (jo == null) { - break; - } - ja.put(jo); - } - if (ja.length() == 0) { - return null; - } - return ja; - } - - - /** - * Produce a comma delimited text from a JSONArray of JSONObjects. The - * first row will be a list of names obtained by inspecting the first - * JSONObject. - * @param ja A JSONArray of JSONObjects. - * @return A comma delimited text. - * @throws JSONException if a called function fails - */ - public static String toString(JSONArray ja) throws JSONException { - return toString(ja, ','); - } - - /** - * Produce a comma delimited text from a JSONArray of JSONObjects. The - * first row will be a list of names obtained by inspecting the first - * JSONObject. - * @param ja A JSONArray of JSONObjects. - * @param delimiter custom delimiter char - * @return A comma delimited text. - * @throws JSONException if a called function fails - */ - public static String toString(JSONArray ja, char delimiter) throws JSONException { - JSONObject jo = ja.optJSONObject(0); - if (jo != null) { - JSONArray names = jo.names(); - if (names != null) { - return rowToString(names, delimiter) + toString(names, ja, delimiter); - } - } - return null; - } - - /** - * Produce a comma delimited text from a JSONArray of JSONObjects using - * a provided list of names. The list of names is not included in the - * output. - * @param names A JSONArray of strings. - * @param ja A JSONArray of JSONObjects. - * @return A comma delimited text. - * @throws JSONException if a called function fails - */ - public static String toString(JSONArray names, JSONArray ja) throws JSONException { - return toString(names, ja, ','); - } - - /** - * Produce a comma delimited text from a JSONArray of JSONObjects using - * a provided list of names. The list of names is not included in the - * output. - * @param names A JSONArray of strings. - * @param ja A JSONArray of JSONObjects. - * @param delimiter custom delimiter char - * @return A comma delimited text. - * @throws JSONException if a called function fails - */ - public static String toString(JSONArray names, JSONArray ja, char delimiter) throws JSONException { - if (names == null || names.length() == 0) { - return null; - } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ja.length(); i += 1) { - JSONObject jo = ja.optJSONObject(i); - if (jo != null) { - sb.append(rowToString(jo.toJSONArray(names), delimiter)); - } - } - return sb.toString(); - } -} diff --git a/src/main/java/org/json/Cookie.java b/src/main/java/org/json/Cookie.java deleted file mode 100644 index ab908a304..000000000 --- a/src/main/java/org/json/Cookie.java +++ /dev/null @@ -1,210 +0,0 @@ -package org.json; - -import java.util.Locale; - -/* -Public Domain. -*/ - -/** - * Convert a web browser cookie specification to a JSONObject and back. - * JSON and Cookies are both notations for name/value pairs. - * See also: https://tools.ietf.org/html/rfc6265 - * @author JSON.org - * @version 2015-12-09 - */ -public class Cookie { - - /** - * Constructs a new Cookie object. - */ - public Cookie() { - } - - /** - * Produce a copy of a string in which the characters '+', '%', '=', ';' - * and control characters are replaced with "%hh". This is a gentle form - * of URL encoding, attempting to cause as little distortion to the - * string as possible. The characters '=' and ';' are meta characters in - * cookies. By convention, they are escaped using the URL-encoding. This is - * only a convention, not a standard. Often, cookies are expected to have - * encoded values. We encode '=' and ';' because we must. We encode '%' and - * '+' because they are meta characters in URL encoding. - * @param string The source string. - * @return The escaped result. - */ - public static String escape(String string) { - char c; - String s = string.trim(); - int length = s.length(); - StringBuilder sb = new StringBuilder(length); - for (int i = 0; i < length; i += 1) { - c = s.charAt(i); - if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { - sb.append('%'); - sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16)); - sb.append(Character.forDigit((char)(c & 0x0f), 16)); - } else { - sb.append(c); - } - } - return sb.toString(); - } - - - /** - * Convert a cookie specification string into a JSONObject. The string - * must contain a name value pair separated by '='. The name and the value - * will be unescaped, possibly converting '+' and '%' sequences. The - * cookie properties may follow, separated by ';', also represented as - * name=value (except the Attribute properties like "Secure" or "HttpOnly", - * which do not have a value. The value {@link Boolean#TRUE} will be used for these). - * The name will be stored under the key "name", and the value will be - * stored under the key "value". This method does not do checking or - * validation of the parameters. It only converts the cookie string into - * a JSONObject. All attribute names are converted to lower case keys in the - * JSONObject (HttpOnly => httponly). If an attribute is specified more than - * once, only the value found closer to the end of the cookie-string is kept. - * @param string The cookie specification string. - * @return A JSONObject containing "name", "value", and possibly other - * members. - * @throws JSONException If there is an error parsing the Cookie String. - * Cookie strings must have at least one '=' character and the 'name' - * portion of the cookie must not be blank. - */ - public static JSONObject toJSONObject(String string) { - final JSONObject jo = new JSONObject(); - String name; - Object value; - - - JSONTokener x = new JSONTokener(string); - - name = unescape(x.nextTo('=').trim()); - //per RFC6265, if the name is blank, the cookie should be ignored. - if("".equals(name)) { - throw new JSONException("Cookies must have a 'name'"); - } - jo.put("name", name); - // per RFC6265, if there is no '=', the cookie should be ignored. - // the 'next' call here throws an exception if the '=' is not found. - x.next('='); - jo.put("value", unescape(x.nextTo(';')).trim()); - // discard the ';' - x.next(); - // parse the remaining cookie attributes - while (x.more()) { - name = unescape(x.nextTo("=;")).trim().toLowerCase(Locale.ROOT); - // don't allow a cookies attributes to overwrite its name or value. - if("name".equalsIgnoreCase(name)) { - throw new JSONException("Illegal attribute name: 'name'"); - } - if("value".equalsIgnoreCase(name)) { - throw new JSONException("Illegal attribute name: 'value'"); - } - // check to see if it's a flag property - if (x.next() != '=') { - value = Boolean.TRUE; - } else { - value = unescape(x.nextTo(';')).trim(); - x.next(); - } - // only store non-blank attributes - if(!"".equals(name) && !"".equals(value)) { - jo.put(name, value); - } - } - return jo; - } - - - /** - * Convert a JSONObject into a cookie specification string. The JSONObject - * must contain "name" and "value" members (case insensitive). - * If the JSONObject contains other members, they will be appended to the cookie - * specification string. User-Agents are instructed to ignore unknown attributes, - * so ensure your JSONObject is using only known attributes. - * See also: https://tools.ietf.org/html/rfc6265 - * @param jo A JSONObject - * @return A cookie specification string - * @throws JSONException thrown if the cookie has no name. - */ - public static String toString(JSONObject jo) throws JSONException { - StringBuilder sb = new StringBuilder(); - - String name = null; - Object value = null; - for(String key : jo.keySet()){ - if("name".equalsIgnoreCase(key)) { - name = jo.getString(key).trim(); - } - if("value".equalsIgnoreCase(key)) { - value=jo.getString(key).trim(); - } - if(name != null && value != null) { - break; - } - } - - if(name == null || "".equals(name.trim())) { - throw new JSONException("Cookie does not have a name"); - } - if(value == null) { - value = ""; - } - - sb.append(escape(name)); - sb.append("="); - sb.append(escape((String)value)); - - for(String key : jo.keySet()){ - if("name".equalsIgnoreCase(key) - || "value".equalsIgnoreCase(key)) { - // already processed above - continue; - } - value = jo.opt(key); - if(value instanceof Boolean) { - if(Boolean.TRUE.equals(value)) { - sb.append(';').append(escape(key)); - } - // don't emit false values - } else { - sb.append(';') - .append(escape(key)) - .append('=') - .append(escape(value.toString())); - } - } - - return sb.toString(); - } - - /** - * Convert %hh sequences to single characters, and - * convert plus to space. - * @param string A string that may contain - * + (plus) and - * %hh sequences. - * @return The unescaped string. - */ - public static String unescape(String string) { - int length = string.length(); - StringBuilder sb = new StringBuilder(length); - for (int i = 0; i < length; ++i) { - char c = string.charAt(i); - if (c == '+') { - c = ' '; - } else if (c == '%' && i + 2 < length) { - int d = JSONTokener.dehexchar(string.charAt(i + 1)); - int e = JSONTokener.dehexchar(string.charAt(i + 2)); - if (d >= 0 && e >= 0) { - c = (char)(d * 16 + e); - i += 2; - } - } - sb.append(c); - } - return sb.toString(); - } -} diff --git a/src/main/java/org/json/CookieList.java b/src/main/java/org/json/CookieList.java deleted file mode 100644 index d1064db52..000000000 --- a/src/main/java/org/json/CookieList.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.json; - -/* -Public Domain. - */ - -/** - * Convert a web browser cookie list string to a JSONObject and back. - * @author JSON.org - * @version 2015-12-09 - */ -public class CookieList { - - /** - * Constructs a new CookieList object. - */ - public CookieList() { - } - - /** - * Convert a cookie list into a JSONObject. A cookie list is a sequence - * of name/value pairs. The names are separated from the values by '='. - * The pairs are separated by ';'. The names and the values - * will be unescaped, possibly converting '+' and '%' sequences. - * - * To add a cookie to a cookie list, - * cookielistJSONObject.put(cookieJSONObject.getString("name"), - * cookieJSONObject.getString("value")); - * @param string A cookie list string - * @return A JSONObject - * @throws JSONException if a called function fails - */ - public static JSONObject toJSONObject(String string) throws JSONException { - JSONObject jo = new JSONObject(); - JSONTokener x = new JSONTokener(string); - while (x.more()) { - String name = Cookie.unescape(x.nextTo('=')); - x.next('='); - jo.put(name, Cookie.unescape(x.nextTo(';'))); - x.next(); - } - return jo; - } - - /** - * Convert a JSONObject into a cookie list. A cookie list is a sequence - * of name/value pairs. The names are separated from the values by '='. - * The pairs are separated by ';'. The characters '%', '+', '=', and ';' - * in the names and values are replaced by "%hh". - * @param jo A JSONObject - * @return A cookie list string - * @throws JSONException if a called function fails - */ - public static String toString(JSONObject jo) throws JSONException { - boolean isEndOfPair = false; - final StringBuilder sb = new StringBuilder(); - // Don't use the new entrySet API to maintain Android support - for (final String key : jo.keySet()) { - final Object value = jo.opt(key); - if (!JSONObject.NULL.equals(value)) { - if (isEndOfPair) { - sb.append(';'); - } - sb.append(Cookie.escape(key)); - sb.append("="); - sb.append(Cookie.escape(value.toString())); - isEndOfPair = true; - } - } - return sb.toString(); - } -} diff --git a/src/main/java/org/json/HTTP.java b/src/main/java/org/json/HTTP.java deleted file mode 100644 index 44ab3a6d3..000000000 --- a/src/main/java/org/json/HTTP.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -import java.util.Locale; - -/** - * Convert an HTTP header to a JSONObject and back. - * @author JSON.org - * @version 2015-12-09 - */ -public class HTTP { - - /** - * Constructs a new HTTP object. - */ - public HTTP() { - } - - /** Carriage return/line feed. */ - public static final String CRLF = "\r\n"; - - /** - * Convert an HTTP header string into a JSONObject. It can be a request - * header or a response header. A request header will contain - *

{
-     *    Method: "POST" (for example),
-     *    "Request-URI": "/" (for example),
-     *    "HTTP-Version": "HTTP/1.1" (for example)
-     * }
- * A response header will contain - *
{
-     *    "HTTP-Version": "HTTP/1.1" (for example),
-     *    "Status-Code": "200" (for example),
-     *    "Reason-Phrase": "OK" (for example)
-     * }
- * In addition, the other parameters in the header will be captured, using - * the HTTP field names as JSON names, so that
{@code
-     *    Date: Sun, 26 May 2002 18:06:04 GMT
-     *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
-     *    Cache-Control: no-cache}
- * become - *
{@code
-     *    Date: "Sun, 26 May 2002 18:06:04 GMT",
-     *    Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
-     *    "Cache-Control": "no-cache",
-     * ...}
- * It does no further checking or conversion. It does not parse dates. - * It does not do '%' transforms on URLs. - * @param string An HTTP header string. - * @return A JSONObject containing the elements and attributes - * of the XML string. - * @throws JSONException if a called function fails - */ - public static JSONObject toJSONObject(String string) throws JSONException { - JSONObject jo = new JSONObject(); - HTTPTokener x = new HTTPTokener(string); - String token; - - token = x.nextToken(); - if (token.toUpperCase(Locale.ROOT).startsWith("HTTP")) { - -// Response - - jo.put("HTTP-Version", token); - jo.put("Status-Code", x.nextToken()); - jo.put("Reason-Phrase", x.nextTo('\0')); - x.next(); - - } else { - -// Request - - jo.put("Method", token); - jo.put("Request-URI", x.nextToken()); - jo.put("HTTP-Version", x.nextToken()); - } - -// Fields - - while (x.more()) { - String name = x.nextTo(':'); - x.next(':'); - jo.put(name, x.nextTo('\0')); - x.next(); - } - return jo; - } - - - /** - * Convert a JSONObject into an HTTP header. A request header must contain - *
{
-     *    Method: "POST" (for example),
-     *    "Request-URI": "/" (for example),
-     *    "HTTP-Version": "HTTP/1.1" (for example)
-     * }
- * A response header must contain - *
{
-     *    "HTTP-Version": "HTTP/1.1" (for example),
-     *    "Status-Code": "200" (for example),
-     *    "Reason-Phrase": "OK" (for example)
-     * }
- * Any other members of the JSONObject will be output as HTTP fields. - * The result will end with two CRLF pairs. - * @param jo A JSONObject - * @return An HTTP header string. - * @throws JSONException if the object does not contain enough - * information. - */ - public static String toString(JSONObject jo) throws JSONException { - StringBuilder sb = new StringBuilder(); - if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { - sb.append(jo.getString("HTTP-Version")); - sb.append(' '); - sb.append(jo.getString("Status-Code")); - sb.append(' '); - sb.append(jo.getString("Reason-Phrase")); - } else if (jo.has("Method") && jo.has("Request-URI")) { - sb.append(jo.getString("Method")); - sb.append(' '); - sb.append('"'); - sb.append(jo.getString("Request-URI")); - sb.append('"'); - sb.append(' '); - sb.append(jo.getString("HTTP-Version")); - } else { - throw new JSONException("Not enough material for an HTTP header."); - } - sb.append(CRLF); - // Don't use the new entrySet API to maintain Android support - for (final String key : jo.keySet()) { - String value = jo.optString(key); - if (!"HTTP-Version".equals(key) && !"Status-Code".equals(key) && - !"Reason-Phrase".equals(key) && !"Method".equals(key) && - !"Request-URI".equals(key) && !JSONObject.NULL.equals(value)) { - sb.append(key); - sb.append(": "); - sb.append(jo.optString(key)); - sb.append(CRLF); - } - } - sb.append(CRLF); - return sb.toString(); - } -} diff --git a/src/main/java/org/json/HTTPTokener.java b/src/main/java/org/json/HTTPTokener.java deleted file mode 100644 index 48cad31a3..000000000 --- a/src/main/java/org/json/HTTPTokener.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -/** - * The HTTPTokener extends the JSONTokener to provide additional methods - * for the parsing of HTTP headers. - * @author JSON.org - * @version 2015-12-09 - */ -public class HTTPTokener extends JSONTokener { - - /** - * Construct an HTTPTokener from a string. - * @param string A source string. - */ - public HTTPTokener(String string) { - super(string); - } - - - /** - * Get the next token or string. This is used in parsing HTTP headers. - * @return A String. - * @throws JSONException if a syntax error occurs - */ - public String nextToken() throws JSONException { - char c; - char q; - StringBuilder sb = new StringBuilder(); - do { - c = next(); - } while (Character.isWhitespace(c)); - if (c == '"' || c == '\'') { - q = c; - for (;;) { - c = next(); - if (c < ' ') { - throw syntaxError("Unterminated string."); - } - if (c == q) { - return sb.toString(); - } - sb.append(c); - } - } - for (;;) { - if (c == 0 || Character.isWhitespace(c)) { - return sb.toString(); - } - sb.append(c); - c = next(); - } - } -} diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index 382359858..f49f295cb 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -328,11 +328,7 @@ public Iterator iterator() { * If there is no value for the index. */ public Object get(int index) throws JSONException { - Object object = this.opt(index); - if (object == null) { - throw new JSONException("JSONArray[" + index + "] not found."); - } - return object; + return this.opt(index); } /** diff --git a/src/main/java/org/json/JSONException.java b/src/main/java/org/json/JSONException.java index 02c29f3fc..f928a4b93 100644 --- a/src/main/java/org/json/JSONException.java +++ b/src/main/java/org/json/JSONException.java @@ -4,6 +4,8 @@ Public Domain. */ +import java.io.Serial; + /** * The JSONException is thrown by the JSON.org classes when things are amiss. * @@ -12,6 +14,7 @@ */ public class JSONException extends RuntimeException { /** Serialization ID */ + @Serial private static final long serialVersionUID = 0; /** diff --git a/src/main/java/org/json/JSONML.java b/src/main/java/org/json/JSONML.java deleted file mode 100644 index 7b53e4da7..000000000 --- a/src/main/java/org/json/JSONML.java +++ /dev/null @@ -1,653 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -/** - * This provides static methods to convert an XML text into a JSONArray or - * JSONObject, and to covert a JSONArray or JSONObject into an XML text using - * the JsonML transform. - * - * @author JSON.org - * @version 2016-01-30 - */ -public class JSONML { - - /** - * Constructs a new JSONML object. - */ - public JSONML() { - } - - /** - * Parse XML values and store them in a JSONArray. - * @param x The XMLTokener containing the source string. - * @param arrayForm true if array form, false if object form. - * @param ja The JSONArray that is containing the current tag or null - * if we are at the outermost level. - * @param keepStrings Don't type-convert text nodes and attribute values - * @return A JSONArray if the value is the outermost tag, otherwise null. - * @throws JSONException if a parsing error occurs - */ - private static Object parse( - XMLTokener x, - boolean arrayForm, - JSONArray ja, - boolean keepStrings, - int currentNestingDepth - ) throws JSONException { - return parse(x,arrayForm, ja, - keepStrings ? JSONMLParserConfiguration.KEEP_STRINGS : JSONMLParserConfiguration.ORIGINAL, - currentNestingDepth); - } - - /** - * Parse XML values and store them in a JSONArray. - * @param x The XMLTokener containing the source string. - * @param arrayForm true if array form, false if object form. - * @param ja The JSONArray that is containing the current tag or null - * if we are at the outermost level. - * @param config The parser configuration: - * JSONMLParserConfiguration.ORIGINAL is the default behaviour; - * JSONMLParserConfiguration.KEEP_STRINGS means Don't type-convert text nodes and attribute values. - * @return A JSONArray if the value is the outermost tag, otherwise null. - * @throws JSONException if a parsing error occurs - */ - private static Object parse( - XMLTokener x, - boolean arrayForm, - JSONArray ja, - JSONMLParserConfiguration config, - int currentNestingDepth - ) throws JSONException { - String attribute; - char c; - String closeTag = null; - int i; - JSONArray newja = null; - JSONObject newjo = null; - Object token; - String tagName = null; - -// Test for and skip past these forms: -// -// -// -// - - while (true) { - if (!x.more()) { - throw x.syntaxError("Bad XML"); - } - token = x.nextContent(); - if (token == XML.LT) { - token = x.nextToken(); - if (token instanceof Character) { - if (token == XML.SLASH) { - -// Close tag "); - } else { - x.back(); - } - } else if (c == '[') { - token = x.nextToken(); - if (token.equals("CDATA") && x.next() == '[') { - if (ja != null) { - ja.put(x.nextCDATA()); - } - } else { - throw x.syntaxError("Expected 'CDATA['"); - } - } else { - i = 1; - do { - token = x.nextMeta(); - if (token == null) { - throw x.syntaxError("Missing '>' after ' 0); - } - } else if (token == XML.QUEST) { - -// "); - } else { - throw x.syntaxError("Misshaped tag"); - } - -// Open tag < - - } else { - if (!(token instanceof String)) { - throw x.syntaxError("Bad tagName '" + token + "'."); - } - tagName = (String)token; - newja = new JSONArray(); - newjo = new JSONObject(); - if (arrayForm) { - newja.put(tagName); - if (ja != null) { - ja.put(newja); - } - } else { - newjo.put("tagName", tagName); - if (ja != null) { - ja.put(newjo); - } - } - token = null; - for (;;) { - if (token == null) { - token = x.nextToken(); - } - if (token == null) { - throw x.syntaxError("Misshaped tag"); - } - if (!(token instanceof String)) { - break; - } - -// attribute = value - - attribute = (String)token; - if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { - throw x.syntaxError("Reserved attribute."); - } - token = x.nextToken(); - if (token == XML.EQ) { - token = x.nextToken(); - if (!(token instanceof String)) { - throw x.syntaxError("Missing value"); - } - newjo.accumulate(attribute, config.isKeepStrings() ? ((String)token) :XML.stringToValue((String)token)); - token = null; - } else { - newjo.accumulate(attribute, ""); - } - } - if (arrayForm && newjo.length() > 0) { - newja.put(newjo); - } - -// Empty tag <.../> - - if (token == XML.SLASH) { - if (x.nextToken() != XML.GT) { - throw x.syntaxError("Misshaped tag"); - } - if (ja == null) { - if (arrayForm) { - return newja; - } - return newjo; - } - -// Content, between <...> and - - } else { - if (token != XML.GT) { - throw x.syntaxError("Misshaped tag"); - } - - if (currentNestingDepth == config.getMaxNestingDepth()) { - throw x.syntaxError("Maximum nesting depth of " + config.getMaxNestingDepth() + " reached"); - } - - closeTag = (String)parse(x, arrayForm, newja, config, currentNestingDepth + 1); - if (closeTag != null) { - if (!closeTag.equals(tagName)) { - throw x.syntaxError("Mismatched '" + tagName + - "' and '" + closeTag + "'"); - } - tagName = null; - if (!arrayForm && newja.length() > 0) { - newjo.put("childNodes", newja); - } - if (ja == null) { - if (arrayForm) { - return newja; - } - return newjo; - } - } - } - } - } else { - if (ja != null) { - ja.put(token instanceof String - ? (config.isKeepStrings() ? XML.unescape((String)token) : XML.stringToValue((String)token)) - : token); - } - } - } - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child tags. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The source string. - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(String string) throws JSONException { - return (JSONArray)parse(new XMLTokener(string), true, null, JSONMLParserConfiguration.ORIGINAL, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child tags. - * As opposed to toJSONArray this method does not attempt to convert - * any text node or attribute value to any type - * but just leaves it as a string. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The source string. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(String string, boolean keepStrings) throws JSONException { - return (JSONArray)parse(new XMLTokener(string), true, null, keepStrings, 0); - } - - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child tags. - * As opposed to toJSONArray this method does not attempt to convert - * any text node or attribute value to any type - * but just leaves it as a string. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The source string. - * @param config The parser configuration: - * JSONMLParserConfiguration.ORIGINAL is the default behaviour; - * JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(String string, JSONMLParserConfiguration config) throws JSONException { - return (JSONArray)parse(new XMLTokener(string), true, null, config, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child content and tags. - * As opposed to toJSONArray this method does not attempt to convert - * any text node or attribute value to any type - * but just leaves it as a string. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener. - * @param config The parser configuration: - * JSONMLParserConfiguration.ORIGINAL is the default behaviour; - * JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(XMLTokener x, JSONMLParserConfiguration config) throws JSONException { - return (JSONArray)parse(x, true, null, config, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child content and tags. - * As opposed to toJSONArray this method does not attempt to convert - * any text node or attribute value to any type - * but just leaves it as a string. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(XMLTokener x, boolean keepStrings) throws JSONException { - return (JSONArray)parse(x, true, null, keepStrings, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONArray using the JsonML transform. Each XML tag is represented as - * a JSONArray in which the first element is the tag name. If the tag has - * attributes, then the second element will be JSONObject containing the - * name/value pairs. If the tag contains children, then strings and - * JSONArrays will represent the child content and tags. - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener. - * @return A JSONArray containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONArray - */ - public static JSONArray toJSONArray(XMLTokener x) throws JSONException { - return (JSONArray)parse(x, true, null, false, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The XML source text. - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(String string) throws JSONException { - return (JSONObject)parse(new XMLTokener(string), false, null, false, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The XML source text. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(String string, boolean keepStrings) throws JSONException { - return (JSONObject)parse(new XMLTokener(string), false, null, keepStrings, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param string The XML source text. - * @param config The parser configuration: - * JSONMLParserConfiguration.ORIGINAL is the default behaviour; - * JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(String string, JSONMLParserConfiguration config) throws JSONException { - return (JSONObject)parse(new XMLTokener(string), false, null, config, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener of the XML source text. - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(XMLTokener x) throws JSONException { - return (JSONObject)parse(x, false, null, false, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener of the XML source text. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(XMLTokener x, boolean keepStrings) throws JSONException { - return (JSONObject)parse(x, false, null, keepStrings, 0); - } - - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject using the JsonML transform. Each XML tag is represented as - * a JSONObject with a "tagName" property. If the tag has attributes, then - * the attributes will be in the JSONObject as properties. If the tag - * contains children, the object will have a "childNodes" property which - * will be an array of strings and JsonML JSONObjects. - - * Comments, prologs, DTDs, and
{@code <[ [ ]]>}
are ignored. - * @param x An XMLTokener of the XML source text. - * @param config The parser configuration: - * JSONMLParserConfiguration.ORIGINAL is the default behaviour; - * JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown on error converting to a JSONObject - */ - public static JSONObject toJSONObject(XMLTokener x, JSONMLParserConfiguration config) throws JSONException { - return (JSONObject)parse(x, false, null, config, 0); - } - - - /** - * Reverse the JSONML transformation, making an XML text from a JSONArray. - * @param ja A JSONArray. - * @return An XML string. - * @throws JSONException Thrown on error converting to a string - */ - public static String toString(JSONArray ja) throws JSONException { - int i; - JSONObject jo; - int length; - Object object; - StringBuilder sb = new StringBuilder(); - String tagName; - -// Emit = length) { - sb.append('/'); - sb.append('>'); - } else { - sb.append('>'); - do { - object = ja.get(i); - i += 1; - if (object != null) { - if (object instanceof String) { - sb.append(XML.escape(object.toString())); - } else if (object instanceof JSONObject) { - sb.append(toString((JSONObject)object)); - } else if (object instanceof JSONArray) { - sb.append(toString((JSONArray)object)); - } else { - sb.append(object.toString()); - } - } - } while (i < length); - sb.append('<'); - sb.append('/'); - sb.append(tagName); - sb.append('>'); - } - return sb.toString(); - } - - - /** - * Reverse the JSONML transformation, making an XML text from a JSONObject. - * The JSONObject must contain a "tagName" property. If it has children, - * then it must have a "childNodes" property containing an array of objects. - * The other properties are attributes with string values. - * @param jo A JSONObject. - * @return An XML string. - * @throws JSONException Thrown on error converting to a string - */ - public static String toString(JSONObject jo) throws JSONException { - StringBuilder sb = new StringBuilder(); - int i; - JSONArray ja; - int length; - Object object; - String tagName; - Object value; - -//Emit '); - } else { - sb.append('>'); - length = ja.length(); - for (i = 0; i < length; i += 1) { - object = ja.get(i); - if (object != null) { - if (object instanceof String) { - sb.append(XML.escape(object.toString())); - } else if (object instanceof JSONObject) { - sb.append(toString((JSONObject)object)); - } else if (object instanceof JSONArray) { - sb.append(toString((JSONArray)object)); - } else { - sb.append(object.toString()); - } - } - } - sb.append('<'); - sb.append('/'); - sb.append(tagName); - sb.append('>'); - } - return sb.toString(); - } -} diff --git a/src/main/java/org/json/JSONMLParserConfiguration.java b/src/main/java/org/json/JSONMLParserConfiguration.java deleted file mode 100644 index 43ba0db62..000000000 --- a/src/main/java/org/json/JSONMLParserConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.json; -/* -Public Domain. -*/ - -/** - * Configuration object for the XML to JSONML parser. The configuration is immutable. - */ -@SuppressWarnings({""}) -public class JSONMLParserConfiguration extends ParserConfiguration { - - /** - * We can override the default maximum nesting depth if needed. - */ - public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH; - - /** Original Configuration of the XML to JSONML Parser. */ - public static final JSONMLParserConfiguration ORIGINAL - = new JSONMLParserConfiguration(); - /** Original configuration of the XML to JSONML Parser except that values are kept as strings. */ - public static final JSONMLParserConfiguration KEEP_STRINGS - = new JSONMLParserConfiguration().withKeepStrings(true); - - /** - * Default parser configuration. Does not keep strings (tries to implicitly convert values). - */ - public JSONMLParserConfiguration() { - super(); - this.maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH; - } - - /** - * Configure the parser string processing and use the default CDATA Tag Name as "content". - * @param keepStrings true to parse all values as string. - * false to try and convert XML string values into a JSON value. - * @param maxNestingDepth int to limit the nesting depth - */ - protected JSONMLParserConfiguration(final boolean keepStrings, final int maxNestingDepth) { - super(keepStrings, maxNestingDepth); - } - - /** - * Provides a new instance of the same configuration. - */ - @Override - protected JSONMLParserConfiguration clone() { - // future modifications to this method should always ensure a "deep" - // clone in the case of collections. i.e. if a Map is added as a configuration - // item, a new map instance should be created and if possible each value in the - // map should be cloned as well. If the values of the map are known to also - // be immutable, then a shallow clone of the map is acceptable. - return new JSONMLParserConfiguration( - this.keepStrings, - this.maxNestingDepth - ); - } - - @SuppressWarnings("unchecked") - @Override - public JSONMLParserConfiguration withKeepStrings(final boolean newVal) { - return super.withKeepStrings(newVal); - } - - @SuppressWarnings("unchecked") - @Override - public JSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) { - return super.withMaxNestingDepth(maxNestingDepth); - } -} diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index 642e96703..ef9ea6fbf 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -614,11 +614,7 @@ public Object get(String key) throws JSONException { if (key == null) { throw new JSONException("Null key."); } - Object object = this.opt(key); - if (object == null) { - throw new JSONException("JSONObject[" + quote(key) + "] not found."); - } - return object; + return this.opt(key); } /** diff --git a/src/main/java/org/json/Property.java b/src/main/java/org/json/Property.java deleted file mode 100644 index ba6c56967..000000000 --- a/src/main/java/org/json/Property.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -import java.util.Enumeration; -import java.util.Properties; - -/** - * Converts a Property file data into JSONObject and back. - * @author JSON.org - * @version 2015-05-05 - */ -public class Property { - - /** - * Constructs a new Property object. - */ - public Property() { - } - - /** - * Converts a property file object into a JSONObject. The property file object is a table of name value pairs. - * @param properties java.util.Properties - * @return JSONObject - * @throws JSONException if a called function has an error - */ - public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException { - // can't use the new constructor for Android support - // JSONObject jo = new JSONObject(properties == null ? 0 : properties.size()); - JSONObject jo = new JSONObject(); - if (properties != null && !properties.isEmpty()) { - Enumeration enumProperties = properties.propertyNames(); - while(enumProperties.hasMoreElements()) { - String name = (String)enumProperties.nextElement(); - jo.put(name, properties.getProperty(name)); - } - } - return jo; - } - - /** - * Converts the JSONObject into a property file object. - * @param jo JSONObject - * @return java.util.Properties - * @throws JSONException if a called function has an error - */ - public static Properties toProperties(JSONObject jo) throws JSONException { - Properties properties = new Properties(); - if (jo != null) { - // Don't use the new entrySet API to maintain Android support - for (final String key : jo.keySet()) { - Object value = jo.opt(key); - if (!JSONObject.NULL.equals(value)) { - properties.put(key, value.toString()); - } - } - } - return properties; - } -} diff --git a/src/main/java/org/json/XML.java b/src/main/java/org/json/XML.java deleted file mode 100644 index e59ec7a4a..000000000 --- a/src/main/java/org/json/XML.java +++ /dev/null @@ -1,1040 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -import java.io.Reader; -import java.io.StringReader; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Iterator; - -/** - * This provides static methods to convert an XML text into a JSONObject, and to - * covert a JSONObject into an XML text. - * - * @author JSON.org - * @version 2016-08-10 - */ -@SuppressWarnings("boxing") -public class XML { - - /** - * Constructs a new XML object. - */ - public XML() { - } - - /** The Character '&'. */ - public static final Character AMP = '&'; - - /** The Character '''. */ - public static final Character APOS = '\''; - - /** The Character '!'. */ - public static final Character BANG = '!'; - - /** The Character '='. */ - public static final Character EQ = '='; - - /** The Character
{@code '>'. }
*/ - public static final Character GT = '>'; - - /** The Character '<'. */ - public static final Character LT = '<'; - - /** The Character '?'. */ - public static final Character QUEST = '?'; - - /** The Character '"'. */ - public static final Character QUOT = '"'; - - /** The Character '/'. */ - public static final Character SLASH = '/'; - - /** - * Null attribute name - */ - public static final String NULL_ATTR = "xsi:nil"; - - /** - * Represents the XML attribute name for specifying type information. - */ - public static final String TYPE_ATTR = "xsi:type"; - - /** - * Creates an iterator for navigating Code Points in a string instead of - * characters. Once Java7 support is dropped, this can be replaced with - * - * string.codePoints() - * - * which is available in Java8 and above. - * - * @see http://stackoverflow.com/a/21791059/6030888 - */ - private static Iterable codePointIterator(final String string) { - return new Iterable() { - @Override - public Iterator iterator() { - return new Iterator() { - private int nextIndex = 0; - private int length = string.length(); - - @Override - public boolean hasNext() { - return this.nextIndex < this.length; - } - - @Override - public Integer next() { - int result = string.codePointAt(this.nextIndex); - this.nextIndex += Character.charCount(result); - return result; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; - } - - /** - * Replace special characters with XML escapes: - * - *
{@code
-     * & (ampersand) is replaced by &amp;
-     * < (less than) is replaced by &lt;
-     * > (greater than) is replaced by &gt;
-     * " (double quote) is replaced by &quot;
-     * ' (single quote / apostrophe) is replaced by &apos;
-     * }
- * - * @param string - * The string to be escaped. - * @return The escaped string. - */ - public static String escape(String string) { - StringBuilder sb = new StringBuilder(string.length()); - for (final int cp : codePointIterator(string)) { - switch (cp) { - case '&': - sb.append("&"); - break; - case '<': - sb.append("<"); - break; - case '>': - sb.append(">"); - break; - case '"': - sb.append("""); - break; - case '\'': - sb.append("'"); - break; - default: - if (mustEscape(cp)) { - sb.append("&#x"); - sb.append(Integer.toHexString(cp)); - sb.append(';'); - } else { - sb.appendCodePoint(cp); - } - } - } - return sb.toString(); - } - - /** - * @param cp code point to test - * @return true if the code point is not valid for an XML - */ - private static boolean mustEscape(int cp) { - /* Valid range from https://www.w3.org/TR/REC-xml/#charsets - * - * #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - * - * any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. - */ - // isISOControl is true when (cp >= 0 && cp <= 0x1F) || (cp >= 0x7F && cp <= 0x9F) - // all ISO control characters are out of range except tabs and new lines - return (Character.isISOControl(cp) - && cp != 0x9 - && cp != 0xA - && cp != 0xD - ) || !( - // valid the range of acceptable characters that aren't control - (cp >= 0x20 && cp <= 0xD7FF) - || (cp >= 0xE000 && cp <= 0xFFFD) - || (cp >= 0x10000 && cp <= 0x10FFFF) - ) - ; - } - - /** - * Removes XML escapes from the string. - * - * @param string - * string to remove escapes from - * @return string with converted entities - */ - public static String unescape(String string) { - StringBuilder sb = new StringBuilder(string.length()); - for (int i = 0, length = string.length(); i < length; i++) { - char c = string.charAt(i); - if (c == '&') { - final int semic = string.indexOf(';', i); - if (semic > i) { - final String entity = string.substring(i + 1, semic); - sb.append(XMLTokener.unescapeEntity(entity)); - // skip past the entity we just parsed. - i += entity.length() + 1; - } else { - // this shouldn't happen in most cases since the parser - // errors on unclosed entries. - sb.append(c); - } - } else { - // not part of an entity - sb.append(c); - } - } - return sb.toString(); - } - - /** - * Throw an exception if the string contains whitespace. Whitespace is not - * allowed in tagNames and attributes. - * - * @param string - * A string. - * @throws JSONException Thrown if the string contains whitespace or is empty. - */ - public static void noSpace(String string) throws JSONException { - int i, length = string.length(); - if (length == 0) { - throw new JSONException("Empty string."); - } - for (i = 0; i < length; i += 1) { - if (Character.isWhitespace(string.charAt(i))) { - throw new JSONException("'" + string - + "' contains a space character."); - } - } - } - - /** - * Scan the content following the named tag, attaching it to the context. - * - * @param x - * The XMLTokener containing the source string. - * @param context - * The JSONObject that will include the new material. - * @param name - * The tag name. - * @param config - * The XML parser configuration. - * @param currentNestingDepth - * The current nesting depth. - * @return true if the close tag is processed. - * @throws JSONException Thrown if any parsing error occurs. - */ - private static boolean parse(XMLTokener x, JSONObject context, String name, XMLParserConfiguration config, int currentNestingDepth) - throws JSONException { - char c; - int i; - JSONObject jsonObject = null; - String string; - String tagName; - Object token; - XMLXsiTypeConverter xmlXsiTypeConverter; - - // Test for and skip past these forms: - // - // - // - // - // Report errors for these forms: - // <> - // <= - // << - - token = x.nextToken(); - - // "); - return false; - } - x.back(); - } else if (c == '[') { - token = x.nextToken(); - if ("CDATA".equals(token)) { - if (x.next() == '[') { - string = x.nextCDATA(); - if (string.length() > 0) { - context.accumulate(config.getcDataTagName(), string); - } - return false; - } - } - throw x.syntaxError("Expected 'CDATA['"); - } - i = 1; - do { - token = x.nextMeta(); - if (token == null) { - throw x.syntaxError("Missing '>' after ' 0); - return false; - } else if (token == QUEST) { - - // "); - return false; - } else if (token == SLASH) { - - // Close tag - if (x.nextToken() != GT) { - throw x.syntaxError("Misshaped tag"); - } - if (config.getForceList().contains(tagName)) { - // Force the value to be an array - if (nilAttributeFound) { - context.append(tagName, JSONObject.NULL); - } else if (jsonObject.length() > 0) { - context.append(tagName, jsonObject); - } else { - context.put(tagName, new JSONArray()); - } - } else { - if (nilAttributeFound) { - context.accumulate(tagName, JSONObject.NULL); - } else if (jsonObject.length() > 0) { - context.accumulate(tagName, jsonObject); - } else { - context.accumulate(tagName, ""); - } - } - return false; - - } else if (token == GT) { - // Content, between <...> and - for (;;) { - token = x.nextContent(); - if (token == null) { - if (tagName != null) { - throw x.syntaxError("Unclosed tag " + tagName); - } - return false; - } else if (token instanceof String) { - string = (String) token; - if (string.length() > 0) { - if(xmlXsiTypeConverter != null) { - jsonObject.accumulate(config.getcDataTagName(), - stringToValue(string, xmlXsiTypeConverter)); - } else { - jsonObject.accumulate(config.getcDataTagName(), - config.isKeepStrings() ? string : stringToValue(string)); - } - } - - } else if (token == LT) { - // Nested element - if (currentNestingDepth == config.getMaxNestingDepth()) { - throw x.syntaxError("Maximum nesting depth of " + config.getMaxNestingDepth() + " reached"); - } - - if (parse(x, jsonObject, tagName, config, currentNestingDepth + 1)) { - if (config.getForceList().contains(tagName)) { - // Force the value to be an array - if (jsonObject.length() == 0) { - context.put(tagName, new JSONArray()); - } else if (jsonObject.length() == 1 - && jsonObject.opt(config.getcDataTagName()) != null) { - context.append(tagName, jsonObject.opt(config.getcDataTagName())); - } else { - context.append(tagName, jsonObject); - } - } else { - if (jsonObject.length() == 0) { - context.accumulate(tagName, ""); - } else if (jsonObject.length() == 1 - && jsonObject.opt(config.getcDataTagName()) != null) { - context.accumulate(tagName, jsonObject.opt(config.getcDataTagName())); - } else { - if (!config.shouldTrimWhiteSpace()) { - removeEmpty(jsonObject, config); - } - context.accumulate(tagName, jsonObject); - } - } - - return false; - } - } - } - } else { - throw x.syntaxError("Misshaped tag"); - } - } - } - } - /** - * This method removes any JSON entry which has the key set by XMLParserConfiguration.cDataTagName - * and contains whitespace as this is caused by whitespace between tags. See test XMLTest.testNestedWithWhitespaceTrimmingDisabled. - * @param jsonObject JSONObject which may require deletion - * @param config The XMLParserConfiguration which includes the cDataTagName - */ - private static void removeEmpty(final JSONObject jsonObject, final XMLParserConfiguration config) { - if (jsonObject.has(config.getcDataTagName())) { - final Object s = jsonObject.get(config.getcDataTagName()); - if (s instanceof String) { - if (isStringAllWhiteSpace(s.toString())) { - jsonObject.remove(config.getcDataTagName()); - } - } - else if (s instanceof JSONArray) { - final JSONArray sArray = (JSONArray) s; - for (int k = sArray.length()-1; k >= 0; k--){ - final Object eachString = sArray.get(k); - if (eachString instanceof String) { - String s1 = (String) eachString; - if (isStringAllWhiteSpace(s1)) { - sArray.remove(k); - } - } - } - if (sArray.isEmpty()) { - jsonObject.remove(config.getcDataTagName()); - } - } - } - } - - private static boolean isStringAllWhiteSpace(final String s) { - for (int k = 0; k= '0' && initial <= '9') || initial == '-') { - // decimal representation - if (isDecimalNotation(val)) { - // Use a BigDecimal all the time so we keep the original - // representation. BigDecimal doesn't support -0.0, ensure we - // keep that by forcing a decimal. - try { - BigDecimal bd = new BigDecimal(val); - if(initial == '-' && BigDecimal.ZERO.compareTo(bd)==0) { - return Double.valueOf(-0.0); - } - return bd; - } catch (NumberFormatException retryAsDouble) { - // this is to support "Hex Floats" like this: 0x1.0P-1074 - try { - Double d = Double.valueOf(val); - if(d.isNaN() || d.isInfinite()) { - throw new NumberFormatException("val ["+val+"] is not a valid number."); - } - return d; - } catch (NumberFormatException ignore) { - throw new NumberFormatException("val ["+val+"] is not a valid number."); - } - } - } - // block items like 00 01 etc. Java number parsers treat these as Octal. - if(initial == '0' && val.length() > 1) { - char at1 = val.charAt(1); - if(at1 >= '0' && at1 <= '9') { - throw new NumberFormatException("val ["+val+"] is not a valid number."); - } - } else if (initial == '-' && val.length() > 2) { - char at1 = val.charAt(1); - char at2 = val.charAt(2); - if(at1 == '0' && at2 >= '0' && at2 <= '9') { - throw new NumberFormatException("val ["+val+"] is not a valid number."); - } - } - // integer representation. - // This will narrow any values to the smallest reasonable Object representation - // (Integer, Long, or BigInteger) - - // BigInteger down conversion: We use a similar bitLength compare as - // BigInteger#intValueExact uses. Increases GC, but objects hold - // only what they need. i.e. Less runtime overhead if the value is - // long lived. - BigInteger bi = new BigInteger(val); - if(bi.bitLength() <= 31){ - return Integer.valueOf(bi.intValue()); - } - if(bi.bitLength() <= 63){ - return Long.valueOf(bi.longValue()); - } - return bi; - } - throw new NumberFormatException("val ["+val+"] is not a valid number."); - } - - /** - * direct copy of {@link JSONObject#isDecimalNotation(String)} to maintain Android support. - */ - private static boolean isDecimalNotation(final String val) { - return val.indexOf('.') > -1 || val.indexOf('e') > -1 - || val.indexOf('E') > -1 || "-0".equals(val); - } - - /** - * This method tries to convert the given string value to the target object - * @param string String to convert - * @param typeConverter value converter to convert string to integer, boolean e.t.c - * @return JSON value of this string or the string - */ - public static Object stringToValue(String string, XMLXsiTypeConverter typeConverter) { - if(typeConverter != null) { - return typeConverter.convert(string); - } - return stringToValue(string); - } - - /** - * This method is the same as {@link JSONObject#stringToValue(String)}. - * - * @param string String to convert - * @return JSON value of this string or the string - */ - // To maintain compatibility with the Android API, this method is a direct copy of - // the one in JSONObject. Changes made here should be reflected there. - // This method should not make calls out of the XML object. - public static Object stringToValue(String string) { - if ("".equals(string)) { - return string; - } - - // check JSON key words true/false/null - if ("true".equalsIgnoreCase(string)) { - return Boolean.TRUE; - } - if ("false".equalsIgnoreCase(string)) { - return Boolean.FALSE; - } - if ("null".equalsIgnoreCase(string)) { - return JSONObject.NULL; - } - - /* - * If it might be a number, try converting it. If a number cannot be - * produced, then the value will just be a string. - */ - - char initial = string.charAt(0); - if ((initial >= '0' && initial <= '9') || initial == '-') { - try { - return stringToNumber(string); - } catch (Exception ignore) { - } - } - return string; - } - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * @param string - * The source string. - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(String string) throws JSONException { - return toJSONObject(string, XMLParserConfiguration.ORIGINAL); - } - - /** - * Convert a well-formed (but not necessarily valid) XML into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * @param reader The XML source reader. - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(Reader reader) throws JSONException { - return toJSONObject(reader, XMLParserConfiguration.ORIGINAL); - } - - /** - * Convert a well-formed (but not necessarily valid) XML into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * All values are converted as strings, for 1, 01, 29.0 will not be coerced to - * numbers but will instead be the exact value as seen in the XML document. - * - * @param reader The XML source reader. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(Reader reader, boolean keepStrings) throws JSONException { - if(keepStrings) { - return toJSONObject(reader, XMLParserConfiguration.KEEP_STRINGS); - } - return toJSONObject(reader, XMLParserConfiguration.ORIGINAL); - } - - /** - * Convert a well-formed (but not necessarily valid) XML into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * All values are converted as strings, for 1, 01, 29.0 will not be coerced to - * numbers but will instead be the exact value as seen in the XML document. - * - * @param reader The XML source reader. - * @param config Configuration options for the parser - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(Reader reader, XMLParserConfiguration config) throws JSONException { - JSONObject jo = new JSONObject(); - XMLTokener x = new XMLTokener(reader, config); - while (x.more()) { - x.skipPast("<"); - if(x.more()) { - parse(x, jo, null, config, 0); - } - } - return jo; - } - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * All values are converted as strings, for 1, 01, 29.0 will not be coerced to - * numbers but will instead be the exact value as seen in the XML document. - * - * @param string - * The source string. - * @param keepStrings If true, then values will not be coerced into boolean - * or numeric values and will instead be left as strings - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(String string, boolean keepStrings) throws JSONException { - return toJSONObject(new StringReader(string), keepStrings); - } - - /** - * Convert a well-formed (but not necessarily valid) XML string into a - * JSONObject. Some information may be lost in this transformation because - * JSON is a data format and XML is a document format. XML uses elements, - * attributes, and content text, while JSON uses unordered collections of - * name/value pairs and arrays of values. JSON does not does not like to - * distinguish between elements and attributes. Sequences of similar - * elements are represented as JSONArrays. Content text may be placed in a - * "content" member. Comments, prologs, DTDs, and
{@code
-     * <[ [ ]]>}
- * are ignored. - * - * All values are converted as strings, for 1, 01, 29.0 will not be coerced to - * numbers but will instead be the exact value as seen in the XML document. - * - * @param string - * The source string. - * @param config Configuration options for the parser. - * @return A JSONObject containing the structured data from the XML string. - * @throws JSONException Thrown if there is an errors while parsing the string - */ - public static JSONObject toJSONObject(String string, XMLParserConfiguration config) throws JSONException { - return toJSONObject(new StringReader(string), config); - } - - /** - * Convert a JSONObject into a well-formed, element-normal XML string. - * - * @param object - * A JSONObject. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(Object object) throws JSONException { - return toString(object, null, XMLParserConfiguration.ORIGINAL); - } - - /** - * Convert a JSONObject into a well-formed, element-normal XML string. - * - * @param object - * A JSONObject. - * @param tagName - * The optional name of the enclosing tag. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(final Object object, final String tagName) { - return toString(object, tagName, XMLParserConfiguration.ORIGINAL); - } - - /** - * Convert a JSONObject into a well-formed, element-normal XML string. - * - * @param object - * A JSONObject. - * @param tagName - * The optional name of the enclosing tag. - * @param config - * Configuration that can control output to XML. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(final Object object, final String tagName, final XMLParserConfiguration config) - throws JSONException { - return toString(object, tagName, config, 0, 0); - } - - /** - * Convert a JSONObject into a well-formed, element-normal XML string, - * either pretty print or single-lined depending on indent factor. - * - * @param object - * A JSONObject. - * @param tagName - * The optional name of the enclosing tag. - * @param config - * Configuration that can control output to XML. - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @param indent - * The current ident level in spaces. - * @return - * @throws JSONException - */ - private static String toString(final Object object, final String tagName, final XMLParserConfiguration config, int indentFactor, int indent) - throws JSONException { - StringBuilder sb = new StringBuilder(); - JSONArray ja; - JSONObject jo; - String string; - - if (object instanceof JSONObject) { - - // Emit - if (tagName != null) { - sb.append(indent(indent)); - sb.append('<'); - sb.append(tagName); - sb.append('>'); - if(indentFactor > 0){ - sb.append("\n"); - indent += indentFactor; - } - } - - // Loop thru the keys. - // don't use the new entrySet accessor to maintain Android Support - jo = (JSONObject) object; - for (final String key : jo.keySet()) { - Object value = jo.opt(key); - if (value == null) { - value = ""; - } else if (value.getClass().isArray()) { - value = new JSONArray(value); - } - - // Emit content in body - if (key.equals(config.getcDataTagName())) { - if (value instanceof JSONArray) { - ja = (JSONArray) value; - int jaLength = ja.length(); - // don't use the new iterator API to maintain support for Android - for (int i = 0; i < jaLength; i++) { - if (i > 0) { - sb.append('\n'); - } - Object val = ja.opt(i); - sb.append(escape(val.toString())); - } - } else { - sb.append(escape(value.toString())); - } - - // Emit an array of similar keys - - } else if (value instanceof JSONArray) { - ja = (JSONArray) value; - int jaLength = ja.length(); - // don't use the new iterator API to maintain support for Android - for (int i = 0; i < jaLength; i++) { - Object val = ja.opt(i); - if (val instanceof JSONArray) { - sb.append('<'); - sb.append(key); - sb.append('>'); - sb.append(toString(val, null, config, indentFactor, indent)); - sb.append("'); - } else { - sb.append(toString(val, key, config, indentFactor, indent)); - } - } - } else if ("".equals(value)) { - if (config.isCloseEmptyTag()){ - sb.append(indent(indent)); - sb.append('<'); - sb.append(key); - sb.append(">"); - sb.append(""); - if (indentFactor > 0) { - sb.append("\n"); - } - }else { - sb.append(indent(indent)); - sb.append('<'); - sb.append(key); - sb.append("/>"); - if (indentFactor > 0) { - sb.append("\n"); - } - } - - // Emit a new tag - - } else { - sb.append(toString(value, key, config, indentFactor, indent)); - } - } - if (tagName != null) { - - // Emit the close tag - sb.append(indent(indent - indentFactor)); - sb.append("'); - if(indentFactor > 0){ - sb.append("\n"); - } - } - return sb.toString(); - - } - - if (object != null && (object instanceof JSONArray || object.getClass().isArray())) { - if(object.getClass().isArray()) { - ja = new JSONArray(object); - } else { - ja = (JSONArray) object; - } - int jaLength = ja.length(); - // don't use the new iterator API to maintain support for Android - for (int i = 0; i < jaLength; i++) { - Object val = ja.opt(i); - // XML does not have good support for arrays. If an array - // appears in a place where XML is lacking, synthesize an - // element. - sb.append(toString(val, tagName == null ? "array" : tagName, config, indentFactor, indent)); - } - return sb.toString(); - } - - - string = (object == null) ? "null" : escape(object.toString()); - String indentationSuffix = (indentFactor > 0) ? "\n" : ""; - if(tagName == null){ - return indent(indent) + "\"" + string + "\"" + indentationSuffix; - } else if(string.length() == 0){ - return indent(indent) + "<" + tagName + "/>" + indentationSuffix; - } else { - return indent(indent) + "<" + tagName - + ">" + string + "" + indentationSuffix; - } - } - - /** - * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. - * - * @param object - * A JSONObject. - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(Object object, int indentFactor){ - return toString(object, null, XMLParserConfiguration.ORIGINAL, indentFactor); - } - - /** - * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. - * - * @param object - * A JSONObject. - * @param tagName - * The optional name of the enclosing tag. - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(final Object object, final String tagName, int indentFactor) { - return toString(object, tagName, XMLParserConfiguration.ORIGINAL, indentFactor); - } - - /** - * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. - * - * @param object - * A JSONObject. - * @param tagName - * The optional name of the enclosing tag. - * @param config - * Configuration that can control output to XML. - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return A string. - * @throws JSONException Thrown if there is an error parsing the string - */ - public static String toString(final Object object, final String tagName, final XMLParserConfiguration config, int indentFactor) - throws JSONException { - return toString(object, tagName, config, indentFactor, 0); - } - - /** - * Return a String consisting of a number of space characters specified by indent - * - * @param indent - * The number of spaces to be appended to the String. - * @return - */ - private static final String indent(int indent) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < indent; i++) { - sb.append(' '); - } - return sb.toString(); - } -} diff --git a/src/main/java/org/json/XMLParserConfiguration.java b/src/main/java/org/json/XMLParserConfiguration.java deleted file mode 100644 index bc4a80074..000000000 --- a/src/main/java/org/json/XMLParserConfiguration.java +++ /dev/null @@ -1,372 +0,0 @@ -package org.json; -/* -Public Domain. -*/ - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - - -/** - * Configuration object for the XML parser. The configuration is immutable. - * @author AylwardJ - */ -@SuppressWarnings({""}) -public class XMLParserConfiguration extends ParserConfiguration { - - /** - * The default maximum nesting depth when parsing a XML document to JSON. - */ -// public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512; // We could override - - /** Original Configuration of the XML Parser. */ - public static final XMLParserConfiguration ORIGINAL - = new XMLParserConfiguration(); - /** Original configuration of the XML Parser except that values are kept as strings. */ - public static final XMLParserConfiguration KEEP_STRINGS - = new XMLParserConfiguration().withKeepStrings(true); - - /** - * The name of the key in a JSON Object that indicates a CDATA section. Historically this has - * been the value "content" but can be changed. Use null to indicate no CDATA - * processing. - */ - private String cDataTagName; - - /** - * When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" - * should be kept as attribute(false), or they should be converted to - * null(true) - */ - private boolean convertNilAttributeToNull; - - /** - * When creating an XML from JSON Object, an empty tag by default will self-close. - * If it has to be closed explicitly, with empty content between start and end tag, - * this flag is to be turned on. - */ - private boolean closeEmptyTag; - - /** - * This will allow type conversion for values in XML if xsi:type attribute is defined - */ - private Map> xsiTypeMap; - - /** - * When parsing the XML into JSON, specifies the tags whose values should be converted - * to arrays - */ - private Set forceList; - - - /** - * Flag to indicate whether white space should be trimmed when parsing XML. - * The default behaviour is to trim white space. When this is set to false, inputting XML - * with tags that are the same as the value of cDataTagName is unsupported. It is recommended to set cDataTagName - * to a distinct value in this case. - */ - private boolean shouldTrimWhiteSpace; - - /** - * Default parser configuration. Does not keep strings (tries to implicitly convert - * values), and the CDATA Tag Name is "content". Trims whitespace. - */ - public XMLParserConfiguration () { - super(); - this.cDataTagName = "content"; - this.convertNilAttributeToNull = false; - this.xsiTypeMap = Collections.emptyMap(); - this.forceList = Collections.emptySet(); - this.shouldTrimWhiteSpace = true; - } - - /** - * Configure the parser string processing and use the default CDATA Tag Name as "content". - * @param keepStrings true to parse all values as string. - * false to try and convert XML string values into a JSON value. - * @deprecated This constructor has been deprecated in favor of using the new builder - * pattern for the configuration. - * This constructor may be removed in a future release. - */ - @Deprecated - public XMLParserConfiguration (final boolean keepStrings) { - this(keepStrings, "content", false); - } - - /** - * Configure the parser string processing to try and convert XML values to JSON values and - * use the passed CDATA Tag Name the processing value. Pass null to - * disable CDATA processing - * @param cDataTagName null to disable CDATA processing. Any other value - * to use that value as the JSONObject key name to process as CDATA. - * @deprecated This constructor has been deprecated in favor of using the new builder - * pattern for the configuration. - * This constructor may be removed in a future release. - */ - @Deprecated - public XMLParserConfiguration (final String cDataTagName) { - this(false, cDataTagName, false); - } - - /** - * Configure the parser to use custom settings. - * @param keepStrings true to parse all values as string. - * false to try and convert XML string values into a JSON value. - * @param cDataTagName null to disable CDATA processing. Any other value - * to use that value as the JSONObject key name to process as CDATA. - * @deprecated This constructor has been deprecated in favor of using the new builder - * pattern for the configuration. - * This constructor may be removed in a future release. - */ - @Deprecated - public XMLParserConfiguration (final boolean keepStrings, final String cDataTagName) { - super(keepStrings, DEFAULT_MAXIMUM_NESTING_DEPTH); - this.cDataTagName = cDataTagName; - this.convertNilAttributeToNull = false; - } - - /** - * Configure the parser to use custom settings. - * @param keepStrings true to parse all values as string. - * false to try and convert XML string values into a JSON value. - * @param cDataTagName null to disable CDATA processing. Any other value - * to use that value as the JSONObject key name to process as CDATA. - * @param convertNilAttributeToNull true to parse values with attribute xsi:nil="true" as null. - * false to parse values with attribute xsi:nil="true" as {"xsi:nil":true}. - * @deprecated This constructor has been deprecated in favor of using the new builder - * pattern for the configuration. - * This constructor may be removed or marked private in a future release. - */ - @Deprecated - public XMLParserConfiguration (final boolean keepStrings, final String cDataTagName, final boolean convertNilAttributeToNull) { - super(keepStrings, DEFAULT_MAXIMUM_NESTING_DEPTH); - this.cDataTagName = cDataTagName; - this.convertNilAttributeToNull = convertNilAttributeToNull; - } - - /** - * Configure the parser to use custom settings. - * @param keepStrings true to parse all values as string. - * false to try and convert XML string values into a JSON value. - * @param cDataTagName null to disable CDATA processing. Any other value - * to use that value as the JSONObject key name to process as CDATA. - * @param convertNilAttributeToNull true to parse values with attribute xsi:nil="true" as null. - * false to parse values with attribute xsi:nil="true" as {"xsi:nil":true}. - * @param xsiTypeMap new HashMap>() to parse values with attribute - * xsi:type="integer" as integer, xsi:type="string" as string - * @param forceList new HashSet() to parse the provided tags' values as arrays - * @param maxNestingDepth int to limit the nesting depth - * @param closeEmptyTag boolean to turn on explicit end tag for tag with empty value - */ - private XMLParserConfiguration (final boolean keepStrings, final String cDataTagName, - final boolean convertNilAttributeToNull, final Map> xsiTypeMap, final Set forceList, - final int maxNestingDepth, final boolean closeEmptyTag) { - super(keepStrings, maxNestingDepth); - this.cDataTagName = cDataTagName; - this.convertNilAttributeToNull = convertNilAttributeToNull; - this.xsiTypeMap = Collections.unmodifiableMap(xsiTypeMap); - this.forceList = Collections.unmodifiableSet(forceList); - this.closeEmptyTag = closeEmptyTag; - } - - /** - * Provides a new instance of the same configuration. - */ - @Override - protected XMLParserConfiguration clone() { - // future modifications to this method should always ensure a "deep" - // clone in the case of collections. i.e. if a Map is added as a configuration - // item, a new map instance should be created and if possible each value in the - // map should be cloned as well. If the values of the map are known to also - // be immutable, then a shallow clone of the map is acceptable. - final XMLParserConfiguration config = new XMLParserConfiguration( - this.keepStrings, - this.cDataTagName, - this.convertNilAttributeToNull, - this.xsiTypeMap, - this.forceList, - this.maxNestingDepth, - this.closeEmptyTag - ); - config.shouldTrimWhiteSpace = this.shouldTrimWhiteSpace; - return config; - } - - /** - * When parsing the XML into JSON, specifies if values should be kept as strings (true), or if - * they should try to be guessed into JSON values (numeric, boolean, string) - * - * @param newVal - * new value to use for the keepStrings configuration option. - * - * @return The existing configuration will not be modified. A new configuration is returned. - */ - @SuppressWarnings("unchecked") - @Override - public XMLParserConfiguration withKeepStrings(final boolean newVal) { - return super.withKeepStrings(newVal); - } - - /** - * The name of the key in a JSON Object that indicates a CDATA section. Historically this has - * been the value "content" but can be changed. Use null to indicate no CDATA - * processing. - * - * @return The cDataTagName configuration value. - */ - public String getcDataTagName() { - return this.cDataTagName; - } - - /** - * The name of the key in a JSON Object that indicates a CDATA section. Historically this has - * been the value "content" but can be changed. Use null to indicate no CDATA - * processing. - * - * @param newVal - * new value to use for the cDataTagName configuration option. - * - * @return The existing configuration will not be modified. A new configuration is returned. - */ - public XMLParserConfiguration withcDataTagName(final String newVal) { - XMLParserConfiguration newConfig = this.clone(); - newConfig.cDataTagName = newVal; - return newConfig; - } - - /** - * When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" - * should be kept as attribute(false), or they should be converted to - * null(true) - * - * @return The convertNilAttributeToNull configuration value. - */ - public boolean isConvertNilAttributeToNull() { - return this.convertNilAttributeToNull; - } - - /** - * When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" - * should be kept as attribute(false), or they should be converted to - * null(true) - * - * @param newVal - * new value to use for the convertNilAttributeToNull configuration option. - * - * @return The existing configuration will not be modified. A new configuration is returned. - */ - public XMLParserConfiguration withConvertNilAttributeToNull(final boolean newVal) { - XMLParserConfiguration newConfig = this.clone(); - newConfig.convertNilAttributeToNull = newVal; - return newConfig; - } - - /** - * When parsing the XML into JSON, specifies that the values with attribute xsi:type - * will be converted to target type defined to client in this configuration - * {@code Map>} to parse values with attribute - * xsi:type="integer" as integer, xsi:type="string" as string - * @return xsiTypeMap unmodifiable configuration map. - */ - public Map> getXsiTypeMap() { - return this.xsiTypeMap; - } - - /** - * When parsing the XML into JSON, specifies that the values with attribute xsi:type - * will be converted to target type defined to client in this configuration - * {@code Map>} to parse values with attribute - * xsi:type="integer" as integer, xsi:type="string" as string - * @param xsiTypeMap {@code new HashMap>()} to parse values with attribute - * xsi:type="integer" as integer, xsi:type="string" as string - * @return The existing configuration will not be modified. A new configuration is returned. - */ - public XMLParserConfiguration withXsiTypeMap(final Map> xsiTypeMap) { - XMLParserConfiguration newConfig = this.clone(); - Map> cloneXsiTypeMap = new HashMap>(xsiTypeMap); - newConfig.xsiTypeMap = Collections.unmodifiableMap(cloneXsiTypeMap); - return newConfig; - } - - /** - * When parsing the XML into JSON, specifies that tags that will be converted to arrays - * in this configuration {@code Set} to parse the provided tags' values as arrays - * @return forceList unmodifiable configuration set. - */ - public Set getForceList() { - return this.forceList; - } - - /** - * When parsing the XML into JSON, specifies that tags that will be converted to arrays - * in this configuration {@code Set} to parse the provided tags' values as arrays - * @param forceList {@code new HashSet()} to parse the provided tags' values as arrays - * @return The existing configuration will not be modified. A new configuration is returned. - */ - public XMLParserConfiguration withForceList(final Set forceList) { - XMLParserConfiguration newConfig = this.clone(); - Set cloneForceList = new HashSet(forceList); - newConfig.forceList = Collections.unmodifiableSet(cloneForceList); - return newConfig; - } - - /** - * Defines the maximum nesting depth that the parser will descend before throwing an exception - * when parsing the XML into JSON. The default max nesting depth is 512, which means the parser - * will throw a JsonException if the maximum depth is reached. - * Using any negative value as a parameter is equivalent to setting no limit to the nesting depth, - * which means the parses will go as deep as the maximum call stack size allows. - * @param maxNestingDepth the maximum nesting depth allowed to the XML parser - * @return The existing configuration will not be modified. A new configuration is returned. - */ - @SuppressWarnings("unchecked") - @Override - public XMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) { - return super.withMaxNestingDepth(maxNestingDepth); - } - - /** - * To enable explicit end tag with empty value. - * @param closeEmptyTag new value for the closeEmptyTag property - * @return same instance of configuration with empty tag config updated - */ - public XMLParserConfiguration withCloseEmptyTag(boolean closeEmptyTag){ - XMLParserConfiguration clonedConfiguration = this.clone(); - clonedConfiguration.closeEmptyTag = closeEmptyTag; - return clonedConfiguration; - } - - /** - * Sets whether whitespace should be trimmed inside of tags. *NOTE* Do not use this if - * you expect your XML tags to have names that are the same as cDataTagName as this is unsupported. - * cDataTagName should be set to a distinct value in these cases. - * @param shouldTrimWhiteSpace boolean to set trimming on or off. Off is default. - * @return same instance of configuration with empty tag config updated - */ - public XMLParserConfiguration withShouldTrimWhitespace(boolean shouldTrimWhiteSpace){ - XMLParserConfiguration clonedConfiguration = this.clone(); - clonedConfiguration.shouldTrimWhiteSpace = shouldTrimWhiteSpace; - return clonedConfiguration; - } - - /** - * Checks if the parser should automatically close empty XML tags. - * - * @return {@code true} if empty XML tags should be automatically closed, {@code false} otherwise. - */ - public boolean isCloseEmptyTag() { - return this.closeEmptyTag; - } - - /** - * Checks if the parser should trim white spaces from XML content. - * - * @return {@code true} if white spaces should be trimmed, {@code false} otherwise. - */ - public boolean shouldTrimWhiteSpace() { - return this.shouldTrimWhiteSpace; - } -} diff --git a/src/main/java/org/json/XMLTokener.java b/src/main/java/org/json/XMLTokener.java deleted file mode 100644 index bc18b31c9..000000000 --- a/src/main/java/org/json/XMLTokener.java +++ /dev/null @@ -1,410 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -import java.io.Reader; - -/** - * The XMLTokener extends the JSONTokener to provide additional methods - * for the parsing of XML texts. - * @author JSON.org - * @version 2015-12-09 - */ -public class XMLTokener extends JSONTokener { - - - /** The table of entity values. It initially contains Character values for - * amp, apos, gt, lt, quot. - */ - public static final java.util.HashMap entity; - - private XMLParserConfiguration configuration = XMLParserConfiguration.ORIGINAL; - - static { - entity = new java.util.HashMap(8); - entity.put("amp", XML.AMP); - entity.put("apos", XML.APOS); - entity.put("gt", XML.GT); - entity.put("lt", XML.LT); - entity.put("quot", XML.QUOT); - } - - /** - * Construct an XMLTokener from a Reader. - * @param r A source reader. - */ - public XMLTokener(Reader r) { - super(r); - } - - /** - * Construct an XMLTokener from a string. - * @param s A source string. - */ - public XMLTokener(String s) { - super(s); - } - - /** - * Construct an XMLTokener from a Reader and an XMLParserConfiguration. - * @param r A source reader. - * @param configuration the configuration that can be used to set certain flags - */ - public XMLTokener(Reader r, XMLParserConfiguration configuration) { - super(r); - this.configuration = configuration; - } - - /** - * Get the text in the CDATA block. - * @return The string up to the ]]>. - * @throws JSONException If the ]]> is not found. - */ - public String nextCDATA() throws JSONException { - char c; - int i; - StringBuilder sb = new StringBuilder(); - while (more()) { - c = next(); - sb.append(c); - i = sb.length() - 3; - if (i >= 0 && sb.charAt(i) == ']' && - sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { - sb.setLength(i); - return sb.toString(); - } - } - throw syntaxError("Unclosed CDATA"); - } - - - /** - * Get the next XML outer token, trimming whitespace. There are two kinds - * of tokens: the
{@code '<' }
character which begins a markup - * tag, and the content - * text between markup tags. - * - * @return A string, or a
{@code '<' }
Character, or null if - * there is no more source text. - * @throws JSONException if a called function has an error - */ - public Object nextContent() throws JSONException { - char c; - StringBuilder sb; - do { - c = next(); - } while (Character.isWhitespace(c) && configuration.shouldTrimWhiteSpace()); - if (c == 0) { - return null; - } - if (c == '<') { - return XML.LT; - } - sb = new StringBuilder(); - for (;;) { - if (c == 0) { - return sb.toString().trim(); - } - if (c == '<') { - back(); - if (configuration.shouldTrimWhiteSpace()) { - return sb.toString().trim(); - } else return sb.toString(); - } - if (c == '&') { - sb.append(nextEntity(c)); - } else { - sb.append(c); - } - c = next(); - } - } - - - /** - *
{@code
-     * Return the next entity. These entities are translated to Characters:
-     *     &  '  >  <  ".
-     * }
- * @param ampersand An ampersand character. - * @return A Character or an entity String if the entity is not recognized. - * @throws JSONException If missing ';' in XML entity. - */ - public Object nextEntity(@SuppressWarnings("unused") char ampersand) throws JSONException { - StringBuilder sb = new StringBuilder(); - for (;;) { - char c = next(); - if (Character.isLetterOrDigit(c) || c == '#') { - sb.append(Character.toLowerCase(c)); - } else if (c == ';') { - break; - } else { - throw syntaxError("Missing ';' in XML entity: &" + sb); - } - } - String string = sb.toString(); - return unescapeEntity(string); - } - - /** - * Unescape an XML entity encoding; - * @param e entity (only the actual entity value, not the preceding & or ending ; - * @return - */ - static String unescapeEntity(String e) { - // validate - if (e == null || e.isEmpty()) { - return ""; - } - // if our entity is an encoded unicode point, parse it. - if (e.charAt(0) == '#') { - int cp; - if (e.charAt(1) == 'x' || e.charAt(1) == 'X') { - // hex encoded unicode - cp = Integer.parseInt(e.substring(2), 16); - } else { - // decimal encoded unicode - cp = Integer.parseInt(e.substring(1)); - } - return new String(new int[] {cp},0,1); - } - Character knownEntity = entity.get(e); - if(knownEntity==null) { - // we don't know the entity so keep it encoded - return '&' + e + ';'; - } - return knownEntity.toString(); - } - - - /** - *
{@code 
-     * Returns the next XML meta token. This is used for skipping over 
-     * and  structures.
-     *  }
- * @return
{@code Syntax characters (< > / = ! ?) are returned as
-     *  Character, and strings and names are returned as Boolean. We don't care
-     *  what the values actually are.
-     *  }
- * @throws JSONException If a string is not properly closed or if the XML - * is badly structured. - */ - public Object nextMeta() throws JSONException { - char c; - char q; - do { - c = next(); - } while (Character.isWhitespace(c)); - switch (c) { - case 0: - throw syntaxError("Misshaped meta tag"); - case '<': - return XML.LT; - case '>': - return XML.GT; - case '/': - return XML.SLASH; - case '=': - return XML.EQ; - case '!': - return XML.BANG; - case '?': - return XML.QUEST; - case '"': - case '\'': - q = c; - for (;;) { - c = next(); - if (c == 0) { - throw syntaxError("Unterminated string"); - } - if (c == q) { - return Boolean.TRUE; - } - } - default: - for (;;) { - c = next(); - if (Character.isWhitespace(c)) { - return Boolean.TRUE; - } - switch (c) { - case 0: - throw syntaxError("Unterminated string"); - case '<': - case '>': - case '/': - case '=': - case '!': - case '?': - case '"': - case '\'': - back(); - return Boolean.TRUE; - } - } - } - } - - - /** - *
{@code
-     * Get the next XML Token. These tokens are found inside of angle
-     * brackets. It may be one of these characters: / > = ! ? or it
-     * may be a string wrapped in single quotes or double quotes, or it may be a
-     * name.
-     * }
- * @return a String or a Character. - * @throws JSONException If the XML is not well formed. - */ - public Object nextToken() throws JSONException { - char c; - char q; - StringBuilder sb; - do { - c = next(); - } while (Character.isWhitespace(c)); - switch (c) { - case 0: - throw syntaxError("Misshaped element"); - case '<': - throw syntaxError("Misplaced '<'"); - case '>': - return XML.GT; - case '/': - return XML.SLASH; - case '=': - return XML.EQ; - case '!': - return XML.BANG; - case '?': - return XML.QUEST; - -// Quoted string - - case '"': - case '\'': - q = c; - sb = new StringBuilder(); - for (;;) { - c = next(); - if (c == 0) { - throw syntaxError("Unterminated string"); - } - if (c == q) { - return sb.toString(); - } - if (c == '&') { - sb.append(nextEntity(c)); - } else { - sb.append(c); - } - } - default: - -// Name - - sb = new StringBuilder(); - for (;;) { - sb.append(c); - c = next(); - if (Character.isWhitespace(c)) { - return sb.toString(); - } - switch (c) { - case 0: - return sb.toString(); - case '>': - case '/': - case '=': - case '!': - case '?': - case '[': - case ']': - back(); - return sb.toString(); - case '<': - case '"': - case '\'': - throw syntaxError("Bad character in a name"); - } - } - } - } - - - /** - * Skip characters until past the requested string. - * If it is not found, we are left at the end of the source with a result of false. - * @param to A string to skip past. - */ - // The Android implementation of JSONTokener has a public method of public void skipPast(String to) - // even though ours does not have that method, to have API compatibility, our method in the subclass - // should match. - public void skipPast(String to) { - boolean b; - char c; - int i; - int j; - int offset = 0; - int length = to.length(); - char[] circle = new char[length]; - - /* - * First fill the circle buffer with as many characters as are in the - * to string. If we reach an early end, bail. - */ - - for (i = 0; i < length; i += 1) { - c = next(); - if (c == 0) { - return; - } - circle[i] = c; - } - - /* We will loop, possibly for all of the remaining characters. */ - - for (;;) { - j = offset; - b = true; - - /* Compare the circle buffer with the to string. */ - - for (i = 0; i < length; i += 1) { - if (circle[j] != to.charAt(i)) { - b = false; - break; - } - j += 1; - if (j >= length) { - j -= length; - } - } - - /* If we exit the loop with b intact, then victory is ours. */ - - if (b) { - return; - } - - /* Get the next character. If there isn't one, then defeat is ours. */ - - c = next(); - if (c == 0) { - return; - } - /* - * Shove the character in the circle buffer and advance the - * circle offset. The offset is mod n. - */ - circle[offset] = c; - offset += 1; - if (offset >= length) { - offset -= length; - } - } - } -} diff --git a/src/main/java/org/json/XMLXsiTypeConverter.java b/src/main/java/org/json/XMLXsiTypeConverter.java deleted file mode 100644 index ea6739d34..000000000 --- a/src/main/java/org/json/XMLXsiTypeConverter.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.json; -/* -Public Domain. -*/ - -/** - * Type conversion configuration interface to be used with xsi:type attributes. - *
- * XML Sample
- * {@code
- *      
- *          12345
- *          54321
- *      
- * }
- * JSON Output
- * {@code
- *     {
- *         "root" : {
- *             "asString" : "12345",
- *             "asInt": 54321
- *         }
- *     }
- * }
- *
- * Usage
- * {@code
- *      Map> xsiTypeMap = new HashMap>();
- *      xsiTypeMap.put("string", new XMLXsiTypeConverter() {
- *          @Override public String convert(final String value) {
- *              return value;
- *          }
- *      });
- *      xsiTypeMap.put("integer", new XMLXsiTypeConverter() {
- *          @Override public Integer convert(final String value) {
- *              return Integer.valueOf(value);
- *          }
- *      });
- * }
- * 
- * @author kumar529 - * @param return type of convert method - */ -public interface XMLXsiTypeConverter { - - /** - * Converts an XML xsi:type attribute value to the specified type {@code T}. - * - * @param value The string representation of the XML xsi:type attribute value to be converted. - * @return An object of type {@code T} representing the converted value. - */ - T convert(String value); -} From e424242a824b32ddb56bda6ea25e83c86255c5e8 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:31:32 +0800 Subject: [PATCH 3/8] fix errors in JSONWriter.java --- src/main/java/org/json/JSONWriter.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/json/JSONWriter.java b/src/main/java/org/json/JSONWriter.java index 11f4a5c7e..804c4de00 100644 --- a/src/main/java/org/json/JSONWriter.java +++ b/src/main/java/org/json/JSONWriter.java @@ -59,7 +59,7 @@ public class JSONWriter { /** * The object/array stack. */ - private final JSONObject stack[]; + private final JSONObject[] stack; /** * The stack top index. A value of 0 indicates that the stack is empty. @@ -302,7 +302,7 @@ private void push(JSONObject jo) throws JSONException { * If the value is or contains an invalid number. */ public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { + if (value == null) { return "null"; } if (value instanceof JSONString) { @@ -315,7 +315,7 @@ public static String valueToString(Object value) throws JSONException { if (object != null) { return object; } - throw new JSONException("Bad value from toJSONString: " + object); + throw new JSONException("error value"); } if (value instanceof Number) { // not all Numbers may match actual JSON Numbers. i.e. Fractions or Complex @@ -332,12 +332,10 @@ public static String valueToString(Object value) throws JSONException { || value instanceof JSONArray) { return value.toString(); } - if (value instanceof Map) { - Map map = (Map) value; + if (value instanceof Map map) { return new JSONObject(map).toString(); } - if (value instanceof Collection) { - Collection coll = (Collection) value; + if (value instanceof Collection coll) { return new JSONArray(coll).toString(); } if (value.getClass().isArray()) { From 77c36fa6f60d8f66d6f4bf5a44c3fb58eaa48a28 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:39:40 +0800 Subject: [PATCH 4/8] =?UTF-8?q?chore:=20=E9=81=BF=E5=85=8D=E4=BA=86idea?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/json/JSONArray.java | 34 ++--- src/main/java/org/json/JSONObject.java | 133 ++++++------------ src/main/java/org/json/JSONPointer.java | 12 +- .../java/org/json/JSONPointerException.java | 3 + src/main/java/org/json/JSONString.java | 2 +- src/main/java/org/json/JSONTokener.java | 42 +----- .../java/org/json/ParserConfiguration.java | 6 +- 7 files changed, 72 insertions(+), 160 deletions(-) diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index f49f295cb..e8fee4989 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -71,7 +71,7 @@ public class JSONArray implements Iterable { * Construct an empty JSONArray. */ public JSONArray() { - this.myArrayList = new ArrayList(); + this.myArrayList = new ArrayList<>(); } /** @@ -239,9 +239,9 @@ public JSONArray(Collection collection, JSONParserConfiguration jsonParserCon throw new JSONException("JSONArray has reached recursion depth limit of " + jsonParserConfiguration.getMaxNestingDepth()); } if (collection == null) { - this.myArrayList = new ArrayList(); + this.myArrayList = new ArrayList<>(); } else { - this.myArrayList = new ArrayList(collection.size()); + this.myArrayList = new ArrayList<>(collection.size()); this.addAll(collection, true, recursionDepth, jsonParserConfiguration); } } @@ -268,11 +268,11 @@ public JSONArray(Iterable iter) { */ public JSONArray(JSONArray array) { if (array == null) { - this.myArrayList = new ArrayList(); + this.myArrayList = new ArrayList<>(); } else { // shallow copy directly the internal array lists as any wrapping // should have been done already in the original JSONArray - this.myArrayList = new ArrayList(array.myArrayList); + this.myArrayList = new ArrayList<>(array.myArrayList); } } @@ -310,7 +310,7 @@ public JSONArray(int initialCapacity) throws JSONException { throw new JSONException( "JSONArray initial capacity cannot be negative."); } - this.myArrayList = new ArrayList(initialCapacity); + this.myArrayList = new ArrayList<>(initialCapacity); } @Override @@ -745,11 +745,10 @@ public double optDouble(int index, double defaultValue) { if (val == null) { return defaultValue; } - final double doubleValue = val.doubleValue(); // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { // return defaultValue; // } - return doubleValue; + return val.doubleValue(); } /** @@ -781,11 +780,10 @@ public Double optDoubleObject(int index, Double defaultValue) { if (val == null) { return defaultValue; } - final Double doubleValue = val.doubleValue(); // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { // return defaultValue; // } - return doubleValue; + return val.doubleValue(); } /** @@ -817,11 +815,10 @@ public float optFloat(int index, float defaultValue) { if (val == null) { return defaultValue; } - final float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return floatValue; // } - return floatValue; + return val.floatValue(); } /** @@ -853,11 +850,10 @@ public Float optFloatObject(int index, Float defaultValue) { if (val == null) { return defaultValue; } - final Float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return floatValue; // } - return floatValue; + return val.floatValue(); } /** @@ -966,9 +962,7 @@ public > E optEnum(Class clazz, int index, E defaultValue) return myE; } return Enum.valueOf(clazz, val.toString()); - } catch (IllegalArgumentException e) { - return defaultValue; - } catch (NullPointerException e) { + } catch (IllegalArgumentException | NullPointerException e) { return defaultValue; } } @@ -1749,7 +1743,6 @@ public String toString() { *  (right bracket). * @throws JSONException if a called function fails */ - @SuppressWarnings("resource") public String toString(int indentFactor) throws JSONException { // each value requires a comma, so multiply the count by 2 // We don't want to oversize the initial capacity @@ -1800,7 +1793,6 @@ public Writer write(Writer writer) throws JSONException { * @return The writer. * @throws JSONException if a called function fails or unable to write */ - @SuppressWarnings("resource") public Writer write(Writer writer, int indentFactor, int indent) throws JSONException { try { @@ -1856,7 +1848,7 @@ public Writer write(Writer writer, int indentFactor, int indent) * @return a java.util.List containing the elements of this array */ public List toList() { - List results = new ArrayList(this.myArrayList.size()); + List results = new ArrayList<>(this.myArrayList.size()); for (Object element : this.myArrayList) { if (element == null || JSONObject.NULL.equals(element)) { results.add(null); @@ -1997,7 +1989,7 @@ private void addAll(Object array, boolean wrap, int recursionDepth, JSONParserCo // JSONArray this.myArrayList.addAll(((JSONArray)array).myArrayList); } else if (array instanceof Collection) { - this.addAll((Collection)array, wrap, recursionDepth); + this.addAll(array, wrap, recursionDepth); } else if (array instanceof Iterable) { this.addAll((Iterable)array, wrap); } else { diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index ef9ea6fbf..1f2c2d9d8 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -86,7 +86,7 @@ private static final class Null { * @return NULL. */ @Override - protected final Object clone() { + protected Object clone() { return this; } @@ -162,7 +162,7 @@ public JSONObject() { // implementations to rearrange their items for a faster element // retrieval based on associative access. // Therefore, an implementation mustn't rely on the order of the item. - this.map = new HashMap(); + this.map = new HashMap<>(); } /** @@ -177,9 +177,9 @@ public JSONObject() { */ public JSONObject(JSONObject jo, String ... names) { this(names.length); - for (int i = 0; i < names.length; i += 1) { + for (String name : names) { try { - this.putOnce(names[i], jo.opt(names[i])); + this.putOnce(name, jo.opt(name)); } catch (Exception ignore) { } } @@ -308,9 +308,9 @@ private JSONObject(Map m, int recursionDepth, JSONParserConfiguration json throw new JSONException("JSONObject has reached recursion depth limit of " + jsonParserConfiguration.getMaxNestingDepth()); } if (m == null) { - this.map = new HashMap(); + this.map = new HashMap<>(); } else { - this.map = new HashMap(m.size()); + this.map = new HashMap<>(m.size()); for (final Entry e : m.entrySet()) { if(e.getKey() == null) { throw new NullPointerException("Null key."); @@ -410,8 +410,7 @@ private JSONObject(Object bean, Set objectsRecord) { public JSONObject(Object object, String ... names) { this(names.length); Class c = object.getClass(); - for (int i = 0; i < names.length; i += 1) { - String name = names[i]; + for (String name : names) { try { this.putOpt(name, c.getField(name).get(object)); } catch (Exception ignore) { @@ -472,14 +471,14 @@ public JSONObject(String baseName, Locale locale) throws JSONException { Enumeration keys = bundle.getKeys(); while (keys.hasMoreElements()) { - Object key = keys.nextElement(); + String key = keys.nextElement(); if (key != null) { // Go through the path, ensuring that there is a nested JSONObject for each // segment except the last. Add the value using the last segment's name into // the deepest nested JSONObject. - String[] path = ((String) key).split("\\."); + String[] path = key.split("\\."); int last = path.length - 1; JSONObject target = this; for (int i = 0; i < last; i += 1) { @@ -491,7 +490,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException { } target = nextTarget; } - target.put(path[last], bundle.getString((String) key)); + target.put(path[last], bundle.getString(key)); } } } @@ -504,7 +503,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException { * @param initialCapacity initial capacity of the internal map. */ protected JSONObject(int initialCapacity){ - this.map = new HashMap(initialCapacity); + this.map = new HashMap<>(initialCapacity); } /** @@ -937,15 +936,15 @@ public JSONObject increment(String key) throws JSONException { if (value == null) { this.put(key, 1); } else if (value instanceof Integer) { - this.put(key, ((Integer) value).intValue() + 1); + this.put(key, (Integer) value + 1); } else if (value instanceof Long) { - this.put(key, ((Long) value).longValue() + 1L); + this.put(key, (Long) value + 1L); } else if (value instanceof BigInteger) { this.put(key, ((BigInteger)value).add(BigInteger.ONE)); } else if (value instanceof Float) { - this.put(key, ((Float) value).floatValue() + 1.0f); + this.put(key, (Float) value + 1.0f); } else if (value instanceof Double) { - this.put(key, ((Double) value).doubleValue() + 1.0d); + this.put(key, (Double) value + 1.0d); } else if (value instanceof BigDecimal) { this.put(key, ((BigDecimal)value).add(BigDecimal.ONE)); } else { @@ -1130,9 +1129,7 @@ public > E optEnum(Class clazz, String key, E defaultValue) return myE; } return Enum.valueOf(clazz, val.toString()); - } catch (IllegalArgumentException e) { - return defaultValue; - } catch (NullPointerException e) { + } catch (IllegalArgumentException | NullPointerException e) { return defaultValue; } } @@ -1166,7 +1163,7 @@ public boolean optBoolean(String key, boolean defaultValue) { return defaultValue; } if (val instanceof Boolean){ - return ((Boolean) val).booleanValue(); + return (Boolean) val; } try { // we'll use the get anyway because it does string conversion. @@ -1205,7 +1202,7 @@ public Boolean optBooleanObject(String key, Boolean defaultValue) { return defaultValue; } if (val instanceof Boolean){ - return ((Boolean) val).booleanValue(); + return (Boolean) val; } try { // we'll use the get anyway because it does string conversion. @@ -1267,7 +1264,7 @@ static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue, boolea return defaultValue; } if (exact) { - return new BigDecimal(((Number)val).doubleValue()); + return BigDecimal.valueOf(((Number) val).doubleValue()); } // use the string constructor so that we maintain "nice" values for doubles and floats // the double constructor will translate doubles to "exact" values instead of the likely @@ -1322,7 +1319,7 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) { if (!numberIsFinite((Number)val)) { return defaultValue; } - return new BigDecimal(((Number) val).doubleValue()).toBigInteger(); + return BigDecimal.valueOf(((Number) val).doubleValue()).toBigInteger(); } if (val instanceof Long || val instanceof Integer || val instanceof Short || val instanceof Byte){ @@ -1438,11 +1435,10 @@ public float optFloat(String key, float defaultValue) { if (val == null) { return defaultValue; } - final float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return defaultValue; // } - return floatValue; + return val.floatValue(); } /** @@ -1474,11 +1470,10 @@ public Float optFloatObject(String key, Float defaultValue) { if (val == null) { return defaultValue; } - final Float floatValue = val.floatValue(); // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { // return defaultValue; // } - return floatValue; + return val.floatValue(); } /** @@ -1745,7 +1740,7 @@ public String optString(String key, String defaultValue) { * If a getter returned a non-finite number. */ private void populateMap(Object bean) { - populateMap(bean, Collections.newSetFromMap(new IdentityHashMap())); + populateMap(bean, Collections.newSetFromMap(new IdentityHashMap<>())); } private void populateMap(Object bean, Set objectsRecord) { @@ -1793,9 +1788,7 @@ && isValidMethodName(method.getName())) { } } } - } catch (IllegalAccessException ignore) { - } catch (IllegalArgumentException ignore) { - } catch (InvocationTargetException ignore) { + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignore) { } } } @@ -1832,7 +1825,7 @@ private static String getKeyNameFromMethod(Method method) { // if the first letter in the key is not uppercase, then skip. // This is to maintain backwards compatibility before PR406 // (https://github.com/stleary/JSON-java/pull/406/) - if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) { + if (Character.isLowerCase(key.charAt(0))) { return null; } if (key.length() == 1) { @@ -1878,10 +1871,7 @@ private static A getAnnotation(final Method m, final Clas try { Method im = i.getMethod(m.getName(), m.getParameterTypes()); return getAnnotation(im, annotationClass); - } catch (final SecurityException ex) { - continue; - } catch (final NoSuchMethodException ex) { - continue; + } catch (final SecurityException | NoSuchMethodException ignored) { } } @@ -1893,9 +1883,7 @@ private static A getAnnotation(final Method m, final Clas return getAnnotation( c.getSuperclass().getMethod(m.getName(), m.getParameterTypes()), annotationClass); - } catch (final SecurityException ex) { - return null; - } catch (final NoSuchMethodException ex) { + } catch (final SecurityException | NoSuchMethodException ex) { return null; } } @@ -1936,10 +1924,7 @@ private static int getAnnotationDepth(final Method m, final Class objectsRecord, int recursi return NULL; } if (object instanceof JSONObject || object instanceof JSONArray - || NULL.equals(object) || object instanceof JSONString + || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean @@ -2740,15 +2719,13 @@ private static Object wrap(Object object, Set objectsRecord, int recursi return object; } - if (object instanceof Collection) { - Collection coll = (Collection) object; + if (object instanceof Collection coll) { return new JSONArray(coll, recursionDepth, jsonParserConfiguration); } if (object.getClass().isArray()) { return new JSONArray(object); } - if (object instanceof Map) { - Map map = (Map) object; + if (object instanceof Map map) { return new JSONObject(map, recursionDepth, jsonParserConfiguration); } Package objectPackage = object.getClass().getPackage(); @@ -2785,10 +2762,9 @@ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); } - @SuppressWarnings("resource") - static final Writer writeValue(Writer writer, Object value, - int indentFactor, int indent) throws JSONException, IOException { - if (value == null || value.equals(null)) { + static Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null) { writer.write("null"); } else if (value instanceof JSONString) { // JSONString must be checked first, so it can overwrite behaviour of other types below @@ -2821,11 +2797,9 @@ static final Writer writeValue(Writer writer, Object value, ((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { - Map map = (Map) value; + } else if (value instanceof Map map) { new JSONObject(map).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { - Collection coll = (Collection) value; + } else if (value instanceof Collection coll) { new JSONArray(coll).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); @@ -2835,7 +2809,7 @@ static final Writer writeValue(Writer writer, Object value, return writer; } - static final void indent(Writer writer, int indent) throws IOException { + static void indent(Writer writer, int indent) throws IOException { for (int i = 0; i < indent; i += 1) { writer.write(' '); } @@ -2868,7 +2842,6 @@ static final void indent(Writer writer, int indent) throws IOException { * @throws JSONException if a called function has an error or a write error * occurs */ - @SuppressWarnings("resource") public Writer write(Writer writer, int indentFactor, int indent) throws JSONException { try { @@ -2934,7 +2907,7 @@ public Writer write(Writer writer, int indentFactor, int indent) * @return a java.util.Map containing the entries of this object */ public Map toMap() { - Map results = new HashMap(); + Map results = new HashMap<>(); for (Entry entry : this.entrySet()) { Object value; if (entry.getValue() == null || NULL.equals(entry.getValue())) { @@ -2990,24 +2963,4 @@ private static JSONException recursivelyDefinedObjectException(String key) { "JavaBean object contains recursively defined member variable of key " + quote(key) ); } - - /** - * For a prospective number, remove the leading zeros - * @param value prospective number - * @return number without leading zeros - */ - private static String removeLeadingZerosOfNumber(String value){ - if (value.equals("-")){return value;} - boolean negativeFirstChar = (value.charAt(0) == '-'); - int counter = negativeFirstChar ? 1:0; - while (counter < value.length()){ - if (value.charAt(counter) != '0'){ - if (negativeFirstChar) {return "-".concat(value.substring(counter));} - return value.substring(counter); - } - ++counter; - } - if (negativeFirstChar) {return "-0";} - return "0"; - } } diff --git a/src/main/java/org/json/JSONPointer.java b/src/main/java/org/json/JSONPointer.java index 859e1e644..66b74f9bc 100644 --- a/src/main/java/org/json/JSONPointer.java +++ b/src/main/java/org/json/JSONPointer.java @@ -49,7 +49,7 @@ public Builder() { } // Segments for the eventual JSONPointer string - private final List refTokens = new ArrayList(); + private final List refTokens = new ArrayList<>(); /** * Creates a {@code JSONPointer} instance using the tokens previously set using the @@ -144,9 +144,9 @@ public JSONPointer(final String pointer) { } else { throw new IllegalArgumentException("a JSON pointer should start with '/' or '#/'"); } - this.refTokens = new ArrayList(); + this.refTokens = new ArrayList<>(); int slashIdx = -1; - int prevSlashIdx = 0; + int prevSlashIdx; do { prevSlashIdx = slashIdx + 1; slashIdx = refs.indexOf('/', prevSlashIdx); @@ -176,7 +176,7 @@ public JSONPointer(final String pointer) { * Each token identifies a step in the path to the targeted value. */ public JSONPointer(List refTokens) { - this.refTokens = new ArrayList(refTokens); + this.refTokens = new ArrayList<>(refTokens); } /** @@ -228,7 +228,7 @@ private static Object readByIndexToken(Object current, String indexToken) throws JSONArray currentArr = (JSONArray) current; if (index >= currentArr.length()) { throw new JSONPointerException(format("index %s is out of bounds - the array has %d elements", indexToken, - Integer.valueOf(currentArr.length()))); + currentArr.length())); } try { return currentArr.get(index); @@ -246,7 +246,7 @@ private static Object readByIndexToken(Object current, String indexToken) throws */ @Override public String toString() { - StringBuilder rval = new StringBuilder(""); + StringBuilder rval = new StringBuilder(); for (String token: this.refTokens) { rval.append('/').append(escape(token)); } diff --git a/src/main/java/org/json/JSONPointerException.java b/src/main/java/org/json/JSONPointerException.java index dc5a25ad6..e38ecb902 100644 --- a/src/main/java/org/json/JSONPointerException.java +++ b/src/main/java/org/json/JSONPointerException.java @@ -4,6 +4,8 @@ Public Domain. */ +import java.io.Serial; + /** * The JSONPointerException is thrown by {@link JSONPointer} if an error occurs * during evaluating a pointer. @@ -12,6 +14,7 @@ * @version 2016-05-13 */ public class JSONPointerException extends JSONException { + @Serial private static final long serialVersionUID = 8872944667561856751L; /** diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index cd8d1847d..ed6595926 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -19,5 +19,5 @@ public interface JSONString { * * @return A strictly syntactically correct JSON text. */ - public String toJSONString(); + String toJSONString(); } diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 63effc5f7..c577e67a4 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -1,7 +1,7 @@ package org.json; import java.io.*; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -53,7 +53,7 @@ public JSONTokener(Reader reader) { this.character = 1; this.characterPreviousLine = 0; this.line = 1; - this.smallCharMemory = new ArrayList(2); + this.smallCharMemory = new ArrayList<>(2); } @@ -62,7 +62,7 @@ public JSONTokener(Reader reader) { * @param inputStream The source. */ public JSONTokener(InputStream inputStream) { - this(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); + this(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); } @@ -484,38 +484,6 @@ public Object nextValue(JSONParserConfiguration jsonParserConfiguration) throws } } - /** - * This method is used to get a JSONObject from the JSONTokener. The strictMode parameter controls the behavior of - * the method when parsing the JSONObject. - * - * @param jsonParserConfiguration which carries options such as strictMode, these methods will - * strictly adhere to the JSON syntax, throwing a JSONException for any deviations. - * deviations. - * @return A JSONObject which is the next value in the JSONTokener. - * @throws JSONException If the JSONObject or JSONArray depth is too large to process. - */ - private JSONObject getJsonObject(JSONParserConfiguration jsonParserConfiguration) { - try { - return new JSONObject(this, jsonParserConfiguration); - } catch (StackOverflowError e) { - throw new JSONException("JSON Array or Object depth too large to process.", e); - } - } - - /** - * This method is used to get a JSONArray from the JSONTokener. - * - * @return A JSONArray which is the next value in the JSONTokener. - * @throws JSONException If the JSONArray depth is too large to process. - */ - private JSONArray getJsonArray() { - try { - return new JSONArray(this); - } catch (StackOverflowError e) { - throw new JSONException("JSON Array or Object depth too large to process.", e); - } - } - /** * Get the next simple value from the JSON input. Simple values include strings (wrapped in single or double * quotes), numbers, booleans, and null. This method is called when the next character is not '{' or '['. @@ -621,7 +589,7 @@ public char skipTo(char to) throws JSONException { * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { - return new JSONException(message + this.toString()); + return new JSONException(message + this); } /** @@ -632,7 +600,7 @@ public JSONException syntaxError(String message) { * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message, Throwable causedBy) { - return new JSONException(message + this.toString(), causedBy); + return new JSONException(message + this, causedBy); } /** diff --git a/src/main/java/org/json/ParserConfiguration.java b/src/main/java/org/json/ParserConfiguration.java index 06cc44366..90a942ee5 100644 --- a/src/main/java/org/json/ParserConfiguration.java +++ b/src/main/java/org/json/ParserConfiguration.java @@ -115,11 +115,7 @@ public int getMaxNestingDepth() { public T withMaxNestingDepth(int maxNestingDepth) { T newConfig = (T) this.clone(); - if (maxNestingDepth > UNDEFINED_MAXIMUM_NESTING_DEPTH) { - newConfig.maxNestingDepth = maxNestingDepth; - } else { - newConfig.maxNestingDepth = UNDEFINED_MAXIMUM_NESTING_DEPTH; - } + newConfig.maxNestingDepth = Math.max(maxNestingDepth, UNDEFINED_MAXIMUM_NESTING_DEPTH); return newConfig; } From a0e4dd7530477bb6575dff4f512d1638dfaf17e3 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:40:11 +0800 Subject: [PATCH 5/8] Delete JSONStringer.java --- src/main/java/org/json/JSONStringer.java | 59 ------------------------ 1 file changed, 59 deletions(-) delete mode 100644 src/main/java/org/json/JSONStringer.java diff --git a/src/main/java/org/json/JSONStringer.java b/src/main/java/org/json/JSONStringer.java deleted file mode 100644 index 2f6cf9ed8..000000000 --- a/src/main/java/org/json/JSONStringer.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.json; - -/* -Public Domain. -*/ - -import java.io.StringWriter; - -/** - * JSONStringer provides a quick and convenient way of producing JSON text. - * The texts produced strictly conform to JSON syntax rules. No whitespace is - * added, so the results are ready for transmission or storage. Each instance of - * JSONStringer can produce one JSON text. - *

- * A JSONStringer instance provides a value method for appending - * values to the - * text, and a key - * method for adding keys before values in objects. There are array - * and endArray methods that make and bound array values, and - * object and endObject methods which make and bound - * object values. All of these methods return the JSONWriter instance, - * permitting cascade style. For example,

- * myString = new JSONStringer()
- *     .object()
- *         .key("JSON")
- *         .value("Hello, World!")
- *     .endObject()
- *     .toString();
which produces the string
- * {"JSON":"Hello, World!"}
- *

- * The first method called must be array or object. - * There are no methods for adding commas or colons. JSONStringer adds them for - * you. Objects and arrays can be nested up to 200 levels deep. - *

- * This can sometimes be easier than using a JSONObject to build a string. - * @author JSON.org - * @version 2015-12-09 - */ -public class JSONStringer extends JSONWriter { - /** - * Make a fresh JSONStringer. It can be used to build one JSON text. - */ - public JSONStringer() { - super(new StringWriter()); - } - - /** - * Return the JSON text. This method is used to obtain the product of the - * JSONStringer instance. It will return null if there was a - * problem in the construction of the JSON text (such as the calls to - * array were not properly balanced with calls to - * endArray). - * @return The JSON text. - */ - @Override - public String toString() { - return this.mode == 'd' ? this.writer.toString() : null; - } -} From 5354e0e3479b83d42a27810ba3b0df539da55fbb Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:41:02 +0800 Subject: [PATCH 6/8] update --- src/main/java/org/json/JSONPointer.java | 2 -- src/main/java/org/json/StringBuilderWriter.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/json/JSONPointer.java b/src/main/java/org/json/JSONPointer.java index 66b74f9bc..6cffd9737 100644 --- a/src/main/java/org/json/JSONPointer.java +++ b/src/main/java/org/json/JSONPointer.java @@ -16,7 +16,6 @@ /** * A JSON Pointer is a simple query language defined for JSON documents by * RFC 6901. - * * In a nutshell, JSONPointer allows the user to navigate into a JSON document * using strings, and retrieve targeted objects, like a simple form of XPATH. * Path segments are separated by the '/' char, which signifies the root of @@ -62,7 +61,6 @@ public JSONPointer build() { /** * Adds an arbitrary token to the list of reference tokens. It can be any non-null value. - * * Unlike in the case of JSON string or URI fragment representation of JSON pointers, the * argument of this method MUST NOT be escaped. If you want to query the property called * {@code "a~b"} then you should simply pass the {@code "a~b"} string as-is, there is no diff --git a/src/main/java/org/json/StringBuilderWriter.java b/src/main/java/org/json/StringBuilderWriter.java index 4aaa4903f..73d473de3 100644 --- a/src/main/java/org/json/StringBuilderWriter.java +++ b/src/main/java/org/json/StringBuilderWriter.java @@ -87,6 +87,6 @@ public void flush() { } @Override - public void close() throws IOException { + public void close() { } } From f59f675a47d67b5630ea48b30080c53074eb6d0a Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:45:42 +0800 Subject: [PATCH 7/8] update --- src/main/java/org/json/JSONArray.java | 13 +------------ src/main/java/org/json/JSONObject.java | 16 ++++++---------- .../java/org/json/JSONParserConfiguration.java | 1 + src/main/java/org/json/JSONPointer.java | 3 --- src/main/java/org/json/JSONWriter.java | 2 +- src/main/java/org/json/ParserConfiguration.java | 1 + src/main/java/org/json/StringBuilderWriter.java | 1 - 7 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index e8fee4989..75fa7c787 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -745,9 +745,6 @@ public double optDouble(int index, double defaultValue) { if (val == null) { return defaultValue; } - // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { - // return defaultValue; - // } return val.doubleValue(); } @@ -780,9 +777,6 @@ public Double optDoubleObject(int index, Double defaultValue) { if (val == null) { return defaultValue; } - // if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { - // return defaultValue; - // } return val.doubleValue(); } @@ -815,9 +809,6 @@ public float optFloat(int index, float defaultValue) { if (val == null) { return defaultValue; } - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { - // return floatValue; - // } return val.floatValue(); } @@ -850,9 +841,6 @@ public Float optFloatObject(int index, Float defaultValue) { if (val == null) { return defaultValue; } - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { - // return floatValue; - // } return val.floatValue(); } @@ -1632,6 +1620,7 @@ public Object remove(int index) { * @param other The other JSONArray * @return true if they are equal */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean similar(Object other) { if (!(other instanceof JSONArray)) { return false; diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index 1f2c2d9d8..05800da06 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -85,6 +85,7 @@ private static final class Null { * * @return NULL. */ + @SuppressWarnings("MethodDoesntCallSuperMethod") @Override protected Object clone() { return this; @@ -99,7 +100,7 @@ protected Object clone() { * null. */ @Override - @SuppressWarnings("lgtm[java/unchecked-cast-in-equals]") + @SuppressWarnings({"lgtm[java/unchecked-cast-in-equals]", "EqualsWhichDoesntCheckParameterClass"}) public boolean equals(Object object) { return object == null || object == this; } @@ -140,6 +141,7 @@ public String toString() { * * @return The class object representing the type of the underlying Map. */ + @SuppressWarnings("rawtypes") public Class getMapType() { return map.getClass(); } @@ -512,7 +514,6 @@ protected JSONObject(int initialCapacity){ * is stored under the key to hold all of the accumulated values. If there * is already a JSONArray, then the new value is appended to it. In * contrast, the put method replaces the previous value. - * * If only one value is accumulated that is not a JSONArray, then the result * will be the same as using put. But if multiple values are accumulated, * then the result will be like append. @@ -995,7 +996,6 @@ public Set keySet() { * match what is returned by the JSONObject get* and opt* functions. Modifying * the returned EntrySet or the Entry objects contained therein will modify the * backing JSONObject. This does not return a clone or a read-only view. - * * Use with caution. * * @see Map#entrySet() @@ -1435,9 +1435,6 @@ public float optFloat(String key, float defaultValue) { if (val == null) { return defaultValue; } - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { - // return defaultValue; - // } return val.floatValue(); } @@ -1470,9 +1467,6 @@ public Float optFloatObject(String key, Float defaultValue) { if (val == null) { return defaultValue; } - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { - // return defaultValue; - // } return val.floatValue(); } @@ -2325,6 +2319,7 @@ public Object remove(String key) { * @param other The other JSONObject * @return true if they are equal */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean similar(Object other) { try { if (!(other instanceof JSONObject)) { @@ -2371,7 +2366,6 @@ public boolean similar(Object other) { /** * Compares two numbers to see if they are similar. - * * If either of the numbers are Double or Float instances, then they are checked to have * a finite value. If either value is not finite (NaN or ±infinity), then this * function will always return false. If both numbers are finite, they are first checked @@ -2384,6 +2378,7 @@ public boolean similar(Object other) { * @param r the right value to compare. Can not be null. * @return true if the numbers are similar, false otherwise. */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") static boolean isNumberSimilar(Number l, Number r) { if (!numberIsFinite(l) || !numberIsFinite(r)) { // non-finite numbers are never similar @@ -2409,6 +2404,7 @@ static boolean isNumberSimilar(Number l, Number r) { return lBigDecimal.compareTo(rBigDecimal) == 0; } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") private static boolean numberIsFinite(Number n) { if (n instanceof Double && (((Double) n).isInfinite() || ((Double) n).isNaN())) { return false; diff --git a/src/main/java/org/json/JSONParserConfiguration.java b/src/main/java/org/json/JSONParserConfiguration.java index ad0d7fb72..62d916599 100644 --- a/src/main/java/org/json/JSONParserConfiguration.java +++ b/src/main/java/org/json/JSONParserConfiguration.java @@ -31,6 +31,7 @@ public JSONParserConfiguration() { this.overwriteDuplicateKey = false; } + @SuppressWarnings("MethodDoesntCallSuperMethod") @Override protected JSONParserConfiguration clone() { JSONParserConfiguration clone = new JSONParserConfiguration(); diff --git a/src/main/java/org/json/JSONPointer.java b/src/main/java/org/json/JSONPointer.java index 6cffd9737..a8c4b332a 100644 --- a/src/main/java/org/json/JSONPointer.java +++ b/src/main/java/org/json/JSONPointer.java @@ -162,9 +162,6 @@ public JSONPointer(final String pointer) { } } while (slashIdx >= 0); // using split does not take into account consecutive separators or "ending nulls" - //for (String token : refs.split("/")) { - // this.refTokens.add(unescape(token)); - //} } /** diff --git a/src/main/java/org/json/JSONWriter.java b/src/main/java/org/json/JSONWriter.java index 804c4de00..f875e7fec 100644 --- a/src/main/java/org/json/JSONWriter.java +++ b/src/main/java/org/json/JSONWriter.java @@ -69,7 +69,7 @@ public class JSONWriter { /** * The writer that will receive the output. */ - protected Appendable writer; + protected final Appendable writer; /** * Make a fresh JSONWriter. It can be used to build one JSON text. diff --git a/src/main/java/org/json/ParserConfiguration.java b/src/main/java/org/json/ParserConfiguration.java index 90a942ee5..9ec3b97fe 100644 --- a/src/main/java/org/json/ParserConfiguration.java +++ b/src/main/java/org/json/ParserConfiguration.java @@ -51,6 +51,7 @@ protected ParserConfiguration(final boolean keepStrings, final int maxNestingDep /** * Provides a new instance of the same configuration. */ + @SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException", "MethodDoesntCallSuperMethod"}) @Override protected ParserConfiguration clone() { // future modifications to this method should always ensure a "deep" diff --git a/src/main/java/org/json/StringBuilderWriter.java b/src/main/java/org/json/StringBuilderWriter.java index 73d473de3..4c22f16ae 100644 --- a/src/main/java/org/json/StringBuilderWriter.java +++ b/src/main/java/org/json/StringBuilderWriter.java @@ -1,6 +1,5 @@ package org.json; -import java.io.IOException; import java.io.Writer; /** From 65ae6764f6daacb68445d38bb63779cf1c880f03 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Fri, 19 Jul 2024 23:47:08 +0800 Subject: [PATCH 8/8] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75c21aa25..9209f723c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.json json - qs-fork-3.1.1 + qs-fork-2.0.1 jar JSON in Java