This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 27da8d78f38ac4c43268bf0afc55bbe2ba0d4bcd Author: Benoit Tellier <[email protected]> AuthorDate: Tue May 18 12:54:46 2021 +0700 [PERFORMANCE] JMAP draft was parsing, formatting then re-parsing JSON --- .../jmap/draft/methods/integration/GetMailboxesMethodTest.java | 2 +- .../jmap/draft/methods/integration/SetMessagesMethodTest.java | 2 +- .../apache/james/jmap/draft/methods/JmapRequestParserImpl.java | 5 ++++- .../james/jmap/draft/methods/UpdateMessagePatchValidator.java | 2 +- .../james/jmap/draft/methods/JmapRequestParserImplTest.java | 9 ++++++--- .../jmap/draft/methods/UpdateMessagePatchValidatorTest.java | 3 ++- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/GetMailboxesMethodTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/GetMailboxesMethodTest.java index 1261e75..982c401 100644 --- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/GetMailboxesMethodTest.java +++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/GetMailboxesMethodTest.java @@ -343,7 +343,7 @@ public abstract class GetMailboxesMethodTest { .body(NAME, equalTo("error")) .body(ARGUMENTS + ".type", equalTo("invalidArguments")) .body(ARGUMENTS + ".description", containsString("Cannot deserialize value of type `java.util.ArrayList<org.apache.james.mailbox.model.MailboxId>` from Boolean value (token `JsonToken.VALUE_TRUE`)")) - .body(ARGUMENTS + ".description", containsString("{\"ids\":true}")); + .body(ARGUMENTS + ".description", containsString("(through reference chain: org.apache.james.jmap.draft.model.GetMailboxesRequest$Builder[\"ids\"])")); } @Category(BasicFeature.class) diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java index 1ecc01e..1e25586 100644 --- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java +++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java @@ -889,7 +889,7 @@ public abstract class SetMessagesMethodTest { .body(NOT_UPDATED + "[\"" + messageId + "\"].type", equalTo("invalidProperties")) .body(NOT_UPDATED + "[\"" + messageId + "\"].properties[0]", equalTo("isUnread")) .body(NOT_UPDATED + "[\"" + messageId + "\"].description", containsString("isUnread: Cannot deserialize value of type `java.lang.Boolean` from String \"123\": only \"true\" or \"false\" recognized")) - .body(NOT_UPDATED + "[\"" + messageId + "\"].description", containsString("{\"isUnread\":\"123\"}")) + .body(NOT_UPDATED + "[\"" + messageId + "\"].description", containsString("(through reference chain: org.apache.james.jmap.draft.model.UpdateMessagePatch$Builder[\"isUnread\"])")) .body(ARGUMENTS + ".updated", hasSize(0)); } diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/JmapRequestParserImpl.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/JmapRequestParserImpl.java index 273efdd..5c77c2c 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/JmapRequestParserImpl.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/JmapRequestParserImpl.java @@ -29,6 +29,7 @@ import org.apache.james.jmap.draft.model.InvocationRequest; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Preconditions; public class JmapRequestParserImpl implements JmapRequestParser { @@ -42,6 +43,8 @@ public class JmapRequestParserImpl implements JmapRequestParser { @Override public <T extends JmapRequest> T extractJmapRequest(InvocationRequest request, Class<T> requestClass) throws IOException, JsonParseException, JsonMappingException { - return objectMapper.readValue(request.getParameters().toString(), requestClass); + Preconditions.checkNotNull(requestClass, "requestClass should not be null"); + + return objectMapper.treeToValue(request.getParameters(), requestClass); } } diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidator.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidator.java index da4264e..5701ba2 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidator.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidator.java @@ -53,7 +53,7 @@ public class UpdateMessagePatchValidator implements Validator<ObjectNode> { @Override public Set<ValidationResult> validate(ObjectNode json) { try { - parser.readValue(json.toString(), UpdateMessagePatch.class); + parser.treeToValue(json, UpdateMessagePatch.class); } catch (JsonMappingException e) { return ImmutableSet.of(ValidationResult.builder() .property(firstFieldFrom(e.getPath()).orElse(ValidationResult.UNDEFINED_PROPERTY)) diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/JmapRequestParserImplTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/JmapRequestParserImplTest.java index 2a64b59..7356d1e 100644 --- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/JmapRequestParserImplTest.java +++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/JmapRequestParserImplTest.java @@ -19,6 +19,8 @@ package org.apache.james.jmap.draft.methods; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import org.apache.james.jmap.draft.json.ObjectMapperFactory; import org.apache.james.jmap.draft.model.InvocationRequest; import org.apache.james.mailbox.inmemory.InMemoryId; @@ -38,13 +40,14 @@ public class JmapRequestParserImplTest { testee = new JmapRequestParserImpl(new ObjectMapperFactory(new InMemoryId.Factory(), new InMemoryMessageId.Factory())); } - @Test(expected = IllegalArgumentException.class) - public void extractJmapRequestShouldThrowWhenNullRequestClass() throws Exception { + @Test + public void extractJmapRequestShouldThrowWhenNullRequestClass() { JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"), new ObjectNode(new JsonNodeFactory(false)).putObject("{\"id\": \"id\"}"), new ObjectNode(new JsonNodeFactory(false)).textNode("#1")}; - testee.extractJmapRequest(InvocationRequest.deserialize(nodes), null); + assertThatThrownBy(() -> testee.extractJmapRequest(InvocationRequest.deserialize(nodes), null)) + .isInstanceOf(NullPointerException.class); } @Test diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidatorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidatorTest.java index 7355f3d..500cf0f 100644 --- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidatorTest.java +++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/UpdateMessagePatchValidatorTest.java @@ -20,6 +20,7 @@ package org.apache.james.jmap.draft.methods; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -82,7 +83,7 @@ public class UpdateMessagePatchValidatorTest { ObjectMapper mapper = mock(ObjectMapper.class); JsonGenerator jsonGenerator = null; - when(mapper.readValue(anyString(), eq(UpdateMessagePatch.class))) + when(mapper.treeToValue(any(), eq(UpdateMessagePatch.class))) .thenThrow(JsonMappingException.from(jsonGenerator, "Exception when parsing")); when(objectMapperFactory.forParsing()) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
