corgy-w opened a new pull request, #12064:
URL: https://github.com/apache/seatunnel/pull/12064
### Purpose of this pull request
Fixes the issue that an explicit `NULL` value in a Debezium `SourceRecord`
is silently replaced by the field's schema default when serialized with the
`COMPATIBLE_DEBEZIUM_JSON` format.
`DebeziumJsonConverter` previously invoked Kafka Connect's `JsonConverter`
through reflection. Kafka Connect's `Struct#get` falls back to the field schema
default, so a raw `NULL`, e.g. a nullable MySQL DECIMAL column with `DEFAULT
'0.0000'`, was emitted as `0.0000` instead of JSON `null`.
This PR mirrors the `toJson` path of Kafka Connect's `JsonConverter`
(3.9.0): `convertToJson`,
`convertToJsonWithEnvelope`/`convertToJsonWithoutEnvelope`, `asJsonSchema` and
the logical type converters. Struct fields are read with
`Struct#getWithoutDefault` (upstream 3.9.0 fix) so an explicit `NULL` stays
JSON `null`, and `replace.null.with.default` is hard-wired to `false` for the
top-level null. Schema metadata, including defaults, is still preserved in the
schema envelope when schemas are enabled. The reflection-based access to
`JsonConverter` private methods is removed.
### Does this PR introduce _any_ user-facing change?
Yes. With the `COMPATIBLE_DEBEZIUM_JSON` format, a NULL field whose schema
carries a default is now serialized as JSON `null` instead of the default value:
- Before: `{"reg_capital":0.0000}`
- After: `{"reg_capital":null}`
A real value keeps its original scale, e.g. `{"reg_capital":116161.5000}`.
Schema metadata (including defaults) is unchanged when schema envelopes are
enabled.
### How was this patch tested?
1. Unit tests:
```bash
./mvnw -pl seatunnel-formats/seatunnel-format-compatible-debezium-json test
```
Result: `Tests run: 10, Failures: 0, Errors: 0, Skipped: 0` (8 in
`TestDebeziumJsonConverter`, including new cases for NULL, zero, non-zero
decimals, key, envelope and mixed fields, plus the preserved existing tests).
2. Code style:
```bash
./mvnw -pl seatunnel-formats/seatunnel-format-compatible-debezium-json
spotless:check
```
Result: passed (JDK 17, since spotless 2.29.0 is incompatible with the JDK
21 default toolchain).
### Check list
* [x] If any new Jar binary package adding in your PR, please add License
Notice according
[New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
* [ ] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this PR.
* [ ] If you are contributing the connector code, please check that the
following files are updated:
1. Update
[plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties)
and add new connector information in it
2. Update the pom file of
[seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
3. Add ci label in
[label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
4. Add e2e testcase in
[seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
5. Update connector
[plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
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]