소스 검색

Allow for ignored fields in struct for `json.unmarshal`

gingerBill 2 년 전
부모
커밋
db1b7b2d21
1개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      core/encoding/json/unmarshal.odin

+ 8 - 1
core/encoding/json/unmarshal.odin

@@ -386,7 +386,14 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
 				continue struct_loop
 			}
 			
-			return Unsupported_Type_Error{v.id, p.curr_token}
+			// 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: