Skip to content

Commit 5aa06f0

Browse files
committed
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
1 parent 3ebc361 commit 5aa06f0

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
### Fixed
2020

21+
- 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).
2122
- 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.
2223
- Preserve Forward multiagent string references when decoding a Template or Session override; typed roster access no longer rejects valid string entries.
2324
- 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.

‎src/main/java/com/qoder/cloudagents/core/JsonValue.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.math.BigDecimal;
99
import java.util.ArrayList;
1010
import java.util.Collections;
11+
import java.util.Iterator;
1112
import java.util.LinkedHashMap;
1213
import java.util.List;
1314
import java.util.Map;
@@ -126,10 +127,15 @@ public List<JsonValue> asArray() {
126127
return Collections.unmodifiableList(result);
127128
}
128129

130+
@SuppressWarnings("deprecation")
129131
public Map<String, JsonValue> asObject() {
130132
if (!node.isObject()) throw invalid("object");
131133
Map<String, JsonValue> result = new LinkedHashMap<>();
132-
node.properties().forEach(entry -> result.put(entry.getKey(), new JsonValue(entry.getValue())));
134+
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
135+
while (fields.hasNext()) {
136+
Map.Entry<String, JsonNode> entry = fields.next();
137+
result.put(entry.getKey(), new JsonValue(entry.getValue()));
138+
}
133139
return Collections.unmodifiableMap(result);
134140
}
135141

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.qoder.cloudagents.core;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
6+
import com.qoder.cloudagents.errors.ResponseValidationException;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.Map;
10+
import org.junit.jupiter.api.Test;
11+
12+
final class JsonValueTest {
13+
@Test
14+
void asObjectPreservesFieldOrderAndReturnsUnmodifiableMap() {
15+
JsonValue value = JsonValue.parse("{\"second\":2,\"first\":\"one\",\"nested\":{\"ok\":true}}");
16+
Map<String, JsonValue> object = value.asObject();
17+
18+
assertEquals(Arrays.asList("second", "first", "nested"), new ArrayList<>(object.keySet()));
19+
assertEquals(2L, object.get("second").asLong());
20+
assertEquals("one", object.get("first").asString());
21+
assertEquals(true, object.get("nested").asObject().get("ok").asBoolean());
22+
assertThrows(
23+
UnsupportedOperationException.class, () -> object.put("extra", JsonValue.of("nope")));
24+
}
25+
26+
@Test
27+
void asObjectRejectsNonObjectValues() {
28+
assertThrows(ResponseValidationException.class, () -> JsonValue.parse("[1,2]").asObject());
29+
assertThrows(ResponseValidationException.class, () -> JsonValue.of("text").asObject());
30+
}
31+
}

0 commit comments

Comments
 (0)