Consider sometimes present field beneath optional array to not be missing
The changes made in 7476562d inadvertently caused a field that is
an descendant of an array and a child of an optional field to be
considered missing when its parent is only sometimes present. Due to
the parent being optional, the parent’s absence should not cause the
absent child to be considered to be missing.
Closes gh-519
This commit is contained in:
@@ -81,6 +81,9 @@ class JsonContentHandler implements ContentHandler {
|
||||
}
|
||||
|
||||
private boolean isMissing(FieldDescriptor candidate, Object payload) {
|
||||
if (!this.fieldProcessor.hasField(candidate.getPath(), payload)) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
ExtractedField extracted = this.fieldProcessor.extract(candidate.getPath(),
|
||||
payload);
|
||||
|
||||
@@ -157,4 +157,14 @@ public class JsonContentHandlerTests {
|
||||
assertThat(missingFields.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describedFieldThatIsSometimesPresentChildOfOptionalArrayIsNotConsideredMissing() {
|
||||
List<FieldDescriptor> missingFields = new JsonContentHandler(
|
||||
"{\"a\":[ {\"b\": \"bravo\"}, {\"b\": \"bravo\", \"c\": { \"d\": \"delta\"}}]}"
|
||||
.getBytes()).findMissingFields(
|
||||
Arrays.asList(new FieldDescriptor("a.[].c").optional(),
|
||||
new FieldDescriptor("a.[].c.d]")));
|
||||
assertThat(missingFields.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user