Skip to content

[Bug][Connector-JSON] Schema defaultValue is ignored during JSON deserialization (fields remain null) #11632

Description

@li3zhi4

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.class option value parsing so defaultValue config 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.conf

Error 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):

  1. JsonToRowConverters.convertField(...) (lines ~474-486) — for a missing field it only checks failOnMissingField and otherwise returns null; it has no Column[] metadata and never checks getDefaultValue():
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);
    }
}
  1. JsonDeserializationSchema (both constructors, lines ~82 and ~103) builds new JsonToRowConverters(failOnMissingField, ignoreParseErrors) and never passes catalogTable.getTableSchema().getColumns() to the converters.

  2. The configuration side works correctly: ReadonlyConfigParser (line ~139) reads columnConfig.get(ConnectorCommonOptions.DEFAULT_VALUE) into PhysicalColumn.of(...), and Column.getDefaultValue() exists in seatunnel-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 a Column[] columns field and a new constructor JsonToRowConverters(boolean failOnMissingField, boolean ignoreParseErrors, Column[] columns); add a convertField(converter, fieldName, field, fieldIndex) overload that consults columns[fieldIndex].getDefaultValue() when the field is missing or null, falling back to the original failOnMissingField/null behavior when no default value is configured.
  • JsonDeserializationSchema: extract Column[] from catalogTable.getTableSchema().getColumns() (with null-safety) and pass it to the new constructor.
  • New test JsonDefaultValueTest: missing field → defaultValue; explicit null → 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)

Code of Conduct

Activity

  1. DanielLeens commented on Aug 4, 2026

    @DanielLeens
    Contributor

    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 defaultValue is carried on the schema column metadata, but the current JSON deserialization path drops that metadata before JsonToRowConverters handles missing or explicit null fields, so configured defaults are never applied.

    Your proposed fix direction also looks reasonable and backward-compatible:

    1. pass column metadata into the JSON row converter;
    2. apply defaultValue when a field is missing or explicitly null;
    3. keep the current behavior unchanged when no default value is configured;
    4. cover both numeric and string defaults with focused regression tests.

    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 dev and link it here. The most important acceptance checks are:

    • missing field -> configured default value;
    • explicit JSON null -> configured default value;
    • no configured default -> existing null behavior preserved;
    • no regression for failOnMissingField / parse-error handling.

    Thanks again for writing this up so concretely.

  2. SEZ9 commented on Aug 4, 2026

    @SEZ9
    Collaborator

    Thanks for the well-researched report, including distinguishing this from the Debezium path fixed in PR #7950. Confirmed that JsonToRowConverters / JsonDeserializationSchema in seatunnel-format-json only reads the JsonNode and has no logic to fall back to Column.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 Column for a non-null defaultValue, 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 in seatunnel-format-json covering both the missing-field and explicit-null cases would be needed.

    One design point to settle before implementing: should defaultValue apply only when the field is missing, or also when the field is explicitly null in 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?

  3. li3zhi4 commented on Aug 5, 2026

    @li3zhi4
    ContributorAuthor

    @SEZ9 — thanks for confirming the bug and for the detailed suggestions. The PR is already submitted and linked from this issue (#11633, closes #11632):

    1. Design point ① (should defaultValue apply only for missing fields, or also for explicit null?): implemented per this issue's acceptance criteria — the configured default is applied for both a missing field and an explicit JSON null, and normalized to the column type by the deserializer. A nullable column without a configured default keeps returning null for explicit null (backward compatible). Both paths have unit test coverage (JsonDefaultValueTest#testDefaultValueWhenFieldMissing covers missing and explicit-null; testNoDefaultValueWhenFieldMissing covers the no-default case).

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

    3. 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 61d05f5a34 and replied to on the PR.

    Thanks again for the sharp review.

  4. DanielLeens commented on Aug 6, 2026

    @DanielLeens
    Contributor

    Thanks for linking PR #11633 and for spelling out the design choices so clearly.

    The scoping here makes sense to me:

    1. for this issue, applying defaultValue to both a missing field and an explicit JSON null is consistent with the acceptance criteria you documented;
    2. keeping the first fix limited to seatunnel-format-json is the right tradeoff for reviewability;
    3. treating the cross-format default-value gap as follow-up work avoids mixing a bug fix with a broader refactor.

    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.

  5. SEZ9 commented on Aug 22, 2026

    @SEZ9
    Collaborator

    @li3zhi4 Thanks for the point-by-point response — answering each item directly:

    1. 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 JSON null, and a nullable column without a configured default keeps returning null. Having both paths covered by JsonDefaultValueTest#testDefaultValueWhenFieldMissing and testNoDefaultValueWhenFieldMissing is exactly the regression coverage I asked for, so consider that point settled.

    2. Design point ② (shared layer for text/csv etc.): agreed with your scoping. Keeping this PR limited to seatunnel-format-json is 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.

    3. Review findings: thanks for confirming they've been addressed on 61d05f5a34 and 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:

    • the current head keeps missing-field and explicit-null behavior covered by tests;
    • no regression for the no-default case;
    • CI reaches terminal green.

    Let's keep further technical discussion on #11633; this issue stays open for tracking until the PR merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions