Consider optional empty arrays to be absent when finding missing fields

Closes gh-519
This commit is contained in:
Andy Wilkinson
2018-06-25 16:59:19 +01:00
parent 7e49a20cb0
commit 7476562d22
2 changed files with 31 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -147,4 +147,14 @@ public class JsonContentHandlerTests {
assertThat(missingFields.size(), is(equalTo(0)));
}
@Test
public void describedFieldThatIsNotPresentNestedBeneathOptionalArrayThatIsEmptyIsNotConsideredMissing() {
List<FieldDescriptor> missingFields = new JsonContentHandler(
"{\"outer\":[]}".getBytes())
.findMissingFields(Arrays.asList(new FieldDescriptor("outer"),
new FieldDescriptor("outer[]").optional(),
new FieldDescriptor("outer[].inner")));
assertThat(missingFields.size(), is(equalTo(0)));
}
}