Skip to content

Commit

Permalink
schema-based parsing: fix handling non-existent fields in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrrzysko committed May 22, 2024
1 parent 3c43857 commit 2c1e099
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/simdjson/ConstructorArgumentsMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ConstructorArgument get(byte[] buffer, int len) {
int place = findPlace(buffer, len);
for (int i = 0; i < capacity; i++) {
byte[] key = keys[place];
if (key == null) {
return null;
}
if (Arrays.equals(key, 0, key.length, buffer, 0, len)) {
return arguments[place];
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/simdjson/ObjectSchemaBasedParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ public void listsWithoutElementTypeAreNotSupported() {
.hasMessage("Undefined list element type.");
}

@Test
public void issue50() {
// given
SimdJsonParser parser = new SimdJsonParser();
byte[] json = toUtf8("{\"name\": \"John\", \"age\": 30, \"aaa\": 1, \"bbb\": 2, \"ccc\": 3}");

// when
Issue50 object = parser.parse(json, json.length, Issue50.class);

// then
assertThat(object.aaa()).isEqualTo(1);
assertThat(object.bbb()).isEqualTo(2);
assertThat(object.ccc()).isEqualTo(3);
}

private record Issue50(long aaa, long bbb, long ccc) {

}

private record RecordWithExplicitFieldNames(@JsonFieldName("ąćśńźż") long firstField,
@JsonFieldName("\u20A9\u0E3F") long secondField,
@JsonFieldName("αβγ") long thirdField,
Expand Down

0 comments on commit 2c1e099

Please sign in to comment.