Skip to content

Commit 9e08655

Browse files
jderegclaude
authored andcommitted
Switch json-io stream deser to JsonIo.toMaps() (toObjects deprecated)
JsonIo.toObjects(InputStream, ReadOptions, Class) is deprecated as of json-io 4.101.0+ (will be removed in 5.0.0). The clean substitute is JsonIo.toMaps(InputStream).asClass(JsonObject.class), which routes through the same MapResolver path and manages Maps-mode options internally via its own cache (no need to pass options). The result is materialized as JsonObject so the round-trip verification in JsonBenchmark.test() recognizes it (instanceof JsonObject branch re-serializes via WriteOptionsBuilder().standardJson().build() before parity-checking against Jackson's Users/Clients POJOs). Removed the now-unused jsonioReadOptionsMaps() method (and its cached field) from JsonProvider, UsersJsonProvider, and ClientsJsonProvider -- the provider is the harness's "cache library config once" pattern, and toMaps() handles its own caching. Files: - stream/Deserialization.java: switch to JsonIo.toMaps().asClass(JsonObject.class) - provider/JsonProvider.java: drop jsonioReadOptionsMaps() declaration - provider/UsersJsonProvider.java: drop the field + override - provider/ClientsJsonProvider.java: drop the field + override 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent da5ece4 commit 9e08655

4 files changed

Lines changed: 15 additions & 29 deletions

File tree

src/main/java/com/github/fabienrenaud/jjb/provider/ClientsJsonProvider.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.fabienrenaud.jjb.provider;
22

3-
import com.cedarsoftware.io.ReadOptions;
4-
import com.cedarsoftware.io.ReadOptionsBuilder;
53
import com.cedarsoftware.io.WriteOptions;
64
import com.cedarsoftware.io.WriteOptionsBuilder;
75
import com.dslplatform.json.DslJson;
@@ -166,10 +164,10 @@ public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable OffsetDateTim
166164

167165
private final com.bigcloud.djomo.Json djomo = new com.bigcloud.djomo.Json();
168166

169-
// json-io options are immutable+thread-safe once built; cache one instance per provider
170-
// to match how every other library here caches its mapper/parser/serializer.
167+
// json-io WriteOptions is immutable+thread-safe once built; cache one instance per provider
168+
// to match how every other library here caches its mapper/parser/serializer. Read-side uses
169+
// JsonIo.toMaps()/toJava() which manage their own option caches internally.
171170
private final WriteOptions jsonioWriteOptions = new WriteOptionsBuilder().standardJson().build();
172-
private final ReadOptions jsonioReadOptionsMaps = new ReadOptionsBuilder().returnAsNativeJsonObjects().build();
173171

174172
public ClientsJsonProvider() {
175173

@@ -305,11 +303,6 @@ public WriteOptions jsonioWriteOptions() {
305303
return jsonioWriteOptions;
306304
}
307305

308-
@Override
309-
public ReadOptions jsonioReadOptionsMaps() {
310-
return jsonioReadOptionsMaps;
311-
}
312-
313306
private static final ThreadLocal<QuickbufSchema.Clients> QUICKBUF_MESSAGE = ThreadLocal.withInitial(QuickbufSchema.Clients::newInstance);
314307
private static final ThreadLocal<JsonSink> QUICKBUF_SINK = ThreadLocal.withInitial(() -> JsonSink.newInstance()
315308
.setPrettyPrinting(false)

src/main/java/com/github/fabienrenaud/jjb/provider/JsonProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.fabienrenaud.jjb.provider;
22

3-
import com.cedarsoftware.io.ReadOptions;
43
import com.cedarsoftware.io.WriteOptions;
54
import com.dslplatform.json.DslJson;
65
import com.fasterxml.jackson.core.JsonFactory;
@@ -66,6 +65,4 @@ public interface JsonProvider<T> {
6665

6766
WriteOptions jsonioWriteOptions();
6867

69-
ReadOptions jsonioReadOptionsMaps();
70-
7168
}

src/main/java/com/github/fabienrenaud/jjb/provider/UsersJsonProvider.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.fabienrenaud.jjb.provider;
22

3-
import com.cedarsoftware.io.ReadOptions;
4-
import com.cedarsoftware.io.ReadOptionsBuilder;
53
import com.cedarsoftware.io.WriteOptions;
64
import com.cedarsoftware.io.WriteOptionsBuilder;
75
import com.dslplatform.json.DslJson;
@@ -62,10 +60,10 @@ public class UsersJsonProvider implements JsonProvider<Users> {
6260

6361
private final com.bigcloud.djomo.Json djomo = new com.bigcloud.djomo.Json();
6462

65-
// json-io options are immutable+thread-safe once built; cache one instance per provider
66-
// to match how every other library here caches its mapper/parser/serializer.
63+
// json-io WriteOptions is immutable+thread-safe once built; cache one instance per provider
64+
// to match how every other library here caches its mapper/parser/serializer. Read-side uses
65+
// JsonIo.toMaps()/toJava() which manage their own option caches internally.
6766
private final WriteOptions jsonioWriteOptions = new WriteOptionsBuilder().standardJson().build();
68-
private final ReadOptions jsonioReadOptionsMaps = new ReadOptionsBuilder().returnAsNativeJsonObjects().build();
6967

7068
public UsersJsonProvider() {
7169

@@ -201,11 +199,6 @@ public WriteOptions jsonioWriteOptions() {
201199
return jsonioWriteOptions;
202200
}
203201

204-
@Override
205-
public ReadOptions jsonioReadOptionsMaps() {
206-
return jsonioReadOptionsMaps;
207-
}
208-
209202
private static final ThreadLocal<QuickbufSchema.Users> QUICKBUF_MESSAGE = ThreadLocal.withInitial(QuickbufSchema.Users::newInstance);
210203
private static final ThreadLocal<JsonSink> QUICKBUF_SINK = ThreadLocal.withInitial(() -> JsonSink.newInstance()
211204
.setPrettyPrinting(false)

src/main/java/com/github/fabienrenaud/jjb/stream/Deserialization.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.concurrent.atomic.AtomicReference;
1414

1515
import com.cedarsoftware.io.JsonIo;
16+
import com.cedarsoftware.io.JsonObject;
1617
import org.json.JSONException;
1718
import org.json.JSONObject;
1819
import org.openjdk.jmh.annotations.Benchmark;
@@ -92,12 +93,14 @@ public Object genson() throws Exception {
9293
@Benchmark
9394
@Override
9495
public Object jsonio() {
95-
// returnAsNativeJsonObjects maps to old JsonWriter.USE_MAPS=true behavior,
96-
// see {@link JsonIo#getReadOptionsBuilder(java.util.Map)} and
97-
// <a href="https://github.com/jdereg/json-io/blob/4.19.1/changelog.md">the v4.19 changelog</a>
98-
return JsonIo.toObjects(
99-
JSON_SOURCE().nextInputStream(), JSON_SOURCE().provider().jsonioReadOptionsMaps(), null
100-
);
96+
// toMaps() returns the JsonObject (Map) graph directly via MapResolver,
97+
// skipping the second-pass POJO field injection that toJava() does.
98+
// ~45% faster on JsonPerformanceTest. The API handles Maps-mode option
99+
// configuration internally via its own cache, so no options needed here.
100+
// Explicit JsonObject target keeps the result as the native lite Map
101+
// representation (the round-trip test in JsonBenchmark.test detects
102+
// JsonObject and re-serializes it for verification).
103+
return JsonIo.toMaps(JSON_SOURCE().nextInputStream()).asClass(JsonObject.class);
101104
}
102105

103106
@Benchmark

0 commit comments

Comments
 (0)