use of cn.taketoday.web.handler.method.JsonViewRequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter.
// SPR-12501
@Test
public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Throwable {
String content = "<root>" + "<withView1>with</withView1>" + "<withView2>with</withView2>" + "<withoutView>without</withoutView></root>";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);
Method method = JacksonController.class.getMethod("handleHttpEntity", HttpEntity.class);
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2XmlHttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()), null);
@SuppressWarnings("unchecked") HttpEntity<JacksonViewBean> result = (HttpEntity<JacksonViewBean>) processor.resolveArgument(request, new ResolvableMethodParameter(methodParameter));
assertThat(result).isNotNull();
assertThat(result.getBody()).isNotNull();
assertThat(result.getBody().getWithView1()).isEqualTo("with");
assertThat(result.getBody().getWithView2()).isNull();
assertThat(result.getBody().getWithoutView()).isNull();
}
use of cn.taketoday.web.handler.method.JsonViewRequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentWithJacksonJsonView.
// SPR-12501
@Test
public void resolveArgumentWithJacksonJsonView() throws Throwable {
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
Method method = JacksonController.class.getMethod("handleRequestBody", JacksonViewBean.class);
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()));
JacksonViewBean result = (JacksonViewBean) processor.resolveArgument(request, new ResolvableMethodParameter(methodParameter));
assertThat(result).isNotNull();
assertThat(result.getWithView1()).isEqualTo("with");
assertThat(result.getWithView2()).isNull();
assertThat(result.getWithoutView()).isNull();
}
use of cn.taketoday.web.handler.method.JsonViewRequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveHttpEntityArgumentWithJacksonJsonView.
// SPR-12501
@Test
public void resolveHttpEntityArgumentWithJacksonJsonView() throws Throwable {
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
Method method = JacksonController.class.getMethod("handleHttpEntity", HttpEntity.class);
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()), null);
@SuppressWarnings("unchecked") HttpEntity<JacksonViewBean> result = (HttpEntity<JacksonViewBean>) processor.resolveArgument(request, new ResolvableMethodParameter(methodParameter));
assertThat(result).isNotNull();
assertThat(result.getBody()).isNotNull();
assertThat(result.getBody().getWithView1()).isEqualTo("with");
assertThat(result.getBody().getWithView2()).isNull();
assertThat(result.getBody().getWithoutView()).isNull();
}
use of cn.taketoday.web.handler.method.JsonViewRequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentWithJacksonJsonViewAndXmlMessageConverter.
// SPR-12501
@Test
public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Throwable {
String content = "<root>" + "<withView1>with</withView1>" + "<withView2>with</withView2>" + "<withoutView>without</withoutView></root>";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);
Method method = JacksonController.class.getMethod("handleRequestBody", JacksonViewBean.class);
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2XmlHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters, null, Collections.singletonList(new JsonViewRequestBodyAdvice()));
JacksonViewBean result = (JacksonViewBean) processor.resolveArgument(request, new ResolvableMethodParameter(methodParameter));
assertThat(result).isNotNull();
assertThat(result.getWithView1()).isEqualTo("with");
assertThat(result.getWithView2()).isNull();
assertThat(result.getWithoutView()).isNull();
}
Aggregations