use of cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter in project today-infrastructure by TAKETODAY.
the class HeaderRequestMatchersIntegrationTests method setup.
@BeforeEach
public void setup() {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new StringHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
use of cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter in project today-framework by TAKETODAY.
the class HttpEntityMethodProcessorTests method jacksonTypeInfoList.
// SPR-12811
@Test
public void jacksonTypeInfoList() throws Exception {
Method method = JacksonController.class.getMethod("handleList");
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);
Object returnValue = new JacksonController().handleList();
processor.handleReturnValue(webRequest, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("\"type\":\"foo\"")).isTrue();
assertThat(content.contains("\"type\":\"bar\"")).isTrue();
}
use of cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method jacksonSubType.
// SPR-13318
@Test
public void jacksonSubType() throws Throwable {
Method method = JacksonController.class.getMethod("handleSubType");
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);
Object returnValue = new JacksonController().handleSubType();
processor.handleReturnValue(request, handlerMethod, returnValue);
String content = this.servletResponse.getContentAsString();
assertThat(content.contains("\"id\":123")).isTrue();
assertThat(content.contains("\"name\":\"foo\"")).isTrue();
}
use of cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentTypeVariableWithNonGenericConverter.
// SPR-11225
@Test
public void resolveArgumentTypeVariableWithNonGenericConverter() throws Throwable {
Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
String content = "{\"name\" : \"Jad\"}";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
HttpMessageConverter<Object> target = new MappingJackson2HttpMessageConverter();
HttpMessageConverter<?> proxy = ProxyFactory.getProxy(HttpMessageConverter.class, new SingletonTargetSource(target));
converters.add(proxy);
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
SimpleBean result = (SimpleBean) processor.resolveArgument(request, new ResolvableMethodParameter(methodParam));
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo("Jad");
}
use of cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentTypeVariableWithGenericInterface.
// SPR-14520
@Test
public void resolveArgumentTypeVariableWithGenericInterface() throws Throwable {
this.servletRequest.setContent("\"foo\"".getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
Method method = MyControllerImplementingInterface.class.getMethod("handle", Object.class);
HandlerMethod handlerMethod = new HandlerMethod(new MyControllerImplementingInterface(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
assertThat(processor.supportsParameter(new ResolvableMethodParameter(methodParameter))).isTrue();
String value = (String) processor.readWithMessageConverters(this.request, methodParameter, methodParameter.getGenericParameterType());
assertThat(value).isEqualTo("foo");
}
Aggregations