File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1216,4 +1216,49 @@ mod tests {
12161216 assert ! ( ty. compatible( & literal) ) ;
12171217 }
12181218 }
1219+
1220+ #[ test]
1221+ fn struct_type_with_type_field ( ) {
1222+ // Test that StructType properly deserializes JSON with "type":"struct" field
1223+ // This was previously broken because the deserializer wasn't consuming the type field value
1224+ let json = r#"
1225+ {
1226+ "type": "struct",
1227+ "fields": [
1228+ {"id": 1, "name": "field1", "required": true, "type": "string"}
1229+ ]
1230+ }
1231+ "# ;
1232+
1233+ let struct_type: StructType = serde_json:: from_str ( json)
1234+ . expect ( "Should successfully deserialize StructType with type field" ) ;
1235+
1236+ assert_eq ! ( struct_type. fields( ) . len( ) , 1 ) ;
1237+ assert_eq ! ( struct_type. fields( ) [ 0 ] . name, "field1" ) ;
1238+ }
1239+
1240+ #[ test]
1241+ fn struct_type_rejects_wrong_type ( ) {
1242+ // Test that StructType validation rejects incorrect type field values
1243+ let json = r#"
1244+ {
1245+ "type": "list",
1246+ "fields": [
1247+ {"id": 1, "name": "field1", "required": true, "type": "string"}
1248+ ]
1249+ }
1250+ "# ;
1251+
1252+ let result = serde_json:: from_str :: < StructType > ( json) ;
1253+ assert ! (
1254+ result. is_err( ) ,
1255+ "Should reject StructType with wrong type field"
1256+ ) ;
1257+ assert ! (
1258+ result
1259+ . unwrap_err( )
1260+ . to_string( )
1261+ . contains( "expected type 'struct'" )
1262+ ) ;
1263+ }
12191264}
You can’t perform that action at this time.
0 commit comments