本文整理汇总了Java中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.setSupportedMediaTypes方法的典型用法代码示例。如果您正苦于以下问题:Java MappingJackson2HttpMessageConverter.setSupportedMediaTypes方法的具体用法?Java MappingJackson2HttpMessageConverter.setSupportedMediaTypes怎么用?Java MappingJackson2HttpMessageConverter.setSupportedMediaTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
的用法示例。
在下文中一共展示了MappingJackson2HttpMessageConverter.setSupportedMediaTypes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureMessageConverters
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
/*FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,//保留空的字段
SerializerFeature.WriteNullStringAsEmpty,//String null -> ""
SerializerFeature.WriteNullNumberAsZero);//Number null -> 0
converter.setFastJsonConfig(config);
converter.setDefaultCharset(Charset.forName("UTF-8"));*/
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
mediaTypes.add(MediaType.TEXT_HTML);
jacksonConverter.setSupportedMediaTypes(mediaTypes);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
jacksonConverter.setObjectMapper(objectMapper);
converters.add(jacksonConverter);
//converters.add(responseBodyConverter());
}
示例2: getRestTemplate
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
protected RestTemplate getRestTemplate() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
converter.setObjectMapper(mapper);
return new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
示例3: ssoFilter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public Filter ssoFilter(ClientResources client, String path) {
MappingJackson2HttpMessageConverter customJsonMessageConverter = new
MappingJackson2HttpMessageConverter();
customJsonMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
MyOAuth2ClientAuthenticationProcessingFilter filter = new MyOAuth2ClientAuthenticationProcessingFilter(path);
filter.setAllowSessionCreation(true);
MyOAuth2RestTemplate template = new MyOAuth2RestTemplate(client.getClient(), oauth2ClientContext);
template.setMessageConverters(Arrays.asList(customJsonMessageConverter));
filter.setRestTemplate(template);
MyUserInfoTokenServices tokenServices = new MyUserInfoTokenServices(client.getResource().getUserInfoUri(),
client.getClient().getClientId(),
userService,
userWechatService,
userPrivilegeService,
privilegeConfigService);
tokenServices.setRestTemplate(template);
filter.setTokenServices(tokenServices);
return filter;
}
示例4: mappingJackson2HttpMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.registerModule(new Jackson2HalModule());
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
示例5: ExampleRestTemplateInheritingFromZg
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
public ExampleRestTemplateInheritingFromZg() {
super();
//json reply should be application/json but we get a text/plain
for (HttpMessageConverter<?> hmc : this.getMessageConverters()) {
if (hmc.getClass().isAssignableFrom(MappingJackson2HttpMessageConverter.class)) {
MappingJackson2HttpMessageConverter mjhc = (MappingJackson2HttpMessageConverter) hmc;
List<MediaType> lmt = new ArrayList<>(mjhc.getSupportedMediaTypes());
lmt.add(MediaType.TEXT_PLAIN);
mjhc.setSupportedMediaTypes(lmt);
}
}
}
示例6: jacksonMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter jacksonMessageConverter() {
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaType.valueOf("application/json")));
jacksonConverter.setObjectMapper(jacksonObjectMapper());
return jacksonConverter;
}
示例7: jsonConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml();
builder.indentOutput(true);
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(builder.build());
jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaType.valueOf("application/json")));
jacksonConverter.setObjectMapper(jacksonObjectMapper());
return jacksonConverter;
}
示例8: customConverters
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public HttpMessageConverters customConverters() {
MappingJackson2HttpMessageConverter jsonConverter =
new MappingJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(Arrays.asList(
new MediaType("application", "json"),
new MediaType("text", "json")
));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JsonOrgModule());
jsonConverter.setObjectMapper(objectMapper);
return new HttpMessageConverters(jsonConverter);
}
示例9: init
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@PostConstruct
public void init() {
restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(portalConfig.readTimeout());
rf.setConnectTimeout(portalConfig.connectTimeout());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(
Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM));
restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
}
示例10: getJacksonHttpMessageConverters
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //导入方法依赖的package包/类
@Bean
public HttpMessageConverters getJacksonHttpMessageConverters(ObjectMapper objectMapper) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN));
return new HttpMessageConverters(converter);
}