From 7aee2acf0cfc814bbf9564c71642d1867ee16cd6 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:19:06 +0200 Subject: [PATCH 01/30] improve testing --- .github/workflows/json-smart-formatting.yml | 12 ++++ .github/workflows/json-smart-unit-tests.yml | 14 +++- .github/workflows/security.yml | 77 +++++++++++++++++++++ README.md | 4 +- accessors-smart/pom.xml | 14 ++-- json-smart-action/pom.xml | 10 +-- json-smart/pom.xml | 10 +-- 7 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/security.yml diff --git a/.github/workflows/json-smart-formatting.yml b/.github/workflows/json-smart-formatting.yml index facc672..d385264 100644 --- a/.github/workflows/json-smart-formatting.yml +++ b/.github/workflows/json-smart-formatting.yml @@ -4,10 +4,14 @@ on: push: branches: - master + - upgrade pull_request: branches: - master +permissions: + contents: read + jobs: formatting: runs-on: ubuntu-latest @@ -21,6 +25,14 @@ jobs: distribution: 'temurin' cache: 'maven' + - name: Cache local Maven repository + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Check formatting accessors-smart run: cd accessors-smart; ./mvnw spotless:check diff --git a/.github/workflows/json-smart-unit-tests.yml b/.github/workflows/json-smart-unit-tests.yml index de3c842..e36150b 100644 --- a/.github/workflows/json-smart-unit-tests.yml +++ b/.github/workflows/json-smart-unit-tests.yml @@ -5,16 +5,20 @@ on: branches: - master - update2024 + - upgrade pull_request: branches: - master +permissions: + contents: read + jobs: publish: runs-on: ubuntu-latest strategy: matrix: - java-version: [8, 11, 16, 17, 21] + java-version: [8, 11, 17, 21, 22, 23] steps: - uses: actions/checkout@v4 @@ -25,6 +29,14 @@ jobs: distribution: 'temurin' cache: 'maven' + - name: Cache local Maven repository + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Unit tests accessors-smart run: cd accessors-smart; ./mvnw -B install; ./mvnw -B clean test diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..e3121eb --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,77 @@ +name: Security Scanning + +on: + push: + branches: [ master, upgrade ] + pull_request: + branches: [ master ] + schedule: + - cron: '0 6 * * 1' # Weekly on Monday at 6am UTC + +permissions: + contents: read + security-events: write + actions: read + +jobs: + codeql: + name: CodeQL Analysis + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: 11 + distribution: 'temurin' + cache: 'maven' + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: Build project + run: | + cd accessors-smart && ./mvnw clean compile + cd ../json-smart && ./mvnw clean compile + cd ../json-smart-action && ./mvnw clean compile + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + + dependency-check: + name: Dependency Vulnerability Scan + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: 11 + distribution: 'temurin' + cache: 'maven' + + - name: Run OWASP Dependency Check + run: | + cd accessors-smart && ./mvnw org.owasp:dependency-check-maven:check + cd ../json-smart && ./mvnw org.owasp:dependency-check-maven:check + cd ../json-smart-action && ./mvnw org.owasp:dependency-check-maven:check + continue-on-error: true + + - name: Upload dependency check results + uses: actions/upload-artifact@v4 + if: always() + with: + name: dependency-check-reports + path: '**/target/dependency-check-report.html' \ No newline at end of file diff --git a/README.md b/README.md index 3591d97..9d9b3d4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # json-smart-v2 -[![Build Status](https://travis-ci.org/netplex/json-smart-v2.svg?branch=master)](https://travis-ci.org/netplex/json-smart-v2) +[![CI](https://github.com/netplex/json-smart-v2/actions/workflows/json-smart-unit-tests.yml/badge.svg)](https://github.com/netplex/json-smart-v2/actions/workflows/json-smart-unit-tests.yml) +[![Security](https://github.com/netplex/json-smart-v2/actions/workflows/security.yml/badge.svg)](https://github.com/netplex/json-smart-v2/actions/workflows/security.yml) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.minidev/json-smart/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/net.minidev/json-smart/) [![Coverage Status](https://coveralls.io/repos/github/netplex/json-smart-v2/badge.svg?branch=master)](https://coveralls.io/github/netplex/json-smart-v2?branch=master) +[![Java 8+](https://img.shields.io/badge/Java-8%2B-blue.svg)](https://openjdk.java.net/) Json-smart development started in 2010, when SQL servers did not support native JSON fields, NoSQL databases were slowly emerging, and all the existing JSON APIs were bogus. I wrote lots of tests to benchmark and compare JSON java parsers. diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index ef87765..b8d88af 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -92,7 +92,7 @@ limitations under the License. org.apache.maven.plugins maven-gpg-plugin - 3.2.7 + 3.2.8 sign-artifacts @@ -178,7 +178,7 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.15.1 UTF-8 ${maven.compiler.source} @@ -189,7 +189,7 @@ limitations under the License. org.apache.maven.plugins maven-resources-plugin - 3.3.1 + 3.4.0 UTF-8 @@ -198,13 +198,13 @@ limitations under the License. org.apache.maven.plugins maven-jar-plugin - 3.4.2 + 3.5.1 org.apache.maven.plugins maven-javadoc-plugin - 3.10.1 + 3.11.2 8 @@ -243,7 +243,7 @@ limitations under the License. com.diffplug.spotless spotless-maven-plugin - 2.44.2 + 2.47.0 @@ -266,7 +266,7 @@ limitations under the License. org.junit.jupiter junit-jupiter-api - 5.11.2 + 5.13.4 test diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 27e3c1e..e19947d 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -169,7 +169,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.14.0 + 3.15.1 UTF-8 ${maven.compiler.source} @@ -180,7 +180,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.3.1 + 3.4.0 UTF-8 @@ -189,7 +189,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.4.2 + 3.5.1 @@ -214,7 +214,7 @@ org.apache.felix maven-bundle-plugin - 5.1.9 + 5.1.10 true @@ -233,7 +233,7 @@ com.diffplug.spotless spotless-maven-plugin - 2.46.1 + 2.47.0 diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 3a6f0ed..2ceb7ff 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -185,7 +185,7 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - 3.14.0 + 3.15.1 UTF-8 ${maven.compiler.source} @@ -196,7 +196,7 @@ limitations under the License. org.apache.maven.plugins maven-resources-plugin - 3.3.1 + 3.4.0 UTF-8 @@ -205,7 +205,7 @@ limitations under the License. org.apache.maven.plugins maven-jar-plugin - 3.4.2 + 3.5.1 @@ -231,7 +231,7 @@ limitations under the License. org.apache.felix maven-bundle-plugin - 5.1.9 + 5.1.10 true @@ -254,7 +254,7 @@ limitations under the License. com.diffplug.spotless spotless-maven-plugin - 2.46.1 + 2.47.0 From c18ae143e82edee3326120ba90d2df2c6482c5f2 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:25:28 +0200 Subject: [PATCH 02/30] fix maven-resources-plugin version to 3.3.1 --- accessors-smart/pom.xml | 2 +- json-smart-action/pom.xml | 2 +- json-smart/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index b8d88af..eb23759 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -189,7 +189,7 @@ limitations under the License. org.apache.maven.plugins maven-resources-plugin - 3.4.0 + 3.3.1 UTF-8 diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index e19947d..8c7f473 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -180,7 +180,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.4.0 + 3.3.1 UTF-8 diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 2ceb7ff..8718f97 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -196,7 +196,7 @@ limitations under the License. org.apache.maven.plugins maven-resources-plugin - 3.4.0 + 3.3.1 UTF-8 From c5a8a7c93992d44f671b2b5f2497718c972b5053 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:33:20 +0200 Subject: [PATCH 03/30] patch on github ations --- .github/workflows/json-smart-formatting.yml | 6 +++--- .github/workflows/security.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/json-smart-formatting.yml b/.github/workflows/json-smart-formatting.yml index d385264..d4ad2a2 100644 --- a/.github/workflows/json-smart-formatting.yml +++ b/.github/workflows/json-smart-formatting.yml @@ -34,10 +34,10 @@ jobs: ${{ runner.os }}-maven- - name: Check formatting accessors-smart - run: cd accessors-smart; ./mvnw spotless:check + run: cd accessors-smart; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check - name: Check formatting json-smart - run: cd json-smart; ./mvnw spotless:check + run: cd json-smart; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check - name: Check formatting json-smart-action - run: cd json-smart-action; ./mvnw spotless:check + run: cd json-smart-action; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index e3121eb..7651472 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -64,9 +64,9 @@ jobs: - name: Run OWASP Dependency Check run: | - cd accessors-smart && ./mvnw org.owasp:dependency-check-maven:check - cd ../json-smart && ./mvnw org.owasp:dependency-check-maven:check - cd ../json-smart-action && ./mvnw org.owasp:dependency-check-maven:check + cd accessors-smart && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} + cd ../json-smart && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} + cd ../json-smart-action && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} continue-on-error: true - name: Upload dependency check results From 4cf87ea25450541fa145649f3508fb2e888853f5 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:35:37 +0200 Subject: [PATCH 04/30] patch versions --- .github/workflows/json-smart-formatting.yml | 6 +++--- accessors-smart/pom.xml | 2 +- json-smart-action/pom.xml | 2 +- json-smart/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/json-smart-formatting.yml b/.github/workflows/json-smart-formatting.yml index d4ad2a2..d385264 100644 --- a/.github/workflows/json-smart-formatting.yml +++ b/.github/workflows/json-smart-formatting.yml @@ -34,10 +34,10 @@ jobs: ${{ runner.os }}-maven- - name: Check formatting accessors-smart - run: cd accessors-smart; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check + run: cd accessors-smart; ./mvnw spotless:check - name: Check formatting json-smart - run: cd json-smart; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check + run: cd json-smart; ./mvnw spotless:check - name: Check formatting json-smart-action - run: cd json-smart-action; ./mvnw com.diffplug.spotless:spotless-maven-plugin:check + run: cd json-smart-action; ./mvnw spotless:check diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index eb23759..124a210 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -243,7 +243,7 @@ limitations under the License. com.diffplug.spotless spotless-maven-plugin - 2.47.0 + 2.46.1 diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 8c7f473..564f919 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -233,7 +233,7 @@ com.diffplug.spotless spotless-maven-plugin - 2.47.0 + 2.46.1 diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 8718f97..2d0d84a 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -254,7 +254,7 @@ limitations under the License. com.diffplug.spotless spotless-maven-plugin - 2.47.0 + 2.46.1 From 4379f313d5128fa1e0f2cbb452e93e907f662a73 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:41:29 +0200 Subject: [PATCH 05/30] fix version --- json-smart-action/pom.xml | 3 ++- json-smart/pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 564f919..35404ca 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -212,9 +212,10 @@ + org.apache.felix maven-bundle-plugin - 5.1.10 + 5.1.9 true diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 2d0d84a..3f55971 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -231,7 +231,7 @@ limitations under the License. org.apache.felix maven-bundle-plugin - 5.1.10 + 5.1.9 true From 6837e8ac4f21bc7926f47298a40ce54f841fb8e6 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:44:09 +0200 Subject: [PATCH 06/30] rollback versions --- accessors-smart/pom.xml | 2 +- json-smart-action/pom.xml | 2 +- json-smart/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index 124a210..7793036 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -198,7 +198,7 @@ limitations under the License. org.apache.maven.plugins maven-jar-plugin - 3.5.1 + 3.4.2 diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 35404ca..da9bfac 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -189,7 +189,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.5.1 + 3.4.2 diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 3f55971..dd99e21 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -205,7 +205,7 @@ limitations under the License. org.apache.maven.plugins maven-jar-plugin - 3.5.1 + 3.4.2 From 9dd4ac4cffe0451231329822e1dd98955b6b9b1a Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 10:53:50 +0200 Subject: [PATCH 07/30] downgrade --- accessors-smart/pom.xml | 2 +- json-smart-action/pom.xml | 2 +- json-smart/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index 7793036..2770188 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -178,7 +178,7 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - 3.15.1 + 3.14.0 UTF-8 ${maven.compiler.source} diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index da9bfac..13dc87a 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -169,7 +169,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.15.1 + 3.14.0 UTF-8 ${maven.compiler.source} diff --git a/json-smart/pom.xml b/json-smart/pom.xml index dd99e21..3a6f0ed 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -185,7 +185,7 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - 3.15.1 + 3.14.0 UTF-8 ${maven.compiler.source} From 20714c2d9bab855339ddff4b20de59cc0cbe83b7 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 12:33:23 +0200 Subject: [PATCH 08/30] add condition for github workflows --- .github/workflows/json-smart-formatting.yml | 10 ++++++++++ .github/workflows/json-smart-unit-tests.yml | 10 ++++++++++ .github/workflows/security.yml | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/.github/workflows/json-smart-formatting.yml b/.github/workflows/json-smart-formatting.yml index d385264..5eb5121 100644 --- a/.github/workflows/json-smart-formatting.yml +++ b/.github/workflows/json-smart-formatting.yml @@ -5,9 +5,19 @@ on: branches: - master - upgrade + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/json-smart-formatting.yml' pull_request: branches: - master + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/json-smart-formatting.yml' permissions: contents: read diff --git a/.github/workflows/json-smart-unit-tests.yml b/.github/workflows/json-smart-unit-tests.yml index e36150b..480a5ea 100644 --- a/.github/workflows/json-smart-unit-tests.yml +++ b/.github/workflows/json-smart-unit-tests.yml @@ -6,9 +6,19 @@ on: - master - update2024 - upgrade + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/json-smart-unit-tests.yml' pull_request: branches: - master + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/json-smart-unit-tests.yml' permissions: contents: read diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 7651472..8c9a8df 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -3,8 +3,18 @@ name: Security Scanning on: push: branches: [ master, upgrade ] + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/security.yml' pull_request: branches: [ master ] + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - 'json-smart-action/**' + - '.github/workflows/security.yml' schedule: - cron: '0 6 * * 1' # Weekly on Monday at 6am UTC From d028b7c94460a86e275278218f699cfe03863f6a Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 13:29:56 +0200 Subject: [PATCH 09/30] patch action --- .github/workflows/security.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 8c9a8df..9fb94db 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -48,11 +48,14 @@ jobs: with: languages: ${{ matrix.language }} - - name: Build project - run: | - cd accessors-smart && ./mvnw clean compile - cd ../json-smart && ./mvnw clean compile - cd ../json-smart-action && ./mvnw clean compile + - name: Build project accessors-smart + run: cd accessors-smart && ./mvnw -q clean compile + + - name: Build project json-smart + run: cd json-smart && ./mvnw -q clean compile + + - name: Build project json-smart-action + run: cd json-smart-action && ./mvnw -q clean compile - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From 39ab9e88bdad3449c6379aad6d0d19bb110892c0 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 13:36:14 +0200 Subject: [PATCH 10/30] test patch action --- .github/workflows/security.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 9fb94db..2a1bfbd 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -49,13 +49,13 @@ jobs: languages: ${{ matrix.language }} - name: Build project accessors-smart - run: cd accessors-smart && ./mvnw -q clean compile + run: cd accessors-smart && ./mvnw -q clean install - name: Build project json-smart - run: cd json-smart && ./mvnw -q clean compile + run: cd json-smart && ./mvnw -q clean install - name: Build project json-smart-action - run: cd json-smart-action && ./mvnw -q clean compile + run: cd json-smart-action && ./mvnw -q clean install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 @@ -77,9 +77,9 @@ jobs: - name: Run OWASP Dependency Check run: | - cd accessors-smart && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} - cd ../json-smart && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} - cd ../json-smart-action && ./mvnw org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} + cd accessors-smart && ./mvnw -q org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} + cd ../json-smart && ./mvnw -q org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} + cd ../json-smart-action && ./mvnw -q org.owasp:dependency-check-maven:check -DnvdApiKey=${{ secrets.NVD_API_KEY }} continue-on-error: true - name: Upload dependency check results From f8fbab82da35f3fedeb6d7a9e41abeaf1a7445d5 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 14:20:15 +0200 Subject: [PATCH 11/30] edd exta test in action --- .github/workflows/security.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 2a1bfbd..d02e3d7 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -49,13 +49,13 @@ jobs: languages: ${{ matrix.language }} - name: Build project accessors-smart - run: cd accessors-smart && ./mvnw -q clean install + run: cd accessors-smart && ./mvnw -q clean install test - name: Build project json-smart - run: cd json-smart && ./mvnw -q clean install + run: cd json-smart && ./mvnw -q clean install test - name: Build project json-smart-action - run: cd json-smart-action && ./mvnw -q clean install + run: cd json-smart-action && ./mvnw -q clean install test - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 From 08e708a99044a37a905a366a2a761d20c8a16cef Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 18:26:57 +0200 Subject: [PATCH 12/30] add jacoco --- .github/workflows/coverage.yml | 49 ++++++++++++++++++++++++++++++++++ .github/workflows/security.yml | 6 ++--- .gitignore | 1 + accessors-smart/pom.xml | 19 +++++++++++++ json-smart/pom.xml | 19 +++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..c57a7c5 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,49 @@ +name: Coverage + +on: + push: + branches: [ master, upgrade ] + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - '.github/workflows/coverage.yml' + pull_request: + branches: [ master ] + paths: + - 'accessors-smart/**' + - 'json-smart/**' + - '.github/workflows/coverage.yml' + +permissions: + contents: read + +jobs: + coverage: + name: Code Coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: 11 + distribution: 'temurin' + cache: 'maven' + + - name: Build and test accessors-smart with coverage + run: cd accessors-smart && ./mvnw -q clean test + + - name: Build and test json-smart with coverage + run: cd json-smart && ./mvnw -q clean test + + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: | + accessors-smart/target/site/jacoco/jacoco.xml + json-smart/target/site/jacoco/jacoco.xml + format: jacoco \ No newline at end of file diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index d02e3d7..2a1bfbd 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -49,13 +49,13 @@ jobs: languages: ${{ matrix.language }} - name: Build project accessors-smart - run: cd accessors-smart && ./mvnw -q clean install test + run: cd accessors-smart && ./mvnw -q clean install - name: Build project json-smart - run: cd json-smart && ./mvnw -q clean install test + run: cd json-smart && ./mvnw -q clean install - name: Build project json-smart-action - run: cd json-smart-action && ./mvnw -q clean install test + run: cd json-smart-action && ./mvnw -q clean install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/.gitignore b/.gitignore index 4b7b9ce..76f248c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ **/bin **/target **/.vscode/ +.env diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index 2770188..98621d7 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -259,6 +259,25 @@ limitations under the License. + + org.jacoco + jacoco-maven-plugin + 0.8.13 + + + + prepare-agent + + + + report + test + + report + + + + diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 3a6f0ed..6fc3938 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -270,6 +270,25 @@ limitations under the License. + + org.jacoco + jacoco-maven-plugin + 0.8.13 + + + + prepare-agent + + + + report + test + + report + + + + From 0827ee7f80350b7997e4b53f1c1a538ee26085c6 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 18:31:00 +0200 Subject: [PATCH 13/30] patch coverage --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c57a7c5..96286f2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,7 +34,7 @@ jobs: cache: 'maven' - name: Build and test accessors-smart with coverage - run: cd accessors-smart && ./mvnw -q clean test + run: cd accessors-smart && ./mvnw -q clean install - name: Build and test json-smart with coverage run: cd json-smart && ./mvnw -q clean test From bcef083fe360ce7e3471767b42133c63b3a17cf4 Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 18:33:56 +0200 Subject: [PATCH 14/30] patch coverage --- .github/workflows/coverage.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 96286f2..856a36b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -39,11 +39,26 @@ jobs: - name: Build and test json-smart with coverage run: cd json-smart && ./mvnw -q clean test - - name: Upload coverage to Coveralls + - name: Upload accessors-smart coverage to Coveralls uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: | - accessors-smart/target/site/jacoco/jacoco.xml - json-smart/target/site/jacoco/jacoco.xml - format: jacoco \ No newline at end of file + file: accessors-smart/target/site/jacoco/jacoco.xml + format: jacoco + flag-name: accessors-smart + parallel: true + + - name: Upload json-smart coverage to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: json-smart/target/site/jacoco/jacoco.xml + format: jacoco + flag-name: json-smart + parallel: true + + - name: Finish parallel build + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true \ No newline at end of file From f22ff395f4c1b09f2626c321854749c94396418a Mon Sep 17 00:00:00 2001 From: Caimo Date: Sun, 3 Aug 2025 00:46:06 +0800 Subject: [PATCH 15/30] Support reading multiple JSON syntax blocks in a single input (#269) (#272) Co-authored-by: QIURC --- .../minidev/json/parser/JSONParserBase.java | 19 ++ .../json/parser/JSONParserByteArray.java | 14 +- .../json/parser/JSONParserInputStream.java | 13 +- .../minidev/json/parser/JSONParserReader.java | 14 +- .../minidev/json/parser/JSONParserStream.java | 22 +- .../minidev/json/parser/JSONParserString.java | 6 + .../json/parser/MultipleJsonParser.java | 67 ++++++ .../test/parser/MultipleJsonParserTest.java | 206 ++++++++++++++++++ .../minidev/json/test/parser/Transaction.java | 77 +++++++ 9 files changed, 391 insertions(+), 47 deletions(-) create mode 100644 json-smart/src/main/java/net/minidev/json/parser/MultipleJsonParser.java create mode 100644 json-smart/src/test/java/net/minidev/json/test/parser/MultipleJsonParserTest.java create mode 100644 json-smart/src/test/java/net/minidev/json/test/parser/Transaction.java diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java index 227dbb9..af3a000 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java @@ -197,12 +197,31 @@ private boolean compareDoublePrecision(String convert, String origin) { return j == originArray.length; } + protected boolean hasNext() { + return c != EOI; + } + /** + * parse from the first position
* use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory */ protected T parse(JsonReaderI mapper) throws ParseException { this.pos = -1; + return parseInner(mapper); + } + + /** + * parse from the last position
+ * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a + * ContainerFactory + */ + protected T parseNext(JsonReaderI mapper) throws ParseException { + this.pos = this.pos > 0 ? this.pos : -1; + return parseInner(mapper); + } + + private T parseInner(JsonReaderI mapper) throws ParseException { T result; try { read(); diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java index 29121dc..d9955b2 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java @@ -33,6 +33,12 @@ public JSONParserByteArray(int permissiveMode) { super(permissiveMode); } + public JSONParserByteArray(byte[] in, int permissiveMode) { + super(permissiveMode); + this.in = in; + this.len = in.length; + } + /** * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory @@ -41,14 +47,6 @@ public Object parse(byte[] in) throws ParseException { return parse(in, JSONValue.defaultReader.DEFAULT); } - // - // - // - // - // - // - // - /** * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserInputStream.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserInputStream.java index 076b302..0eac3ca 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserInputStream.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserInputStream.java @@ -33,6 +33,10 @@ public JSONParserInputStream(int permissiveMode) { super(permissiveMode); } + public JSONParserInputStream(InputStream in, int permissiveMode) { + super(new InputStreamReader(in, StandardCharsets.UTF_8), permissiveMode); + } + /** * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory @@ -54,13 +58,4 @@ public T parse(InputStream in, JsonReaderI mapper) // return super.parse(i2, mapper); } - - // - // - // - // - // - // - // - // } diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserReader.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserReader.java index 20f624e..a073090 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserReader.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserReader.java @@ -35,6 +35,11 @@ public JSONParserReader(int permissiveMode) { super(permissiveMode); } + public JSONParserReader(Reader in, int permissiveMode) { + super(permissiveMode); + this.in = in; + } + /** * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory @@ -54,19 +59,10 @@ public T parse(Reader in, JsonReaderI mapper) throws ParseException { return super.parse(mapper); } - // - // - // - // - // - // - // - protected void read() throws IOException { int i = in.read(); c = (i == -1) ? (char) EOI : (char) i; pos++; - // } protected void readS() throws IOException { diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserStream.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserStream.java index dbcc938..1ec1236 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserStream.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserStream.java @@ -28,8 +28,6 @@ * @see JSONParserReader */ abstract class JSONParserStream extends JSONParserBase { - // len - // public JSONParserStream(int permissiveMode) { super(permissiveMode); } @@ -112,26 +110,8 @@ protected void readString() throws ParseException, IOException { throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c); } sb.clear(); - // - // - // - // - // - // - // - // - // - // + /* assert (c == '\"' || c == '\'') */ readString2(); } - - // - // - // - // - // - // - // - // } diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserString.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserString.java index 94a4c78..637dfa7 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserString.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserString.java @@ -32,6 +32,12 @@ public JSONParserString(int permissiveMode) { super(permissiveMode); } + public JSONParserString(String in, int permissiveMode) { + super(permissiveMode); + this.in = in; + this.len = in.length(); + } + /** * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a * ContainerFactory diff --git a/json-smart/src/main/java/net/minidev/json/parser/MultipleJsonParser.java b/json-smart/src/main/java/net/minidev/json/parser/MultipleJsonParser.java new file mode 100644 index 0000000..76a1c68 --- /dev/null +++ b/json-smart/src/main/java/net/minidev/json/parser/MultipleJsonParser.java @@ -0,0 +1,67 @@ +package net.minidev.json.parser; + +import java.io.InputStream; +import java.io.Reader; +import net.minidev.json.JSONValue; +import net.minidev.json.writer.JsonReaderI; + +/** + * json-smart will parse multiple json separated by blank or line break character. + * + *

multiple json example:
+ * {"json1": "value1"} {"json2": "value2"}
+ * or
+ * [{"json1-key1": "value1"}] [{"json2": "value2"}] + */ +public class MultipleJsonParser { + + private final JSONParserBase jsonParser; + + public MultipleJsonParser(byte[] in, int permissiveMode) { + this.jsonParser = new JSONParserByteArray(in, permissiveMode); + } + + public MultipleJsonParser(InputStream in, int permissiveMode) { + this.jsonParser = new JSONParserInputStream(in, permissiveMode); + } + + public MultipleJsonParser(Reader in, int permissiveMode) { + this.jsonParser = new JSONParserReader(in, permissiveMode); + } + + public MultipleJsonParser(String in, int permissiveMode) { + this.jsonParser = new JSONParserString(in, permissiveMode); + } + + /** + * Parse next json with defaultReader
+ * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a + * ContainerFactory + */ + public Object parseNext() throws ParseException { + return jsonParser.parseNext(JSONValue.defaultReader.DEFAULT); + } + + /** + * Parse next json with target JsonReaderI
+ * use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a + * ContainerFactory + */ + public T parseNext(JsonReaderI mapper) throws ParseException { + return this.jsonParser.parseNext(mapper); + } + + /** Parse next json with target Class */ + public T parseNext(Class mapTo) throws ParseException { + return this.jsonParser.parseNext(JSONValue.defaultReader.getMapper(mapTo)); + } + + /** + * Checks if there is another JSON value available in the input. + * + * @return true if another JSON value exists, false otherwise + */ + public boolean hasNext() { + return this.jsonParser.hasNext(); + } +} diff --git a/json-smart/src/test/java/net/minidev/json/test/parser/MultipleJsonParserTest.java b/json-smart/src/test/java/net/minidev/json/test/parser/MultipleJsonParserTest.java new file mode 100644 index 0000000..7cecb8a --- /dev/null +++ b/json-smart/src/test/java/net/minidev/json/test/parser/MultipleJsonParserTest.java @@ -0,0 +1,206 @@ +package net.minidev.json.test.parser; + +import static net.minidev.json.parser.JSONParser.DEFAULT_PERMISSIVE_MODE; + +import java.io.ByteArrayInputStream; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; +import net.minidev.json.JSONValue; +import net.minidev.json.parser.JSONParser; +import net.minidev.json.parser.MultipleJsonParser; +import net.minidev.json.parser.ParseException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class MultipleJsonParserTest { + + @Test + public void testMultipleJsonsFromSingleJsonArraySuccess() + throws ParseException, UnsupportedEncodingException { + String json = + "[{\"friends\":[{\"id\":0,\"name\":\"test1\"},{\"id\":1,\"name\":\"test2\"}]}] other data"; + MultipleJsonParser parser = new MultipleJsonParser(json, DEFAULT_PERMISSIVE_MODE); + JSONArray root = (JSONArray) parser.parseNext(); + JSONObject rootObj = (JSONObject) root.get(0); + JSONArray array = (JSONArray) rootObj.get("friends"); + for (int idx = 0; idx < array.size(); idx++) { + JSONObject cap = (JSONObject) array.get(idx); + String first = (String) cap.get("name"); + Assertions.assertEquals("test" + (idx + 1), first); + } + } + + @Test + public void testMultipleJsonsFromMultipleJsonArraySuccess() + throws ParseException, UnsupportedEncodingException { + String json = + "[{\"friends\":[{\"id\":0,\"name\":\"test1\"},{\"id\":1,\"name\":\"test2\"}]}] " + + "[{\"friends\":[{\"id\":2,\"name\":\"test3\"},{\"id\":3,\"name\":\"test4\"}]}]"; + MultipleJsonParser parser = new MultipleJsonParser(json, DEFAULT_PERMISSIVE_MODE); + + // first + JSONArray root = (JSONArray) parser.parseNext(); + JSONObject rootObj = (JSONObject) root.get(0); + JSONArray array = (JSONArray) rootObj.get("friends"); + for (int idx = 0; idx < array.size(); idx++) { + JSONObject cap = (JSONObject) array.get(idx); + String first = (String) cap.get("name"); + Assertions.assertEquals("test" + (idx + 1), first); + } + + // second + JSONArray root2 = (JSONArray) parser.parseNext(); + JSONObject rootObj2 = (JSONObject) root2.get(0); + JSONArray array2 = (JSONArray) rootObj2.get("friends"); + for (int idx = 0; idx < array2.size(); idx++) { + JSONObject cap = (JSONObject) array2.get(idx); + String first = (String) cap.get("name"); + Assertions.assertEquals("test" + (idx + 3), first); + } + } + + @Test + public void testMultipleJsonsFromByteSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + "\n{tranid:\"1213\", \"user\":{\"name\":\"345\",\"addr\":\"4234 iu\"}}"; + MultipleJsonParser parser = + new MultipleJsonParser(json.getBytes(StandardCharsets.UTF_8), DEFAULT_PERMISSIVE_MODE); + + JSONObject root1 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1212", root1.get("tranid")); + + Assertions.assertTrue(parser.hasNext()); + JSONObject root2 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1213", root2.get("tranid")); + + Assertions.assertFalse(parser.hasNext()); + } + + @Test + public void testMultipleJsonsFromInputStreamSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + "\n{tranid:\"1213\", \"user\":{\"name\":\"345\",\"addr\":\"4234 iu\"}}"; + ByteArrayInputStream stream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); + MultipleJsonParser parser = new MultipleJsonParser(stream, DEFAULT_PERMISSIVE_MODE); + + JSONObject root1 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1212", root1.get("tranid")); + + Assertions.assertTrue(parser.hasNext()); + JSONObject root2 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1213", root2.get("tranid")); + + Assertions.assertFalse(parser.hasNext()); + } + + @Test + public void testMultipleJsonsFromInputStreamReaderSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + "\n{tranid:\"1213\", \"user\":{\"name\":\"345\",\"addr\":\"4234 iu\"}}"; + StringReader reader = new StringReader(json); + MultipleJsonParser parser = new MultipleJsonParser(reader, DEFAULT_PERMISSIVE_MODE); + + JSONObject root1 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1212", root1.get("tranid")); + + Assertions.assertTrue(parser.hasNext()); + JSONObject root2 = (JSONObject) parser.parseNext(); + Assertions.assertEquals("1213", root2.get("tranid")); + + Assertions.assertFalse(parser.hasNext()); + } + + @Test + public void testMultipleJsonsFromStringSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + " {tranid:\"1213\", \"user\":{\"name\":\"343\",\"addr\":\"4233 iu\"}}" + + "\r{tranid:\"1214\", \"user\":{\"name\":\"344\",\"addr\":\"4234 iu\"}}" + + "\t{tranid:\"1215\", \"user\":{\"name\":\"345\",\"addr\":\"4235 iu\"}}" + + "\n{tranid:\"1216\", \"user\":{\"name\":\"346\",\"addr\":\"4236 iu\"}}"; + MultipleJsonParser parser = new MultipleJsonParser(json, DEFAULT_PERMISSIVE_MODE); + JSONObject root1 = (JSONObject) parser.parseNext(JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("1212", root1.get("tranid")); + + int count = 3; + while (parser.hasNext()) { + JSONObject root2 = (JSONObject) parser.parseNext(JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("121" + count, root2.get("tranid")); + count++; + } + Assertions.assertEquals(7, count); + } + + @Test + public void testMultipleJsonsParseClassFromStringSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + " {tranid:\"1213\", \"user\":{\"name\":\"343\",\"addr\":\"4233 iu\"}}" + + "\r{tranid:\"1214\", \"user\":{\"name\":\"344\",\"addr\":\"4234 iu\"}}" + + "\t{tranid:\"1215\", \"user\":{\"name\":\"345\",\"addr\":\"4235 iu\"}}" + + "\n{tranid:\"1216\", \"user\":{\"name\":\"346\",\"addr\":\"4236 iu\"}}"; + MultipleJsonParser parser = new MultipleJsonParser(json, DEFAULT_PERMISSIVE_MODE); + JSONObject root1 = (JSONObject) parser.parseNext(JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("1212", root1.get("tranid")); + + int count = 3; + while (parser.hasNext()) { + Transaction root2 = parser.parseNext(Transaction.class); + Assertions.assertEquals("121" + count, root2.getTranid()); + Assertions.assertEquals("34" + count, root2.getUser().getName()); + count++; + } + Assertions.assertEquals(7, count); + } + + @Test + public void testMultipleJsonsFromInvalidStringFailed() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}} bbb " + + "\n{tranid:\"1213\", \"user\":{\"name\":\"343\",\"addr\":\"4233 iu\"}} "; + MultipleJsonParser parser = new MultipleJsonParser(json, DEFAULT_PERMISSIVE_MODE); + JSONObject root1 = (JSONObject) parser.parseNext(JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("1212", root1.get("tranid")); + + int count = 3; + while (parser.hasNext()) { + // return invalid input when parse failed + Object root2 = parser.parseNext(JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals( + "bbb \n" + "{tranid:\"1213\", \"user\":{\"name\":\"343\",\"addr\":\"4233 iu\"}}", root2); + count++; + } + Assertions.assertEquals(4, count); + } + + @Test + public void testMultipleJsonsWithJsonParserBySubStringSuccess() throws Exception { + String json = + "{tranid:\"1212\", \"user\":{\"name\":\"123\",\"addr\":\"786 rt\"}}" + + "\n{tranid:\"1213\", \"user\":{\"name\":\"345\",\"addr\":\"4234 iu\"}}"; + JSONParser parser = new JSONParser(DEFAULT_PERMISSIVE_MODE); + JSONObject root1 = (JSONObject) parser.parse(json, JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("1212", root1.get("tranid")); + + Field field = Class.forName("net.minidev.json.parser.JSONParserBase").getDeclaredField("pos"); + field.setAccessible(true); + Field pStringField = JSONParser.class.getDeclaredField("pString"); + pStringField.setAccessible(true); + Object parser2 = pStringField.get(parser); + Integer ipos = (Integer) field.get(parser2); + Assertions.assertEquals(54, ipos); + + JSONObject root2 = + (JSONObject) parser.parse(json.substring(ipos), JSONValue.defaultReader.DEFAULT); + Assertions.assertEquals("1213", root2.get("tranid")); + ipos = (Integer) field.get(parser2); + Assertions.assertEquals(56, ipos); + } +} diff --git a/json-smart/src/test/java/net/minidev/json/test/parser/Transaction.java b/json-smart/src/test/java/net/minidev/json/test/parser/Transaction.java new file mode 100644 index 0000000..e8c9db1 --- /dev/null +++ b/json-smart/src/test/java/net/minidev/json/test/parser/Transaction.java @@ -0,0 +1,77 @@ +package net.minidev.json.test.parser; + +import java.util.List; +import java.util.Map; + +/** Represents a transaction data structure parsed from JSON. */ +public class Transaction { + private String tranid; + private User user; + private List> friends; + + // Getters and Setters + public String getTranid() { + return tranid; + } + + public void setTranid(String tranid) { + this.tranid = tranid; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public List> getFriends() { + return friends; + } + + public void setFriends(List> friends) { + this.friends = friends; + } + + @Override + public String toString() { + return "Transaction{" + + "tranid='" + + tranid + + '\'' + + ", user=" + + user + + ", friends=" + + friends + + '}'; + } + + /** Represents the user object within the transaction. */ + public static class User { + private String name; + private String addr; + + // Getters and Setters + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } + + @Override + public String toString() { + return "User{" + "name='" + name + '\'' + ", addr='" + addr + '\'' + '}'; + } + } +} From 212c00ace429d24e8a346e346c474a9612e2ba6e Mon Sep 17 00:00:00 2001 From: urielch Date: Sat, 2 Aug 2025 19:11:54 +0200 Subject: [PATCH 16/30] change year + offset some code + fix warning --- accessors-smart/pom.xml | 2 +- .../main/java/net/minidev/asm/ASMUtil.java | 2 +- .../main/java/net/minidev/asm/Accessor.java | 2 +- .../java/net/minidev/asm/BeansAccess.java | 2 +- .../net/minidev/asm/DynamicClassLoader.java | 2 +- .../test/java/net/minidev/asm/ASMTest.java | 1 - json-smart/pom.xml | 2 +- .../main/java/net/minidev/json/JSONArray.java | 2 +- .../main/java/net/minidev/json/JSONAware.java | 2 +- .../java/net/minidev/json/JSONAwareEx.java | 2 +- .../main/java/net/minidev/json/JSONNavi.java | 2 +- .../java/net/minidev/json/JSONObject.java | 2 +- .../net/minidev/json/JSONStreamAware.java | 2 +- .../net/minidev/json/JSONStreamAwareEx.java | 2 +- .../main/java/net/minidev/json/JSONStyle.java | 2 +- .../main/java/net/minidev/json/JSONUtil.java | 2 +- .../main/java/net/minidev/json/JSONValue.java | 2 +- .../java/net/minidev/json/JStylerObj.java | 2 +- .../net/minidev/json/parser/JSONParser.java | 2 +- .../minidev/json/parser/JSONParserBase.java | 11 ++++---- .../json/parser/JSONParserByteArray.java | 2 +- .../json/parser/JSONParserInputStream.java | 2 +- .../minidev/json/parser/JSONParserMemory.java | 6 ++++- .../minidev/json/parser/JSONParserReader.java | 4 +-- .../minidev/json/parser/JSONParserStream.java | 25 +++++++++++++++++-- .../minidev/json/parser/JSONParserString.java | 4 ++- .../minidev/json/parser/ParseException.java | 2 +- .../net/minidev/json/writer/ArraysMapper.java | 2 +- .../net/minidev/json/writer/BeansMapper.java | 2 +- .../minidev/json/writer/CollectionMapper.java | 2 +- .../minidev/json/writer/CompessorMapper.java | 2 +- .../json/writer/DefaultMapperCollection.java | 2 +- .../json/writer/DefaultMapperOrdered.java | 2 +- .../net/minidev/json/writer/FakeMapper.java | 2 +- .../net/minidev/json/writer/JsonReader.java | 2 +- .../net/minidev/json/writer/JsonReaderI.java | 2 +- 36 files changed, 69 insertions(+), 42 deletions(-) diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index 98621d7..aa20816 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -1,5 +1,5 @@ diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 378eace..f0d8e1e 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -51,13 +51,9 @@ https://github.com/netplex/json-smart-v2 - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + central + https://central.sonatype.com/api/v1/publisher/upload diff --git a/json-smart/pom.xml b/json-smart/pom.xml index a1fafc6..0e03e13 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -66,13 +66,9 @@ limitations under the License. https://github.com/netplex/json-smart-v2 - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + central + https://central.sonatype.com/api/v1/publisher/upload