Browse Source

Merge pull request #2099 from Skytrias/skytrias-json-unused-field

allow json struct unused fields
gingerBill 2 years ago
parent
commit
775c9648f9
1 changed files with 7 additions and 9 deletions
  1. 7 9
      core/encoding/json/unmarshal.odin

+ 7 - 9
core/encoding/json/unmarshal.odin

@@ -380,20 +380,18 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
 				field := any{field_ptr, type.id}
 				unmarshal_value(p, field) or_return
 					
+				if parse_comma(p) {
+					break struct_loop
+				}
+				continue struct_loop
+			} else {
+				// allows skipping unused struct fields
+				parse_value(p) or_return
 				if parse_comma(p) {
 					break struct_loop
 				}
 				continue struct_loop
 			}
-			
-			// NOTE(bill, 2022-09-14): Previously this would not be allowed
-			//         {"foo": 123, "bar": 456}
-			//         T :: struct{foo: int}
-			// `T` is missing the `bar` field
-			// The line below is commented out to ignore fields in an object which
-			// do not have a corresponding target field
-			//
-			// return Unsupported_Type_Error{v.id, p.curr_token}
 		}
 		
 	case reflect.Type_Info_Map: