diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..d3bd5d9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: gradle + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 \ No newline at end of file diff --git a/.github/workflows/dependabot-gradle.yml b/.github/workflows/dependabot-gradle.yml new file mode 100644 index 0000000..fab0d7e --- /dev/null +++ b/.github/workflows/dependabot-gradle.yml @@ -0,0 +1,25 @@ +name: Dependabot Java CI with Gradle + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - uses: actions/checkout + with: + ref: ${{ github.event.pull_request.head.sha }} + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build + - name: Run everything + run: | + ./gradlew test diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..ffc8f79 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,39 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + if: ${{ github.actor != 'dependabot[bot]' }} + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.TOKEN_GIT }} + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build + - name: Run everything + run: | + sh run-everything + cd output + ./toMd.sh ../index.md + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: result adding back to repo [skip ci] another test diff --git a/.gitignore b/.gitignore index 9721afc..2b900d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Build target/ *.csv -*.txt build/ .gradle/ *.gz @@ -21,3 +20,5 @@ out/ *.json !ami.json *.log + +output/*.txt \ No newline at end of file diff --git a/build.gradle b/build.gradle index 52b1ab3..31a42f5 100644 --- a/build.gradle +++ b/build.gradle @@ -2,15 +2,17 @@ plugins { id 'java' id 'application' id 'com.github.johnrengelman.shadow' version '5.2.0' - id 'com.github.ben-manes.versions' version '0.28.0' + id 'com.github.ben-manes.versions' version '0.43.0' } group = 'com.github.fabienrenaud' version = '7' mainClassName = 'com.github.fabienrenaud.jjb.Cli' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_11 + +applicationDefaultJvmArgs = ["--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED"] repositories { mavenCentral() @@ -43,7 +45,7 @@ dependencies { implementation group: 'org.glassfish', name: 'javax.json', version: '1.1.4' // JSONB implementation group: 'javax.json.bind', name: 'javax.json.bind-api', version: '1.0' - implementation group: 'org.eclipse', name: 'yasson', version: '1.0.11' + implementation group: 'org.eclipse', name: 'yasson', version: '3.0.2' // GENSON implementation group: 'com.owlike', name: 'genson', version: '1.6' // FlexJson diff --git a/index.md b/index.md new file mode 100644 index 0000000..18681a2 --- /dev/null +++ b/index.md @@ -0,0 +1,261 @@ +2022-10-22 + +# *users* data type + +## JMH: Deserialization - 1000 KB + +| # | Benchmark | mode: | Throughput, | ops/time | | +| javaxjson/stream | | | | +| | | | | | | +| # | Run | progress: | 66.67% | complete, | ETA | +| # | Fork: | 1 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=302604088310502 | +| 97.561 | ops/s | | | | | +| Iteration | 1: | 236.208 | ops/s | | | +| | | | | | | +| # | Run | progress: | 68.18% | complete, | ETA | +| # | Fork: | 2 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=302618047231209 | +| 152.718 | ops/s | | | | | +| Iteration | 1: | 241.265 | ops/s | | | +| | | | | | | +| | | | | | | +| javaxjson/stream": | | | | | +| 238.736 | ops/s | | | | | +| | | | | | | +| | | | | | | +| # | JMH | version: | 1.33 | | | +| # | VM | version: | JDK | 17.0.4, | OpenJDK | +| # | VM | invoker: | /home/mintozzy/.sdkman/candidates/java/22.2.r17-grl/bin/java | | | +| # | VM | options: | -XX:ThreadPriorityPolicy=1 | -XX:+UnlockExperimentalVMOptions | -XX:+EnableJVMCIProduct | +| # | Blackhole | mode: | full | + | dont-inline | +| # | Warmup: | 1 | iterations, | 10 | s | +| # | Measurement: | 1 | iterations, | 2 | s | +| # | Timeout: | 10 | min | per | iteration | +| # | Threads: | 16 | threads, | will | synchronize | +| # | Benchmark | mode: | Throughput, | ops/time | | +| jsonio/stream | | | | +| | | | | | | +| # | Run | progress: | 69.70% | complete, | ETA | +| # | Fork: | 1 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=302631891832633 | + +## JMH: Deserialization - 10 KB + +| Benchmark | Mode | Cnt | Score | Error | Units | +|-----------|------|-----|-------|-------|-------| +| avajejsonb/databind | thrpt | 2 | 54005.389 | ops/s | | +| avajejsonb_jackson/databind | thrpt | 2 | 36925.350 | ops/s | | +| dsljson/databind | thrpt | 2 | 69102.664 | ops/s | | +| dsljson_reflection/databind | thrpt | 2 | 48574.896 | ops/s | | +| fastjson/databind | thrpt | 2 | 37747.513 | ops/s | | +| flexjson/databind | thrpt | 2 | 6884.114 | ops/s | | +| genson/databind | thrpt | 2 | 29363.905 | ops/s | | +| gson/databind | thrpt | 2 | 29921.616 | ops/s | | +| jackson/databind | thrpt | 2 | 37711.584 | ops/s | | +| jackson_afterburner/databind | thrpt | 2 | 43057.176 | ops/s | | +| jackson_blackbird/databind | thrpt | 2 | 40909.535 | ops/s | | +| jodd/databind | thrpt | 2 | 30561.517 | ops/s | | +| johnzon/databind | thrpt | 2 | 13691.347 | ops/s | | +| jsonsmart/databind | thrpt | 2 | 36760.182 | ops/s | | +| logansquare/databind | thrpt | 2 | 38064.617 | ops/s | | +| moshi/databind | thrpt | 2 | 26968.731 | ops/s | | +| yasson/databind | thrpt | 2 | 6910.953 | ops/s | | +| genson/stream | thrpt | 2 | 45845.491 | ops/s | | +| gson/stream | thrpt | 2 | 40362.608 | ops/s | | +| jackson/stream | thrpt | 2 | 40131.419 | ops/s | | +| javaxjson/stream | thrpt | 2 | 14664.587 | ops/s | | +| jsonio/stream | thrpt | 2 | 8390.436 | ops/s | | +| jsonsimple/stream | thrpt | 2 | 10104.037 | ops/s | | +| minimaljson/stream | thrpt | 2 | 28654.995 | ops/s | | +| mjson/stream | thrpt | 2 | 10137.066 | ops/s | | +| moshi/stream | thrpt | 2 | 29554.606 | ops/s | | +| nanojson/stream | thrpt | 2 | 25102.768 | ops/s | | +| orgjson/stream | thrpt | 2 | 11259.996 | ops/s | | +| purejson/stream | thrpt | 2 | 6771.798 | ops/s | | +| tapestry/stream | thrpt | 2 | 36592.065 | ops/s | | + +## JMH: Deserialization - 1 KB + +| Benchmark | Mode | Cnt | Score | Error | Units | +|-----------|------|-----|-------|-------|-------| +| avajejsonb/databind | thrpt | 2 | 624962.583 | ops/s | | +| avajejsonb_jackson/databind | thrpt | 2 | 466918.677 | ops/s | | +| dsljson/databind | thrpt | 2 | 820010.890 | ops/s | | +| dsljson_reflection/databind | thrpt | 2 | 583335.098 | ops/s | | +| fastjson/databind | thrpt | 2 | 297191.131 | ops/s | | +| flexjson/databind | thrpt | 2 | 80740.006 | ops/s | | +| genson/databind | thrpt | 2 | 353564.220 | ops/s | | +| gson/databind | thrpt | 2 | 343625.586 | ops/s | | +| jackson/databind | thrpt | 2 | 455998.590 | ops/s | | +| jackson_afterburner/databind | thrpt | 2 | 493959.078 | ops/s | | +| jackson_blackbird/databind | thrpt | 2 | 468453.693 | ops/s | | +| jodd/databind | thrpt | 2 | 309085.725 | ops/s | | +| johnzon/databind | thrpt | 2 | 171410.990 | ops/s | | +| jsonsmart/databind | thrpt | 2 | 399677.771 | ops/s | | +| logansquare/databind | thrpt | 2 | 230431.332 | ops/s | | +| moshi/databind | thrpt | 2 | 368204.261 | ops/s | | +| yasson/databind | thrpt | 2 | 85356.962 | ops/s | | +| genson/stream | thrpt | 2 | 422320.899 | ops/s | | +| gson/stream | thrpt | 2 | 413403.114 | ops/s | | +| jackson/stream | thrpt | 2 | 466533.498 | ops/s | | +| javaxjson/stream | thrpt | 2 | 40338.546 | ops/s | | +| jsonio/stream | thrpt | 2 | 99302.659 | ops/s | | +| jsonsimple/stream | thrpt | 2 | 135489.105 | ops/s | | +| minimaljson/stream | thrpt | 2 | 309484.974 | ops/s | | +| mjson/stream | thrpt | 2 | 111380.614 | ops/s | | +| moshi/stream | thrpt | 2 | 340699.598 | ops/s | | +| nanojson/stream | thrpt | 2 | 139411.537 | ops/s | | +| orgjson/stream | thrpt | 2 | 110455.834 | ops/s | | +| purejson/stream | thrpt | 2 | 79386.207 | ops/s | | +| tapestry/stream | thrpt | 2 | 381093.265 | ops/s | | + +## JMH: Serialization - 1000 KB + +| Benchmark | Mode | Cnt | Score | Error | Units | +|-----------|------|-----|-------|-------|-------| +| avajejsonb/databind | thrpt | 2 | 909.796 | ops/s | | +| avajejsonb_jackson/databind | thrpt | 2 | 725.338 | ops/s | | +| dsljson/databind | thrpt | 2 | 1211.758 | ops/s | | +| dsljson_reflection/databind | thrpt | 2 | 879.461 | ops/s | | +| fastjson/databind | thrpt | 2 | 286.244 | ops/s | | +| flexjson/databind | thrpt | 2 | 34.818 | ops/s | | +| genson/databind | thrpt | 2 | 465.310 | ops/s | | +| gson/databind | thrpt | 2 | 329.002 | ops/s | | +| jackson/databind | thrpt | 2 | 677.204 | ops/s | | +| jackson_afterburner/databind | thrpt | 2 | 748.052 | ops/s | | +| jackson_blackbird/databind | thrpt | 2 | 709.803 | ops/s | | +| jodd/databind | thrpt | 2 | 121.420 | ops/s | | +| johnzon/databind | thrpt | 2 | 276.222 | ops/s | | +| jsonsmart/databind | thrpt | 2 | 342.483 | ops/s | | +| logansquare/databind | thrpt | 2 | 930.066 | ops/s | | +| moshi/databind | thrpt | 2 | 354.500 | ops/s | | +| yasson/databind | thrpt | 2 | 272.193 | ops/s | | +| genson/stream | thrpt | 2 | 463.230 | ops/s | | +| gson/stream | thrpt | 2 | 162.848 | ops/s | | +| jackson/stream | thrpt | 2 | 872.831 | ops/s | | +| javaxjson/stream | thrpt | 2 | 797.142 | ops/s | | +| jsonio/stream | thrpt | 2 | 136.553 | ops/s | | +| jsonsimple/stream | thrpt | 2 | 94.080 | ops/s | | +| minimaljson/stream | thrpt | 2 | 431.163 | ops/s | | +| mjson/stream | thrpt | 2 | 120.385 | ops/s | | +| moshi/stream | thrpt | 2 | 493.473 | ops/s | | +| nanojson/stream | thrpt | 2 | 709.363 | ops/s | | +| orgjson/stream | thrpt | 2 | 170.667 | ops/s | | +| purejson/stream | thrpt | 2 | 6.409 | ops/s | | +| tapestry/stream | thrpt | 2 | 92.288 | ops/s | | + +## JMH: Serialization - 100 KB + +| # | Benchmark | mode: | Throughput, | ops/time | | +| avajejsonb/databind | | | | +| | | | | | | +| # | Run | progress: | 0.00% | complete, | ETA | +| # | Fork: | 1 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=298585768449823 | +| 10320.877 | ops/s | | | | | +| Iteration | 1: | 10780.606 | ops/s | | | +| | | | | | | +| # | Run | progress: | 1.52% | complete, | ETA | +| # | Fork: | 2 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=298599019564176 | +| 11059.269 | ops/s | | | | | +| Iteration | 1: | 10597.304 | ops/s | | | +| | | | | | | +| | | | | | | +| avajejsonb/databind": | | | | | +| 10688.955 | ops/s | | | | | +| | | | | | | +| | | | | | | +| # | JMH | version: | 1.33 | | | +| # | VM | version: | JDK | 17.0.4, | OpenJDK | +| # | VM | invoker: | /home/mintozzy/.sdkman/candidates/java/22.2.r17-grl/bin/java | | | +| # | VM | options: | -XX:ThreadPriorityPolicy=1 | -XX:+UnlockExperimentalVMOptions | -XX:+EnableJVMCIProduct | +| # | Blackhole | mode: | full | + | dont-inline | +| # | Warmup: | 1 | iterations, | 10 | s | +| # | Measurement: | 1 | iterations, | 2 | s | +| # | Timeout: | 10 | min | per | iteration | +| # | Threads: | 16 | threads, | will | synchronize | +| # | Benchmark | mode: | Throughput, | ops/time | | +| avajejsonb_jackson/databind | | | | +| | | | | | | +| # | Run | progress: | 3.03% | complete, | ETA | +| # | Fork: | 1 | of | 2 | | +| OpenJDK | 64-Bit | Server | VM | warning: | -XX:ThreadPriorityPolicy=1 | +| # | Warmup | Iteration | 1: | Using | SEED=298612265677184 | + +## JMH: Serialization - 10 KB + +| Benchmark | Mode | Cnt | Score | Error | Units | +|-----------|------|-----|-------|-------|-------| +| avajejsonb/databind | thrpt | 2 | 114531.353 | ops/s | | +| avajejsonb_jackson/databind | thrpt | 2 | 89917.118 | ops/s | | +| dsljson/databind | thrpt | 2 | 114508.712 | ops/s | | +| dsljson_reflection/databind | thrpt | 2 | 89277.436 | ops/s | | +| fastjson/databind | thrpt | 2 | 53726.393 | ops/s | | +| flexjson/databind | thrpt | 2 | 295.878 | ops/s | | +| genson/databind | thrpt | 2 | 44159.073 | ops/s | | +| gson/databind | thrpt | 2 | 33678.323 | ops/s | | +| jackson/databind | thrpt | 2 | 95337.370 | ops/s | | +| jackson_afterburner/databind | thrpt | 2 | 100637.060 | ops/s | | +| jackson_blackbird/databind | thrpt | 2 | 90378.728 | ops/s | | +| jodd/databind | thrpt | 2 | 14288.889 | ops/s | | +| johnzon/databind | thrpt | 2 | 32237.287 | ops/s | | +| jsonsmart/databind | thrpt | 2 | 30488.845 | ops/s | | +| logansquare/databind | thrpt | 2 | 87328.072 | ops/s | | +| moshi/databind | thrpt | 2 | 33484.818 | ops/s | | +| yasson/databind | thrpt | 2 | 28699.823 | ops/s | | +| genson/stream | thrpt | 2 | 40289.101 | ops/s | | +| gson/stream | thrpt | 2 | 14416.889 | ops/s | | +| jackson/stream | thrpt | 2 | 93692.784 | ops/s | | +| javaxjson/stream | thrpt | 2 | 64441.873 | ops/s | | +| jsonio/stream | thrpt | 2 | 10725.616 | ops/s | | +| jsonsimple/stream | thrpt | 2 | 7554.123 | ops/s | | +| minimaljson/stream | thrpt | 2 | 31133.600 | ops/s | | +| mjson/stream | thrpt | 2 | 12092.740 | ops/s | | +| moshi/stream | thrpt | 2 | 38112.080 | ops/s | | +| nanojson/stream | thrpt | 2 | 62321.300 | ops/s | | +| orgjson/stream | thrpt | 2 | 11842.706 | ops/s | | +| purejson/stream | thrpt | 2 | 5773.181 | ops/s | | +| tapestry/stream | thrpt | 2 | 6429.512 | ops/s | | + +## JMH: Serialization - 1 KB + +| Benchmark | Mode | Cnt | Score | Error | Units | +|-----------|------|-----|-------|-------|-------| +| avajejsonb/databind | thrpt | 2 | 894924.900 | ops/s | | +| avajejsonb_jackson/databind | thrpt | 2 | 773176.956 | ops/s | | +| dsljson/databind | thrpt | 2 | 1160153.247 | ops/s | | +| dsljson_reflection/databind | thrpt | 2 | 910009.496 | ops/s | | +| fastjson/databind | thrpt | 2 | 847854.362 | ops/s | | +| flexjson/databind | thrpt | 2 | 1442.951 | ops/s | | +| genson/databind | thrpt | 2 | 531644.539 | ops/s | | +| gson/databind | thrpt | 2 | 351756.931 | ops/s | | +| jackson/databind | thrpt | 2 | 819795.872 | ops/s | | +| jackson_afterburner/databind | thrpt | 2 | 817250.051 | ops/s | | +| jackson_blackbird/databind | thrpt | 2 | 787275.241 | ops/s | | +| jodd/databind | thrpt | 2 | 134957.460 | ops/s | | +| johnzon/databind | thrpt | 2 | 372523.854 | ops/s | | +| jsonsmart/databind | thrpt | 2 | 324399.536 | ops/s | | +| logansquare/databind | thrpt | 2 | 881008.053 | ops/s | | +| moshi/databind | thrpt | 2 | 321891.464 | ops/s | | +| yasson/databind | thrpt | 2 | 297482.821 | ops/s | | +| genson/stream | thrpt | 2 | 428789.230 | ops/s | | +| gson/stream | thrpt | 2 | 242049.815 | ops/s | | +| jackson/stream | thrpt | 2 | 904008.643 | ops/s | | +| javaxjson/stream | thrpt | 2 | 687635.775 | ops/s | | +| jsonio/stream | thrpt | 2 | 106270.217 | ops/s | | +| jsonsimple/stream | thrpt | 2 | 132087.245 | ops/s | | +| minimaljson/stream | thrpt | 2 | 450195.906 | ops/s | | +| mjson/stream | thrpt | 2 | 147958.702 | ops/s | | +| moshi/stream | thrpt | 2 | 390937.392 | ops/s | | +| nanojson/stream | thrpt | 2 | 661480.535 | ops/s | | +| orgjson/stream | thrpt | 2 | 143553.352 | ops/s | | +| purejson/stream | thrpt | 2 | 81867.154 | ops/s | | +| tapestry/stream | thrpt | 2 | 99915.994 | ops/s | | + diff --git a/output/toMd.sh b/output/toMd.sh index 9c4665b..00cdf05 100755 --- a/output/toMd.sh +++ b/output/toMd.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh -e +#!/bin/bash datatypes=$(ls *.txt | cut -d- -f1 | sort | uniq) diff --git a/run b/run index f8ccae2..cd5b55d 100755 --- a/run +++ b/run @@ -3,7 +3,7 @@ JAR=build/libs/app.jar HEAP_SIZE=2g -[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -XX:+AggressiveOpts -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE}" +[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE}" [ -z ${SEED} ] && export SEED=${RANDOM} [ -z ${SHADOW} ] && echo ./gradlew clean build shadowJar && ./gradlew clean build shadowJar diff --git a/run.ps1 b/run.ps1 index be36553..0f0548e 100644 --- a/run.ps1 +++ b/run.ps1 @@ -2,7 +2,7 @@ $jar = "build\libs\app.jar" $heapSize = "2g" if (-not (Test-Path env:JVM_OPTIONS)) { - $jvmOpts = "-server -XX:+AggressiveOpts -Xms${heapSize} -Xmx${heapSize}" + $jvmOpts = "-server -Xms${heapSize} -Xmx${heapSize}" } else { $jvmOpts = "$env:JVM_OPTIONS" } diff --git a/src/main/java/com/github/fabienrenaud/jjb/Cli.java b/src/main/java/com/github/fabienrenaud/jjb/Cli.java index 5c9621e..3fe9c42 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/Cli.java +++ b/src/main/java/com/github/fabienrenaud/jjb/Cli.java @@ -48,13 +48,13 @@ public static abstract class AbstractCommand implements Runnable { * JMH options */ @Option(type = OptionType.GLOBAL, name = "-f", description = "JMH: forks. Defaults to 2.") - public int forks = 2; - @Option(type = OptionType.GLOBAL, name = "-wi", description = "JMH: warmup iterations. Defaults to 5.") - public int warmupIterations = 5; - @Option(type = OptionType.GLOBAL, name = "-i", description = "JMH: measurement iterations. Defaults to 10.") - public int measurementIterations = 10; - @Option(type = OptionType.GLOBAL, name = "-m", description = "JMH: measurement time in seconds. Defaults to 3.") - public int measurementTime = 3; + public int forks = 1; + @Option(type = OptionType.GLOBAL, name = "-wi", description = "JMH: warmup iterations. Defaults to 1.") + public int warmupIterations = 1; + @Option(type = OptionType.GLOBAL, name = "-i", description = "JMH: measurement iterations. Defaults to 1.") + public int measurementIterations = 1; + @Option(type = OptionType.GLOBAL, name = "-m", description = "JMH: measurement time in seconds. Defaults to 2.") + public int measurementTime = 2; @Option(type = OptionType.GLOBAL, name = "-t", description = "JMH: number of threads. Defaults to 16.") public int threads = 16; diff --git a/src/main/java/com/github/fabienrenaud/jjb/provider/ClientsJsonProvider.java b/src/main/java/com/github/fabienrenaud/jjb/provider/ClientsJsonProvider.java index 0ef61af..254bea9 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/provider/ClientsJsonProvider.java +++ b/src/main/java/com/github/fabienrenaud/jjb/provider/ClientsJsonProvider.java @@ -11,11 +11,7 @@ import com.fasterxml.jackson.module.afterburner.AfterburnerModule; import com.fasterxml.jackson.module.blackbird.BlackbirdModule; import com.github.fabienrenaud.jjb.model.Clients; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializer; +import com.google.gson.*; import com.owlike.genson.Context; import com.owlike.genson.Converter; import com.owlike.genson.Genson; @@ -33,9 +29,9 @@ import org.apache.johnzon.core.JsonProviderImpl; import org.apache.johnzon.mapper.Mapper; import org.eclipse.yasson.JsonBindingProvider; +import org.eclipse.yasson.YassonJsonb; import javax.annotation.Nullable; -import javax.json.bind.Jsonb; import java.io.IOException; import java.math.BigDecimal; import java.time.LocalDate; @@ -72,6 +68,7 @@ public class ClientsJsonProvider implements JsonProvider { public void serialize(LocalDate object, com.owlike.genson.stream.ObjectWriter writer, Context ctx) { writer.writeString(object.toString()); } + public LocalDate deserialize(ObjectReader reader, Context ctx) { return LocalDate.parse(reader.valueAsString()); } @@ -80,26 +77,27 @@ public LocalDate deserialize(ObjectReader reader, Context ctx) { public void serialize(OffsetDateTime object, com.owlike.genson.stream.ObjectWriter writer, Context ctx) { writer.writeString(object.toString()); } + public OffsetDateTime deserialize(ObjectReader reader, Context ctx) { return OffsetDateTime.parse(reader.valueAsString()); } }, OffsetDateTime.class) .create(); - private final Jsonb yasson = new JsonBindingProvider().create() - .withProvider(new org.glassfish.json.JsonProviderImpl()) + private final YassonJsonb yasson = (YassonJsonb) new JsonBindingProvider().create() +// .withProvider("org.glassfish.json.JsonProviderImpl") .build(); - private static final AbstractTransformer FLEX_IDENTITY = new AbstractTransformer() { - @Override - public void transform(Object o) { - getContext().writeQuoted(o.toString()); - } - }; + private static final AbstractTransformer FLEX_IDENTITY = new AbstractTransformer() { + @Override + public void transform(Object o) { + getContext().writeQuoted(o.toString()); + } + }; private final JSONDeserializer flexjsonDeser = new JSONDeserializer() .use(UUID.class, (objectBinder, o, type, aClass) -> UUID.fromString((String) o)) .use(LocalDate.class, (objectBinder, o, type, aClass) -> LocalDate.parse((String) o)) .use(OffsetDateTime.class, (objectBinder, o, type, aClass) -> OffsetDateTime.parse((String) o)); - private final org.boon.json.ObjectMapper boon = org.boon.json.JsonFactory.create(); + private final org.boon.json.ObjectMapper boon = org.boon.json.JsonFactory.create(); private final Mapper johnzon; private final com.squareup.moshi.JsonAdapter moshi = new Moshi.Builder().add(UUID.class, new JsonAdapter() { @@ -108,6 +106,7 @@ public void transform(Object o) { public UUID fromJson(com.squareup.moshi.JsonReader reader) throws IOException { return UUID.fromString(reader.nextString()); } + @Override public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable UUID value) throws IOException { writer.value(value.toString()); @@ -118,6 +117,7 @@ public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable UUID value) t public BigDecimal fromJson(com.squareup.moshi.JsonReader reader) throws IOException { return new BigDecimal(reader.nextString()); } + @Override public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable BigDecimal value) throws IOException { writer.value(value.toPlainString()); @@ -128,6 +128,7 @@ public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable BigDecimal va public LocalDate fromJson(com.squareup.moshi.JsonReader reader) throws IOException { return LocalDate.parse(reader.nextString()); } + @Override public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable LocalDate value) throws IOException { writer.value(value.toString()); @@ -138,6 +139,7 @@ public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable LocalDate val public OffsetDateTime fromJson(com.squareup.moshi.JsonReader reader) throws IOException { return OffsetDateTime.parse(reader.nextString()); } + @Override public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable OffsetDateTime value) throws IOException { writer.value(value.toString()); @@ -151,10 +153,10 @@ public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable OffsetDateTim private final DslJson dsljson_reflection = new DslJson<>(Settings.withRuntime());//don't include generated classes private final io.avaje.jsonb.JsonType avajeJsonb_jackson = io.avaje.jsonb.Jsonb - .newBuilder() + .builder() .adapter(new JacksonAdapter(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Clients.class); private final io.avaje.jsonb.JsonType avajeJsonb_default = io.avaje.jsonb.Jsonb - .newBuilder() + .builder() .adapter(new JsonStream(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Clients.class); private final Map jsonioStreamOptions = new HashMap<>(); @@ -167,15 +169,15 @@ public ClientsJsonProvider() { // set johnson JsonReader (default is `JsonProvider.provider()`) javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl(); johnzon = new org.apache.johnzon.mapper.MapperBuilder() - .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) - .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) - .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes - .build(); + .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) + .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) + .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes + .build(); TypeConverterManager joddTypeConverterManager = TypeConverterManager.get(); - joddTypeConverterManager.register(UUID.class, value -> UUID.fromString((String)value)); - joddTypeConverterManager.register(LocalDate.class, value -> LocalDate.parse((String)value)); - joddTypeConverterManager.register(OffsetDateTime.class, value -> OffsetDateTime.parse((String)value)); + joddTypeConverterManager.register(UUID.class, value -> UUID.fromString((String) value)); + joddTypeConverterManager.register(LocalDate.class, value -> LocalDate.parse((String) value)); + joddTypeConverterManager.register(OffsetDateTime.class, value -> OffsetDateTime.parse((String) value)); } @@ -215,7 +217,7 @@ public Genson genson() { } @Override - public Jsonb yasson() { + public YassonJsonb yasson() { return yasson; } diff --git a/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java b/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java index 9df7f6f..ce2a186 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java +++ b/src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java @@ -8,8 +8,7 @@ import flexjson.JSONDeserializer; import flexjson.JSONSerializer; import org.apache.johnzon.mapper.Mapper; - -import javax.json.bind.Jsonb; +import org.eclipse.yasson.YassonJsonb; import java.util.Map; @@ -29,7 +28,7 @@ public interface JsonProvider { Genson genson(); - Jsonb yasson(); + YassonJsonb yasson(); JSONDeserializer flexjsonDeser(); diff --git a/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java b/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java index 3a40599..4b53f20 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java +++ b/src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java @@ -12,21 +12,19 @@ import com.google.gson.Gson; import com.owlike.genson.Genson; import com.squareup.moshi.Moshi; - import flexjson.JSONDeserializer; import io.avaje.jsonb.JsonType; -import io.avaje.jsonb.stream.JsonStream; import io.avaje.jsonb.jackson.JacksonAdapter; +import io.avaje.jsonb.stream.JsonStream; import org.apache.johnzon.core.JsonProviderImpl; import org.apache.johnzon.mapper.Mapper; import org.eclipse.yasson.JsonBindingProvider; +import org.eclipse.yasson.YassonJsonb; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import javax.json.bind.Jsonb; - public class UsersJsonProvider implements JsonProvider { private final Gson gson = new Gson(); @@ -38,8 +36,8 @@ public class UsersJsonProvider implements JsonProvider { .registerModule(new BlackbirdModule()); private final JsonFactory jacksonFactory = new JsonFactory(); private final Genson genson = new Genson(); - private final Jsonb yasson = new JsonBindingProvider().create() - .withProvider(new org.glassfish.json.JsonProviderImpl()) + private final YassonJsonb yasson = (YassonJsonb) new JsonBindingProvider().create() +// .withProvider(new org.glassfish.json.JsonProviderImpl()) .build(); private final JSONDeserializer flexjsonDeser = new JSONDeserializer<>(); private final org.boon.json.ObjectMapper boon = org.boon.json.JsonFactory.create(); @@ -54,8 +52,8 @@ public class UsersJsonProvider implements JsonProvider { private final Map jsonioStreamOptions = new HashMap<>(); - private final JsonType avajeJsonb_jackson = io.avaje.jsonb.Jsonb.newBuilder().adapter(new JacksonAdapter(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Users.class); - private final JsonType avajeJsonb_default = io.avaje.jsonb.Jsonb.newBuilder().adapter(new JsonStream(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Users.class); + private final JsonType avajeJsonb_jackson = io.avaje.jsonb.Jsonb.builder().adapter(new JacksonAdapter(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Users.class); + private final JsonType avajeJsonb_default = io.avaje.jsonb.Jsonb.builder().adapter(new JsonStream(/* serializeNulls */ true, /* serializeEmpty */ true, /* failOnUnknown */ false)).build().type(Users.class); public UsersJsonProvider() { jsonioStreamOptions.put(JsonReader.USE_MAPS, true); @@ -64,10 +62,10 @@ public UsersJsonProvider() { // set johnson JsonReader (default is `JsonProvider.provider()`) javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl(); johnzon = new org.apache.johnzon.mapper.MapperBuilder() - .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) - .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) - .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes - .build(); + .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) + .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) + .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes + .build(); } @Override @@ -106,7 +104,7 @@ public Genson genson() { } @Override - public Jsonb yasson() { + public YassonJsonb yasson() { return yasson; }