Aias00 opened a new issue, #7480:
URL: https://github.com/apache/shenyu/issues/7480
## Description
AI request transformation accepts a valid generated JSON array, but replaces
the downstream request body with literal JSON `null`.
extractJsonBodyFromHttpResponse explicitly accepts both object and array
delimiters, then always calls GsonUtils.convertToMap. The custom map adapter
returns null for a non-object root. Serializing that Map result produces the
four-byte JSON text `null`, discarding the generated array.
## Expected Behavior
For application/json, preserve any supported valid JSON root, including
arrays. The request template already accepts an original array as a JsonNode
and instructs the model to produce valid JSON text, not only JSON objects.
## Reproduction
The isolated verifier executed actual AiRequestTransformerPlugin.doExecute
with original array JSON and a mocked ChatClient stream. Object generated
output worked; array generated output became null:
```text
objectControl.promptContainsOriginalArray=true
objectControl.executed=true
objectControl.body={"generated":"object"}
arrayCase.promptContainsOriginalArray=true
arrayCase.executed=true
arrayCase.body=null
staticArrayExtract=null
```
The array fixture returns `[{"generated":"array"}]` in a normal HTTP
request-shaped model response. The harness asserts the actual downstream body
equals the String `null`; this is not a Java null reference and is not the
fallback path.
## Location
-
[AiRequestTransformerPlugin.java:199](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/AiRequestTransformerPlugin.java#L199):
recognizes an array then forces Map conversion.
-
[GsonUtils.java:343](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-common/src/main/java/org/apache/shenyu/common/utils/GsonUtils.java#L343):
custom object/map deserialization discards non-object roots.
-
[AiRequestTransformerTemplate.java:169](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/template/AiRequestTransformerTemplate.java#L169):
original JSON is parsed as a generic JsonNode.
## Impact
Severity: Medium. Confidence: high. A valid model-generated batch/array
request loses its data and forwards null to the backend instead of the
transformed records.
## Suggested Fix And Tests
Validate/serialize JSON bodies as generic JSON rather than forcing
Map<String,Object>. Preserve arrays and other roots permitted by the
transformation contract. Keep object-only conversion separate for form encoding.
Test original-array input with generated-array output, object output
control, empty arrays and nested data through doExecute. Assert the downstream
body rather than only helper recognition.
## Validation And Deduplication
Reviewed apache/shenyu master a89b6a2338c24e978428b731e8f1edce86022418. The
current pipeline was run using local production classes and a mocked model; no
external AI/backend request was made. Harness assertions exited 0.
#7459/#7460 concern request target/query/context rewriting, not JSON body
root serialization. Existing transformer buffering/cache issues do not cover
arrays being converted to literal null. No matching issue or pending PR was
found.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]