@@ -38,23 +38,16 @@ namespace iceberg::rest {
3838template <typename Model>
3939Result<Model> FromJson (const nlohmann::json& json);
4040
41- #define ICEBERG_DECLARE_JSON_SERDE (Model ) \
41+ // Declares the two FromJson entry points for a model.
42+ #define ICEBERG_DECLARE_FROM_JSON (Model ) \
4243 ICEBERG_REST_EXPORT Result<Model> Model##FromJson(const nlohmann::json& json); \
4344 \
4445 template <> \
45- ICEBERG_REST_EXPORT Result<Model> FromJson (const nlohmann::json& json); \
46- \
47- ICEBERG_REST_EXPORT nlohmann::json ToJson (const Model& model);
46+ ICEBERG_REST_EXPORT Result<Model> FromJson (const nlohmann::json& json);
4847
49- // Same as ICEBERG_DECLARE_JSON_SERDE, but ToJson returns Result because the model
50- // embeds a Schema/TableMetadata whose default-value serialization can fail.
51- #define ICEBERG_DECLARE_JSON_SERDE_FALLIBLE (Model ) \
52- ICEBERG_REST_EXPORT Result<Model> Model##FromJson(const nlohmann::json& json); \
53- \
54- template <> \
55- ICEBERG_REST_EXPORT Result<Model> FromJson (const nlohmann::json& json); \
56- \
57- ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson (const Model& model);
48+ #define ICEBERG_DECLARE_JSON_SERDE (Model ) \
49+ ICEBERG_DECLARE_FROM_JSON (Model) \
50+ ICEBERG_REST_EXPORT nlohmann::json ToJson (const Model& model);
5851
5952// / \note Don't forget to add `ICEBERG_DEFINE_FROM_JSON` to the end of
6053// / `json_internal.cc` to define the `FromJson` function for the model.
@@ -67,16 +60,23 @@ ICEBERG_DECLARE_JSON_SERDE(GetNamespaceResponse)
6760ICEBERG_DECLARE_JSON_SERDE (UpdateNamespacePropertiesRequest)
6861ICEBERG_DECLARE_JSON_SERDE (UpdateNamespacePropertiesResponse)
6962ICEBERG_DECLARE_JSON_SERDE (ListTablesResponse)
70- ICEBERG_DECLARE_JSON_SERDE_FALLIBLE (LoadTableResult)
7163ICEBERG_DECLARE_JSON_SERDE (RegisterTableRequest)
7264ICEBERG_DECLARE_JSON_SERDE (RenameTableRequest)
73- ICEBERG_DECLARE_JSON_SERDE_FALLIBLE (CreateTableRequest)
74- ICEBERG_DECLARE_JSON_SERDE_FALLIBLE (CommitTableRequest)
75- ICEBERG_DECLARE_JSON_SERDE_FALLIBLE (CommitTableResponse)
7665ICEBERG_DECLARE_JSON_SERDE (OAuthTokenResponse)
7766
67+ // These models embed a Schema/TableMetadata whose default-value serialization can
68+ // fail, so their ToJson returns Result; FromJson is declared like the others.
69+ ICEBERG_DECLARE_FROM_JSON (LoadTableResult)
70+ ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson (const LoadTableResult& model);
71+ ICEBERG_DECLARE_FROM_JSON (CreateTableRequest)
72+ ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson (const CreateTableRequest& model);
73+ ICEBERG_DECLARE_FROM_JSON (CommitTableRequest)
74+ ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson (const CommitTableRequest& model);
75+ ICEBERG_DECLARE_FROM_JSON (CommitTableResponse)
76+ ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson (const CommitTableResponse& model);
77+
78+ #undef ICEBERG_DECLARE_FROM_JSON
7879#undef ICEBERG_DECLARE_JSON_SERDE
79- #undef ICEBERG_DECLARE_JSON_SERDE_FALLIBLE
8080
8181ICEBERG_REST_EXPORT Result<PlanTableScanResponse> PlanTableScanResponseFromJson (
8282 const nlohmann::json& json,
0 commit comments