Improve diagnostics when extracting a non-existent subsection
Closes gh-568
This commit is contained in:
@@ -75,6 +75,9 @@ public class FieldPathPayloadSubsectionExtractor
|
||||
ExtractedField extractedField = new JsonFieldProcessor().extract(this.fieldPath,
|
||||
objectMapper.readValue(payload, Object.class));
|
||||
Object value = extractedField.getValue();
|
||||
if (value == ExtractedField.ABSENT) {
|
||||
throw new PayloadHandlingException(this.fieldPath + " does not identify a section of the payload");
|
||||
}
|
||||
if (value instanceof List) {
|
||||
List<?> extractedList = (List<?>) value;
|
||||
Set<String> uncommonPaths = JsonFieldPaths.from(extractedList).getUncommon();
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link FieldPathPayloadSubsectionExtractor}.
|
||||
@@ -130,4 +131,12 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
assertThat(new String(extractedSubsection)).isEqualTo(new String(subsection));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNonExistentSubsection() throws JsonParseException, JsonMappingException, IOException {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.c")
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
.hasMessage("a.c does not identify a section of the payload");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user