Skip to content
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

allowing requests without content to do not deserialize parameters #838

Merged
merged 1 commit into from
Oct 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void deserializes(@Observes InterceptorsReady event, HttpServletRequest r

List<String> supported = asList(method.getMethod().getAnnotation(Consumes.class).value());

if(request.getContentType() == null) {
logger.warn("Request does not have Content-Type and parameters will be not deserialized");
return;
}

String contentType = mime(request.getContentType());
if (!supported.isEmpty() && !supported.contains(contentType)) {
unsupported("Request with media type [%s]. Expecting one of %s.", status, contentType, supported);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ public void willDeserializeForAnyContentTypeIfPossible() throws Exception {
assertEquals(methodInfo.getValuedParameters()[1].getValue(), "def");
}

@Test
public void shouldNotDeserializeIfHasNoContentType() throws Exception {
final ControllerMethod consumesAnything = new DefaultControllerMethod(null, DummyResource.class.getDeclaredMethod("consumesAnything", String.class, String.class));

when(request.getContentType()).thenReturn(null);
methodInfo.setControllerMethod(consumesAnything);
observer.deserializes(new InterceptorsReady(consumesAnything), request, methodInfo, status);

assertEquals(methodInfo.getValuedParameters()[0].getValue(), null);
assertEquals(methodInfo.getValuedParameters()[1].getValue(), null);
}

@Test
public void willSetOnlyNonNullParameters() throws Exception {
final Deserializer deserializer = mock(Deserializer.class);
Expand Down