Skip to content

refactor(serde): return Result from ToJson schema/type/metadata serializers#785

Merged
wgtmac merged 1 commit into
apache:mainfrom
huan233usc:refactor/serde-tojson-result
Jun 27, 2026
Merged

refactor(serde): return Result from ToJson schema/type/metadata serializers#785
wgtmac merged 1 commit into
apache:mainfrom
huan233usc:refactor/serde-tojson-result

Conversation

@huan233usc

Copy link
Copy Markdown
Contributor

What

Change the schema/type/metadata ToJson serializers from returning bare nlohmann::json to Result<nlohmann::json>:

  • json_serde: ToJson(SchemaField | Type | Schema | TableMetadata | TableUpdate)
  • REST: ToJson(CreateTableRequest | CommitTableRequest | LoadTableResult | CommitTableResponse)

Errors propagate via ICEBERG_ASSIGN_OR_RAISE; callers bottom out at the existing Result-returning boundaries (ToJsonString, rest_catalog, TableMetadataUtil::Write).

Why

Preparation for v3 column default values (#730 / #746). Single-value (Literal) serialization is fallible, and column defaults invoke it from schema serialization, so these serializers need to propagate the error instead of throwing. Splitting it out keeps the feature PR focused on the feature.

Notes

  • No behavior change — every conversion still succeeds today; only the return type changes.
  • The shared ToJsonList template stays bare (it also serializes infallible types such as partition specs and snapshots); TableMetadata serializes its schema list with an explicit loop.
  • The REST ICEBERG_DECLARE_JSON_SERDE macro is unchanged; the four schema/metadata-bearing models are declared explicitly so only their ToJson return type differs.

Testing

No behavior change; existing tests are adapted to the new return type. Full build and ctest pass locally.

…lizers

Single-value (Literal) serialization can fail, and upcoming v3 column default
values (apache#730) invoke it from schema serialization. Switch the schema/type/metadata
ToJson serializers (and the REST request/response serializers that embed them) from
returning bare nlohmann::json to Result<nlohmann::json>, propagating errors via
ICEBERG_ASSIGN_OR_RAISE instead of forcing callers to throw.

Behavior is unchanged: every conversion still succeeds today; this only changes the
return type so the column-defaults PR can serialize default values without throwing.

- ToJson for SchemaField/Type/Schema/TableMetadata/TableUpdate, plus REST
  CreateTableRequest/CommitTableRequest/LoadTableResult/CommitTableResponse.
- The shared ToJsonList template stays bare (also used by infallible types);
  TableMetadata serializes its schema list with an explicit loop.
- Callers bottom out at existing Result boundaries (ToJsonString wrappers,
  rest_catalog.cc, TableMetadataUtil::Write).
@wgtmac wgtmac merged commit 90a2be7 into apache:main Jun 27, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants