From 5aa06f027b625865368ca7e2c4cc61b4e9461ffa Mon Sep 17 00:00:00 2001 From: Aibu <29893417+wssab314@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:15:14 +0800 Subject: [PATCH] fix(core): use Jackson 2.x-compatible JsonNode.fields() in JsonValue.asObject() Replace Jackson 2.19+ JsonNode.properties() in JsonValue.asObject() with JsonNode.fields() so applications pinned to Jackson 2.13-2.18 (such as Spring Boot 2.x and 3.0-3.4) do not fail with NoSuchMethodError at runtime. Fixes #18 --- CHANGELOG.md | 1 + .../com/qoder/cloudagents/core/JsonValue.java | 8 ++++- .../qoder/cloudagents/core/JsonValueTest.java | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/qoder/cloudagents/core/JsonValueTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f30a5e..ce4112f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Fixed +- Use Jackson 2.x-compatible `JsonNode.fields()` in `JsonValue.asObject()` instead of Jackson 2.19+ `JsonNode.properties()`, preventing `NoSuchMethodError` crashes in applications pinned to Jackson 2.13–2.18 (such as Spring Boot 2.x and 3.0–3.4). - Cancel active Skill and File downloads before releasing their response bodies, and defer body closure until in-flight reads exit. Closing a client during a blocked download read now raises the SDK abort error instead of an Okio `Unbalanced enter/exit` exception. - Preserve Forward multiagent string references when decoding a Template or Session override; typed roster access no longer rejects valid string entries. - Send the required `scope: by_schedule_ids` in Forward `schedules().archiveMany(...)`. Earlier releases sent only `schedule_ids`, so every batch archive request was rejected with HTTP 400 `invalid_request`; existing calls work without code changes. diff --git a/src/main/java/com/qoder/cloudagents/core/JsonValue.java b/src/main/java/com/qoder/cloudagents/core/JsonValue.java index d17b9fa..7dc6188 100644 --- a/src/main/java/com/qoder/cloudagents/core/JsonValue.java +++ b/src/main/java/com/qoder/cloudagents/core/JsonValue.java @@ -8,6 +8,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -126,10 +127,15 @@ public List asArray() { return Collections.unmodifiableList(result); } + @SuppressWarnings("deprecation") public Map asObject() { if (!node.isObject()) throw invalid("object"); Map result = new LinkedHashMap<>(); - node.properties().forEach(entry -> result.put(entry.getKey(), new JsonValue(entry.getValue()))); + Iterator> fields = node.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + result.put(entry.getKey(), new JsonValue(entry.getValue())); + } return Collections.unmodifiableMap(result); } diff --git a/src/test/java/com/qoder/cloudagents/core/JsonValueTest.java b/src/test/java/com/qoder/cloudagents/core/JsonValueTest.java new file mode 100644 index 0000000..3f684f9 --- /dev/null +++ b/src/test/java/com/qoder/cloudagents/core/JsonValueTest.java @@ -0,0 +1,31 @@ +package com.qoder.cloudagents.core; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.qoder.cloudagents.errors.ResponseValidationException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import org.junit.jupiter.api.Test; + +final class JsonValueTest { + @Test + void asObjectPreservesFieldOrderAndReturnsUnmodifiableMap() { + JsonValue value = JsonValue.parse("{\"second\":2,\"first\":\"one\",\"nested\":{\"ok\":true}}"); + Map object = value.asObject(); + + assertEquals(Arrays.asList("second", "first", "nested"), new ArrayList<>(object.keySet())); + assertEquals(2L, object.get("second").asLong()); + assertEquals("one", object.get("first").asString()); + assertEquals(true, object.get("nested").asObject().get("ok").asBoolean()); + assertThrows( + UnsupportedOperationException.class, () -> object.put("extra", JsonValue.of("nope"))); + } + + @Test + void asObjectRejectsNonObjectValues() { + assertThrows(ResponseValidationException.class, () -> JsonValue.parse("[1,2]").asObject()); + assertThrows(ResponseValidationException.class, () -> JsonValue.of("text").asObject()); + } +}