Repository navigation
Description
Search before asking
- I had searched in the issues and found related but different-root-cause reports:
- #8759 — Oracle CDC → Kafka: Debezium struct default value used when column is null (Debezium deserialization path).
- PR #7950 — fixed the Debezium path via
struct.getWithoutDefault(...); the JSON format deserializer (seatunnel-format-json) is a separate code path and was NOT touched. - PR #6247 — fixed
Object.classoption value parsing sodefaultValueconfig can be read correctly. - No existing issue reports the JSON format deserializer ignoring
schema.columns[].defaultValue.
What happened
When a source connector using the JSON format (Kafka, Pulsar, HTTP, MongoDB, Elasticsearch, …) configures schema { columns = [ { name = "GROUPID", type = "int", nullable = false, defaultValue = 0 } ] }, the defaultValue is parsed and stored on the Column but never applied during deserialization: if the JSON message is missing the field or contains an explicit null, the row field stays null instead of the configured default value.
Expected: defaultValue = 0 is used when the JSON field is missing or null.
Actual: the field is null; the defaultValue config is silently ignored.
SeaTunnel Version
2.3.13 (verified locally). Also reproducible on current upstream dev (checked 2026-08-03, 6bf786bee7).
SeaTunnel Config
source {
Kafka {
bootstrap.servers = "localhost:9092"
topic = "test"
format = json
schema {
columns = [
{ name = "GROUPID", type = "int", nullable = false, defaultValue = 0 }
{ name = "name", type = "string", nullable = false, defaultValue = "unknown" }
]
}
}
}
sink {
Console {}
}Running Command
./bin/seatunnel.sh --config ./config/xxx.confError Exception
No error. The job runs, but fields configured with defaultValue come out as null when the JSON message omits them or sets them to null — a silent data-integrity bug.
Root cause (confirmed by code inspection on upstream dev)
The defaultValue is lost on the way from CatalogTable to the row converter:
CatalogTable (contains Column metadata incl. defaultValue)
↓ getSeaTunnelRowType()
SeaTunnelRowType (fieldNames[] + fieldTypes[] only) ← defaultValue dropped here
↓
JsonToRowConverters (no access to Column[] / defaultValue)
↓
convertField(): field == null → returns null (defaultValue never consulted)
Concretely, on upstream dev (same as 2.3.13):
JsonToRowConverters.convertField(...)(lines ~474-486) — for a missing field it only checksfailOnMissingFieldand otherwise returnsnull; it has noColumn[]metadata and never checksgetDefaultValue():
private Object convertField(
JsonToObjectConverter fieldConverter, String fieldName, JsonNode field) {
if (field == null) {
if (failOnMissingField) {
throw new IllegalArgumentException(...);
} else {
return null; // defaultValue never applied
}
} else {
return fieldConverter.convert(field, fieldName);
}
}-
JsonDeserializationSchema(both constructors, lines ~82 and ~103) buildsnew JsonToRowConverters(failOnMissingField, ignoreParseErrors)and never passescatalogTable.getTableSchema().getColumns()to the converters. -
The configuration side works correctly:
ReadonlyConfigParser(line ~139) readscolumnConfig.get(ConnectorCommonOptions.DEFAULT_VALUE)intoPhysicalColumn.of(...), andColumn.getDefaultValue()exists inseatunnel-api. The API contract explicitly supports default values — the deserialization side just never uses them.
Proposed fix (implemented & verified locally on 2.3.13)
Minimal, backward-compatible, root-cause fix:
JsonToRowConverters: add aColumn[] columnsfield and a new constructorJsonToRowConverters(boolean failOnMissingField, boolean ignoreParseErrors, Column[] columns); add aconvertField(converter, fieldName, field, fieldIndex)overload that consultscolumns[fieldIndex].getDefaultValue()when the field is missing ornull, falling back to the originalfailOnMissingField/nullbehavior when no default value is configured.JsonDeserializationSchema: extractColumn[]fromcatalogTable.getTableSchema().getColumns()(with null-safety) and pass it to the new constructor.- New test
JsonDefaultValueTest: missing field → defaultValue; explicitnull→ defaultValue; no defaultValue →null(backward compatibility); string-typed default values.
Verification on 2.3.13: 3 new unit tests + full seatunnel-format-json module (46 tests) all pass; spotless:apply clean.
Zeta or Flink or Spark Version
zeta (format module is engine-agnostic; affects all of them)
Java or Scala Version
Java 8 / 11 (both OK)
Screenshots
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR! (fix already implemented and verified locally; will port to
dev)
Activity
DanielLeens commentedon Aug 4, 2026
Thanks for the very complete report and for separating this from the earlier Debezium-specific default-value fix.
I checked the JSON format path you described, and this does look like a real bug rather than a usage problem. The
defaultValueis carried on the schema column metadata, but the current JSON deserialization path drops that metadata beforeJsonToRowConvertershandles missing or explicitnullfields, so configured defaults are never applied.Your proposed fix direction also looks reasonable and backward-compatible:
defaultValuewhen a field is missing or explicitlynull;Since you marked that you are willing to submit a PR, I've assigned the issue to you. Please feel free to open the PR against
devand link it here. The most important acceptance checks are:null-> configured default value;nullbehavior preserved;failOnMissingField/ parse-error handling.Thanks again for writing this up so concretely.
SEZ9 commentedon Aug 4, 2026
Thanks for the well-researched report, including distinguishing this from the Debezium path fixed in PR #7950. Confirmed that
JsonToRowConverters/JsonDeserializationSchemainseatunnel-format-jsononly reads the JsonNode and has no logic to fall back toColumn.getDefaultValue()when the node is missing or null, so the config is silently ignored.Suggested fix direction: in the JSON row converter, when the field node is absent or NullNode, check the corresponding
Columnfor a non-nulldefaultValue, convert it to the column's SeaTunnel data type, and use it instead of null. This should be gated so explicit nulls on nullable columns without a default still yield null. A unit test inseatunnel-format-jsoncovering both the missing-field and explicit-null cases would be needed.One design point to settle before implementing: should
defaultValueapply only when the field is missing, or also when the field is explicitlynullin the payload (as this issue expects)? Also note other formats (e.g., text/csv) may have the same gap — worth checking whether the fix should live in a shared layer rather than per-format. Would you be willing to submit a PR?li3zhi4 commentedon Aug 5, 2026
@SEZ9 — thanks for confirming the bug and for the detailed suggestions. The PR is already submitted and linked from this issue (#11633, closes #11632):
Design point ① (should
defaultValueapply only for missing fields, or also for explicitnull?): implemented per this issue's acceptance criteria — the configured default is applied for both a missing field and an explicit JSONnull, and normalized to the column type by the deserializer. A nullable column without a configured default keeps returningnullfor explicitnull(backward compatible). Both paths have unit test coverage (JsonDefaultValueTest#testDefaultValueWhenFieldMissingcovers missing and explicit-null;testNoDefaultValueWhenFieldMissingcovers the no-default case).Design point ② (text/csv etc. may have the same gap — should the fix live in a shared layer?): agreed this is a shared gap. This PR deliberately scopes to the JSON format (
seatunnel-format-json) to keep the change reviewable; a follow-up for the other formats (text/csv/…) would be better tracked in a separate issue so this PR stays single-purpose.Your review findings on the PR (nested-ROW scoping, shared mutable defaults for ARRAY/MAP/BYTES, test coverage for unconvertible defaults, e2e ordering) have all been addressed on the current head
61d05f5a34and replied to on the PR.Thanks again for the sharp review.
DanielLeens commentedon Aug 6, 2026
Thanks for linking PR #11633 and for spelling out the design choices so clearly.
The scoping here makes sense to me:
defaultValueto both a missing field and an explicit JSONnullis consistent with the acceptance criteria you documented;seatunnel-format-jsonis the right tradeoff for reviewability;The issue can stay open for tracking, but the technical discussion should now continue primarily on PR #11633. From the issue side, the remaining acceptance bar is straightforward: the current PR head needs to keep the missing-field and explicit-null behavior covered, avoid regressions for the no-default case, and reach terminal green CI before we treat this as resolved.
SEZ9 commentedon Aug 22, 2026
@li3zhi4 Thanks for the point-by-point response — answering each item directly:
Design point ① (missing field vs. explicit
null): your implementation choice matches the acceptance criteria we agreed on in this issue — the configured default applies to both a missing field and an explicit JSONnull, and a nullable column without a configured default keeps returningnull. Having both paths covered byJsonDefaultValueTest#testDefaultValueWhenFieldMissingandtestNoDefaultValueWhenFieldMissingis exactly the regression coverage I asked for, so consider that point settled.Design point ② (shared layer for text/csv etc.): agreed with your scoping. Keeping this PR limited to
seatunnel-format-jsonis the right tradeoff for reviewability, and tracking the other formats in a separate follow-up issue keeps this fix single-purpose. One concrete ask here: please open that follow-up issue (or let me know if you'd like me to file it) so the cross-format gap doesn't get lost once this closes.Review findings: thanks for confirming they've been addressed on
61d05f5a34and replied to on the PR. I'll verify the responses on the PR side rather than re-litigating them here.Remaining before we treat this issue as resolved, all on PR #11633:
Let's keep further technical discussion on #11633; this issue stays open for tracking until the PR merges.