Skip to content

Diagnostics are poor when a wildcard is used with beneathPath and the identified field doesn't exist everywhere in the payload #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wilkinsona opened this issue Apr 7, 2021 · 2 comments
Labels
Milestone

Comments

@wilkinsona
Copy link
Member

See #714 for some background. When a field path containing a wildcard is used with beneathPath and the field doesn't exist everywhere in the payload, the resulting error message is the following:

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.lang.Object and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

An error explaining that the identified sections of the payload do not have a common structure should be thrown instead.

@wilkinsona
Copy link
Member Author

I can't reproduce the problem described in #714. This test passes:

@Test
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap()
        throws JsonParseException, JsonMappingException, IOException {
    this.thrown.expect(PayloadHandlingException.class);
    this.thrown.expectMessage(
            "The following non-optional uncommon paths were found: [*.thread.content, *.thread.count]");
    new FieldPathPayloadSubsectionExtractor("*.thread").extractSubsection(
            "{ \"number\":\"123\", \"link\":{ \"scheme\":\"scheme\", \"url\":\"url\" }, \"chat\":{ \"message\":\"send message\", \"id\":\"id\", \"thread\":{ \"content\":\"thread content\", \"count\":1 } } }"
                    .getBytes(),
            MediaType.APPLICATION_JSON);
}

@ddaaac Can you please provide a complete and minimal sample that reproduces the error message that you reported in #714?

@wilkinsona wilkinsona removed this from the 2.0.6.RELEASE milestone Apr 7, 2021
@wilkinsona wilkinsona added status: waiting-for-feedback Feedback is required before progress can be made status: waiting-for-triage Untriaged issue labels Apr 7, 2021
@ddaaac
Copy link
Contributor

ddaaac commented Apr 8, 2021

In my PR 71577e6, there is a test case. With some modifications to this case, following case would be not work.
And this exception seems to be thrown when the field descriptors exist.

@Test
	public void extractSubSectionWithWildcardAndFieldDescriptors() throws IOException {
		byte[] extractedPayload = new FieldPathPayloadSubsectionExtractor("*.d")
				.extractSubsection("{\"a\":{\"b\":1},\"c\":{\"d\":{\"e\":1,\"f\":2}}}".getBytes(),
								   MediaType.APPLICATION_JSON,
								   Arrays.asList(new FieldDescriptor("e").optional(), new FieldDescriptor("f").optional()));
		Map<String, Object> extracted = new ObjectMapper().readValue(extractedPayload, Map.class);
		assertThat(extracted.size()).isEqualTo(2);
		assertThat(extracted).containsOnlyKeys("e", "f");
	}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback Feedback is required before progress can be made labels Apr 8, 2021
@wilkinsona wilkinsona removed status: feedback-provided Feedback has been provided status: waiting-for-triage Untriaged issue labels Apr 19, 2021
@wilkinsona wilkinsona added this to the 2.0.6.RELEASE milestone Apr 19, 2021
wilkinsona added a commit that referenced this issue Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants