hutiefang76 opened a new pull request, #12962:
URL: https://github.com/apache/seatunnel/pull/12962

   ### Purpose of this pull request
   
   Yes, I am contributing this fix to Apache SeaTunnel.
   
   Fixes #12961.
   
   The JSON ARRAY and MAP converters currently iterate any JSON node without 
checking its container type. As a result, an ARRAY field containing a string, 
number or boolean silently becomes an empty array; an object becomes an array 
of nulls. A MAP field containing a scalar or an array silently becomes an empty 
map. This happens even when parse errors are not ignored and can silently 
discard source data.
   
   Validate the node shape before iterating it. ARRAY requires an array and MAP 
requires an object. The resulting parse exception names the field and expected 
container type and follows the existing error-handling wrappers. No dependency 
or configuration option is added.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Malformed container values now fail deserialization in strict mode. 
With `ignore-parse-errors = true`, only the malformed value becomes null. For a 
malformed nested value, valid siblings and the enclosing collection remain 
intact.
   
   For example, with `arr` declared as ARRAY<INT>, `{"id":7,"arr":42}` 
previously produced an empty array. It now reports a parse error, or yields 
`id=7, arr=null` when errors are ignored. Valid empty containers, null/missing 
fields, element and key conversions, and positional ROW arrays retain their 
existing behavior.
   
   English and Chinese compatibility notes explain the change and migration 
options: supply the declared JSON container type, or enable ignored parse 
errors to obtain null for malformed values.
   
   ### How was this patch tested?
   
   Locally on macOS ARM64 with JDK 17.0.18, against dev commit 
`6b63aca173eb8c056db0b78a87539aec3e4ad1a5`:
   
   - Before changing production code, the public-schema regression run had 31 
tests with 4 failing new test methods, covering 16 malformed input/mode 
assertions. Existing and valid-input controls passed.
   - Added seven tests in the existing schema test class. They cover 
strict/ignored-error ARRAY and MAP inputs through both String and byte entry 
points, field/type error context, valid empty/nonempty/nullable containers, 
numeric-string coercion, and nested-value containment.
   - `./mvnw -B -pl seatunnel-formats/seatunnel-format-json -am package`: 566 
tests passed, including all 62 JSON-format tests, with no failures, errors or 
skips.
   - `./mvnw spotless:apply`: passed; a second format run left the patch 
unchanged.
   - `./mvnw -q -DskipTests verify`: passed (tests deliberately skipped in this 
build check).
   
   These are local Java format-module results; upstream CI remains pending.
   
   AI assistance: Codex and DeepSeek assisted the investigation, patch, tests 
and review. The submitted diff and actual test reports were checked before 
submission.
   
   ### Check list
   
   * [x] No new Jar binary package or dependency is added.
   * [x] User-facing behavior and migration guidance are documented in English 
and Chinese.
   * [x] Both `incompatible-changes.md` files are updated.
   * [x] Connector registration changes are not applicable to this format-only 
patch.
   


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