Merge branch '1.2.x'
This commit is contained in:
@@ -86,8 +86,23 @@ class JsonContentHandler implements ContentHandler {
|
||||
}
|
||||
ExtractedField extracted = this.fieldProcessor.extract(candidate.getPath(),
|
||||
payload);
|
||||
return extracted.getValue() instanceof Collection
|
||||
&& ((Collection<?>) extracted.getValue()).isEmpty();
|
||||
return isEmptyCollection(extracted.getValue());
|
||||
}
|
||||
|
||||
private boolean isEmptyCollection(Object value) {
|
||||
if (!(value instanceof Collection)) {
|
||||
return false;
|
||||
}
|
||||
Collection<?> collection = (Collection<?>) value;
|
||||
if (collection.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (Object entry : collection) {
|
||||
if (!isEmptyCollection(entry)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -158,7 +158,7 @@ public class JsonContentHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describedFieldThatIsSometimesPresentChildOfOptionalArrayIsNotConsideredMissing() {
|
||||
public void describedSometimesPresentFieldThatIsChildOfSometimesPresentOptionalArrayIsNotConsideredMissing() {
|
||||
List<FieldDescriptor> missingFields = new JsonContentHandler(
|
||||
"{\"a\":[ {\"b\": \"bravo\"}, {\"b\": \"bravo\", \"c\": { \"d\": \"delta\"}}]}"
|
||||
.getBytes()).findMissingFields(
|
||||
@@ -167,4 +167,25 @@ public class JsonContentHandlerTests {
|
||||
assertThat(missingFields.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describedMissingFieldThatIsChildOfNestedOptionalArrayThatIsEmptyIsNotConsideredMissing() {
|
||||
List<FieldDescriptor> missingFields = new JsonContentHandler(
|
||||
"{\"a\":[{\"b\":[]}]}".getBytes()).findMissingFields(
|
||||
Arrays.asList(new FieldDescriptor("a.[].b").optional(),
|
||||
new FieldDescriptor("a.[].b.[]").optional(),
|
||||
new FieldDescriptor("a.[].b.[].c")));
|
||||
assertThat(missingFields.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describedMissingFieldThatIsChildOfNestedOptionalArrayThatContainsAnObjectIsConsideredMissing() {
|
||||
List<FieldDescriptor> missingFields = new JsonContentHandler(
|
||||
"{\"a\":[{\"b\":[{}]}]}".getBytes()).findMissingFields(
|
||||
Arrays.asList(new FieldDescriptor("a.[].b").optional(),
|
||||
new FieldDescriptor("a.[].b.[]").optional(),
|
||||
new FieldDescriptor("a.[].b.[].c")));
|
||||
assertThat(missingFields.size(), is(equalTo(1)));
|
||||
assertThat(missingFields.get(0).getPath(), is(equalTo("a.[].b.[].c")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user