Commit b3519d5
fix: StructType fails to deserialize JSON with type field (#1822)
This fix enables proper interoperability with Iceberg implementations
that include the type discriminator field in their JSON serialization
(such as Apache Iceberg Java).
## Which issue does this PR close?
Partially address #1749.
## What changes are included in this PR?
Fixes a bug in the `StructType` deserializer that causes JSON
deserialization to fail with the error `expected ',' or '}' at line 1
column 8`.
**Root Cause:**
The `StructType::Deserialize` implementation was not properly consuming
the `"type"` field value when deserializing JSON like:
```json
{"type":"struct","fields":[{"id":1,"name":"foo","required":true,"type":"string"}]}
```
In serde's visitor pattern, when you call `map.next_key()`, you must
call `map.next_value()` to consume the corresponding value, even if
you're discarding it. The deserializer was calling `next_key()` for the
"type" field but not consuming its value, causing the parser to remain
stuck at the value position and fail when encountering the next field.
Changes:
- Modified `StructTypeVisitor::visit_map` to properly consume the type
field value
- Added validation that the type field equals "struct"
## Are these changes tested?
Yes, two new unit tests have been added to
`crates/iceberg/src/spec/datatypes.rs`:
1. **`struct_type_with_type_field`** - Verifies that `StructType`
successfully deserializes from JSON containing the `"type":"struct"`
field. This test would fail before the fix with the error `expected ','
or '}' at line 1 column 8`
2. **`struct_type_rejects_wrong_type`** - Validates that the
deserializer properly rejects JSON with incorrect type values (e.g.,
`"type":"list"`)
---------
Co-authored-by: Renjie Liu <liurenjie2008@gmail.com>1 parent e08bc61 commit b3519d5
1 file changed
+54
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
427 | 435 | | |
428 | 436 | | |
429 | 437 | | |
| |||
1208 | 1216 | | |
1209 | 1217 | | |
1210 | 1218 | | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
1211 | 1264 | | |
0 commit comments