use of cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method jacksonJsonViewWithResponseBodyAndXmlMessageConverter.
// SPR-12149
@Test
public void jacksonJsonViewWithResponseBodyAndXmlMessageConverter() throws Throwable {
Method method = JacksonController.class.getMethod("handleResponseBody");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2XmlHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()));
Object returnValue = new JacksonController().handleResponseBody();
processor.handleReturnValue(request, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("<withView1>with</withView1>")).isFalse();
assertThat(content.contains("<withView2>with</withView2>")).isTrue();
assertThat(content.contains("<withoutView>without</withoutView>")).isFalse();
}
use of cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method jacksonJsonViewWithResponseEntityAndXmlMessageConverter.
// SPR-12149
@Test
public void jacksonJsonViewWithResponseEntityAndXmlMessageConverter() throws Throwable {
Method method = JacksonController.class.getMethod("handleResponseEntity");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2XmlHttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()), null);
Object returnValue = new JacksonController().handleResponseEntity();
processor.handleReturnValue(request, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("<withView1>with</withView1>")).isFalse();
assertThat(content.contains("<withView2>with</withView2>")).isTrue();
assertThat(content.contains("<withoutView>without</withoutView>")).isFalse();
}
use of cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method jacksonJsonViewWithResponseBodyAndJsonMessageConverter.
@Test
public void jacksonJsonViewWithResponseBodyAndJsonMessageConverter() throws Throwable {
Method method = JacksonController.class.getMethod("handleResponseBody");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()));
Object returnValue = new JacksonController().handleResponseBody();
processor.handleReturnValue(request, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("\"withView1\":\"with\"")).isFalse();
assertThat(content.contains("\"withView2\":\"with\"")).isTrue();
assertThat(content.contains("\"withoutView\":\"without\"")).isFalse();
}
use of cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method jacksonJsonViewWithResponseEntityAndJsonMessageConverter.
@Test
public void jacksonJsonViewWithResponseEntityAndJsonMessageConverter() throws Throwable {
Method method = JacksonController.class.getMethod("handleResponseEntity");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()), null);
Object returnValue = new JacksonController().handleResponseEntity();
processor.handleReturnValue(request, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("\"withView1\":\"with\"")).isFalse();
assertThat(content.contains("\"withView2\":\"with\"")).isTrue();
assertThat(content.contains("\"withoutView\":\"without\"")).isFalse();
}
Aggregations