lymerin opened a new pull request, #7486:
URL: https://github.com/apache/shenyu/pull/7486

   Fixes #7480
   
   ### Problem
   
   `AiRequestTransformerPlugin.extractJsonBodyFromHttpResponse()` accepts JSON 
object and array bodies but always converts them through 
`GsonUtils.convertToMap()`.
   
   The custom Map deserializer returns Java `null` for an array root. 
Serializing that result produces literal JSON `null`, discarding the generated 
array without raising an exception.
   
   ### Impact
   
   Valid generated arrays, including empty and nested arrays, are forwarded to 
the backend as literal JSON `null`.
   
   The same conversion also changes numbers and booleans inside object arrays 
into strings, drops explicit null-valued object fields, and throws 
`IllegalStateException` for objects containing nested arrays such as 
`{"a":[[1,2]]}`.
   
   ### Changes
   
   - Parse the extracted body as a generic `JsonElement` and return the 
extracted JSON text unchanged.
   - Follow the existing validate-and-return approach in 
[[AiResponseTransformerPlugin.java:223-231](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java#L223-L231)](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java#L223-L231),
 aligning JSON body preservation between the request and response transformers.
   - Preserve internal whitespace and line breaks instead of reserializing the 
body as compact JSON. Existing surrounding whitespace trimming and LF 
normalization remain unchanged.
   - Keep the existing object and array root checks and JSON parsing behavior, 
with object conversion retained for form encoding.
   - Replace the existing valid-configuration test with four regression cases 
that execute `doExecute` using an original array request and verify the actual 
downstream body.
   - Cover nested arrays under both array and object roots, numbers, booleans, 
nulls, empty arrays, and a multiline object output control.
   - Replace the redundant object-only helper test with a malformed JSON test 
and add a form encoding test.
   
   ### Validation
   
   - All four regression cases failed before the fix and passed after the fix.
   - All 20 module tests passed, with no failures or errors.
   - Checkstyle reported 0 violations, and Apache RAT passed.
   - The full local `clean install` build previously passed.
   
   ### Checklist
   
   - [x] You have read the [[contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide)](https://shenyu.apache.org/community/contributor-guide).
   - [x] You submit test cases (unit or integration tests) that back your 
changes.
   - [x] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.


-- 
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]

Reply via email to