allow unknown struct fields

This commit is contained in:
Emil Lerch 2021-05-13 09:03:00 -07:00
parent c24ef3f3b8
commit 94266582b7
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -1590,6 +1590,21 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
}
if (!found and !options.allow_unknown_fields) return error.UnknownField;
},
.ObjectBegin => {
if (!options.allow_unknown_fields) return error.UnknownField;
// At this point, we are in a struct that we do not care about. Fast forward
var objects: u64 = 1;
while (true) {
switch ((try tokens.next()) orelse return error.UnexpectedEndOfJson) {
.ObjectBegin => objects = objects + 1,
.ObjectEnd => {
objects = objects - 1;
if (objects == 0) break;
},
else => {},
}
}
},
else => return error.UnexpectedToken,
}
}