Skip to content

Commit 75685cd

Browse files
authored
schema-based parsing: fix handling non-existent fields in schema (#51)
1 parent 3c43857 commit 75685cd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/org/simdjson/ConstructorArgumentsMap.java

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ ConstructorArgument get(byte[] buffer, int len) {
5151
int place = findPlace(buffer, len);
5252
for (int i = 0; i < capacity; i++) {
5353
byte[] key = keys[place];
54+
if (key == null) {
55+
return null;
56+
}
5457
if (Arrays.equals(key, 0, key.length, buffer, 0, len)) {
5558
return arguments[place];
5659
}

src/test/java/org/simdjson/ObjectSchemaBasedParsingTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,25 @@ public void listsWithoutElementTypeAreNotSupported() {
642642
.hasMessage("Undefined list element type.");
643643
}
644644

645+
@Test
646+
public void issue50() {
647+
// given
648+
SimdJsonParser parser = new SimdJsonParser();
649+
byte[] json = toUtf8("{\"name\": \"John\", \"age\": 30, \"aaa\": 1, \"bbb\": 2, \"ccc\": 3}");
650+
651+
// when
652+
Issue50 object = parser.parse(json, json.length, Issue50.class);
653+
654+
// then
655+
assertThat(object.aaa()).isEqualTo(1);
656+
assertThat(object.bbb()).isEqualTo(2);
657+
assertThat(object.ccc()).isEqualTo(3);
658+
}
659+
660+
private record Issue50(long aaa, long bbb, long ccc) {
661+
662+
}
663+
645664
private record RecordWithExplicitFieldNames(@JsonFieldName("ąćśńźż") long firstField,
646665
@JsonFieldName("\u20A9\u0E3F") long secondField,
647666
@JsonFieldName("αβγ") long thirdField,

0 commit comments

Comments
 (0)