Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/qoder/cloudagents/core/JsonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,10 +127,15 @@ public List<JsonValue> asArray() {
return Collections.unmodifiableList(result);
}

@SuppressWarnings("deprecation")
public Map<String, JsonValue> asObject() {
if (!node.isObject()) throw invalid("object");
Map<String, JsonValue> result = new LinkedHashMap<>();
node.properties().forEach(entry -> result.put(entry.getKey(), new JsonValue(entry.getValue())));
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
result.put(entry.getKey(), new JsonValue(entry.getValue()));
}
return Collections.unmodifiableMap(result);
}

Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/qoder/cloudagents/core/JsonValueTest.java
Original file line number Diff line number Diff line change
@@ -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<String, JsonValue> 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());
}
}