本文整理汇总了Java中org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractJackson2HttpMessageConverter类的具体用法?Java AbstractJackson2HttpMessageConverter怎么用?Java AbstractJackson2HttpMessageConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractJackson2HttpMessageConverter类属于org.springframework.http.converter.json包,在下文中一共展示了AbstractJackson2HttpMessageConverter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getJacksonConverter
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
/**
* Get a registered AbstractJackson2HttpMessageConverter from RestTemplate
* @param restTemplate RestTemplate
* @return Optional AbstractJackson2HttpMessageConverter, empty if not registered
*/
private static Optional<AbstractJackson2HttpMessageConverter> getJacksonConverter(RestTemplate restTemplate) {
for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
if (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converter.getClass())) {
return Optional.of((AbstractJackson2HttpMessageConverter) converter);
}
}
return Optional.empty();
}
开发者ID:holon-platform,项目名称:holon-json,代码行数:14,代码来源:SpringJacksonConfiguration.java
示例2: supports_PageReturnType_ReturnTrue
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Test
public void supports_PageReturnType_ReturnTrue() {
MethodParameter returnType = new MethodParameter(pageableMethod, -1, 0);
boolean support = paginationAdvice.supports(returnType, AbstractJackson2HttpMessageConverter.class);
assertThat(support, equalTo(Boolean.TRUE));
}
开发者ID:cmateosl,项目名称:role-api,代码行数:8,代码来源:PaginationAdviceTest.java
示例3: supports_NonPageReturnTyp_ReturnFalse
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Test
public void supports_NonPageReturnTyp_ReturnFalse() {
MethodParameter returnType = new MethodParameter(nonPageableMethod, -1, 0);
boolean support = paginationAdvice.supports(returnType, AbstractJackson2HttpMessageConverter.class);
assertThat(support, equalTo(Boolean.FALSE));
}
开发者ID:cmateosl,项目名称:role-api,代码行数:8,代码来源:PaginationAdviceTest.java
示例4: supports
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Override
public boolean supports(MethodParameter methodParameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) {
return (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType) &&
methodParameter.getParameterAnnotation(JsonView.class) != null);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:JsonViewRequestBodyAdvice.java
示例5: requestMappingHandlerAdapter
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Test
public void requestMappingHandlerAdapter() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertEquals(9, converters.size());
for(HttpMessageConverter<?> converter : converters) {
if (converter instanceof AbstractJackson2HttpMessageConverter) {
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
assertEquals(XmlMapper.class, objectMapper.getClass());
}
}
}
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
assertNotNull(initializer);
ConversionService conversionService = initializer.getConversionService();
assertNotNull(conversionService);
assertTrue(conversionService instanceof FormattingConversionService);
Validator validator = initializer.getValidator();
assertNotNull(validator);
assertTrue(validator instanceof LocalValidatorFactoryBean);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
@SuppressWarnings("unchecked")
List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
assertEquals(2, bodyAdvice.size());
assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:37,代码来源:WebMvcConfigurationSupportTests.java
示例6: supports
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:AbstractMappingJacksonResponseBodyAdvice.java
示例7: testDefaultConfig
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; //导入依赖的package包/类
@Test
public void testDefaultConfig() throws Exception {
loadBeanDefinitions("mvc-config.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
assertEquals(0, mapping.getOrder());
assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
NativeWebRequest webRequest = new ServletWebRequest(request);
ContentNegotiationManager manager = mapping.getContentNegotiationManager();
assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertTrue(converters.size() > 0);
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof AbstractJackson2HttpMessageConverter) {
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
assertEquals(XmlMapper.class, objectMapper.getClass());
}
}
}
assertNotNull(appContext.getBean(FormattingConversionServiceFactoryBean.class));
assertNotNull(appContext.getBean(ConversionService.class));
assertNotNull(appContext.getBean(LocalValidatorFactoryBean.class));
assertNotNull(appContext.getBean(Validator.class));
// default web binding initializer behavior test
request = new MockHttpServletRequest("GET", "/");
request.addParameter("date", "2009-10-31");
request.addParameter("percent", "99.99%");
MockHttpServletResponse response = new MockHttpServletResponse();
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(1, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
interceptor.preHandle(request, response, handlerMethod);
assertSame(appContext.getBean(ConversionService.class), request.getAttribute(ConversionService.class.getName()));
adapter.handle(request, response, handlerMethod);
assertTrue(handler.recordedValidationError);
assertEquals(LocalDate.parse("2009-10-31").toDate(), handler.date);
assertEquals(Double.valueOf(0.9999), handler.percent);
CompositeUriComponentsContributor uriComponentsContributor = this.appContext.getBean(
MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME,
CompositeUriComponentsContributor.class);
assertNotNull(uriComponentsContributor);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:63,代码来源:MvcNamespaceTests.java
注:本文中的org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论