本文整理汇总了Java中org.springframework.boot.autoconfigure.web.HttpMessageConverters类的典型用法代码示例。如果您正苦于以下问题:Java HttpMessageConverters类的具体用法?Java HttpMessageConverters怎么用?Java HttpMessageConverters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpMessageConverters类属于org.springframework.boot.autoconfigure.web包,在下文中一共展示了HttpMessageConverters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wxApiTemplate
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
/**
* 是否有必要模仿Spring不提供RestTemplate,只提供RestTemplateBuilder
*
* @return dummy
*/
@Bean(name = WxBeans.WX_API_TEMPLATE_NAME)
public WxApiTemplate wxApiTemplate() {
RestTemplateBuilder builder = new RestTemplateBuilder();
builder = builder.requestFactory(new WxApiHttpRequestFactory(wxProperties))
.errorHandler(new WxResponseErrorHandler());
HttpMessageConverters converters = this.messageConverters.getIfUnique();
List<HttpMessageConverter<?>> converterList = new ArrayList<>();
// 加入默认转换
converterList.add(new WxHttpInputMessageConverter());
if (converters != null) {
converterList.addAll(converters.getConverters());
builder = builder.messageConverters(Collections.unmodifiableList(converterList));
}
return new WxApiTemplate(builder.build());
}
示例2: feignDecoder
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public Decoder feignDecoder () {
val springConverters = messageConverters.getObject().getConverters();
val decoderConverters = new ArrayList<HttpMessageConverter<?>>(springConverters.size() + 1);
decoderConverters.addAll(springConverters);
decoderConverters.add(new SpringManyMultipartFilesReader(4096));
val httpMessageConverters = new HttpMessageConverters(decoderConverters);
return new SpringDecoder(new ObjectFactory<HttpMessageConverters>() {
@Override
public HttpMessageConverters getObject () {
return httpMessageConverters;
}
});
}
示例3: customConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.class)
public HttpMessageConverters customConverters(FastJsonHttpMessageConverter converter) {
Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
if (null == converter) {
Class<?> converterClass = properties.getConverter();
converter = (FastJsonHttpMessageConverter) BeanUtils.instantiate(converterClass);
}
FastJsonConfig config = new FastJsonConfig();
List<SerializerFeature> features = properties.getFeatures();
if (!CollectionUtils.isBlank(features)) {
SerializerFeature[] featureArray = new SerializerFeature[features.size()];
config.setSerializerFeatures(features.toArray(featureArray));
}
converter.setFastJsonConfig(config);
messageConverters.add(converter);
return new HttpMessageConverters(true, messageConverters);
}
示例4: customConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters customConverters()
{
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(gson);
// normally you can simply exclude jackson from the classpath to cause
// Spring to use gson, but minio also depends on jackson
List<HttpMessageConverter<?>> converters = new RestTemplate().getMessageConverters();
converters.removeIf(converter -> converter.getClass() == MappingJackson2HttpMessageConverter.class);
converters.add(gsonHttpMessageConverter);
return new HttpMessageConverters(false, converters);
}
示例5: registerHttpMessageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
private String registerHttpMessageConverters(final String id) {
return registry.register(id, HttpMessageConverters.class, () -> {
final List<Object> list = list();
LOG.debug("Client [{}]: Registering StringHttpMessageConverter", id);
list.add(genericBeanDefinition(StringHttpMessageConverter.class)
.addPropertyValue("writeAcceptCharset", false)
.getBeanDefinition());
final String objectMapperId = findObjectMapper(id);
LOG.debug("Client [{}]: Registering MappingJackson2HttpMessageConverter referencing [{}]", id, objectMapperId);
list.add(genericBeanDefinition(MappingJackson2HttpMessageConverter.class)
.addConstructorArgReference(objectMapperId)
.getBeanDefinition());
LOG.debug("Client [{}]: Registering StreamConverter referencing [{}]", id, objectMapperId);
list.add(genericBeanDefinition(Streams.class)
.setFactoryMethod("streamConverter")
.addConstructorArgReference(objectMapperId)
.getBeanDefinition());
return BeanDefinitionBuilder.genericBeanDefinition(ClientHttpMessageConverters.class)
.addConstructorArgValue(list);
});
}
示例6: messageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters messageConverters() {
final ObjectMapper objectMapper = new ObjectMapper();
setupObjectMapper(objectMapper);
return new HttpMessageConverters(
// Prevent default converters
false,
// Have Jackson2 converter as the sole converter
Arrays.<HttpMessageConverter<?>>asList(new MappingJackson2HttpMessageConverter(objectMapper)));
}
示例7: fastJsonHttpMessageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
/**
* 配置使用springmvc fastjson
* @return
*/
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
示例8: fastJsonHttpMessageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//处理中文乱码
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastConverter.setSupportedMediaTypes(fastMediaTypes);
return new HttpMessageConverters((HttpMessageConverter<?>) fastConverter);
}
示例9: customConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的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);
}
示例10: messageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters messageConverters() {
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
return new HttpMessageConverters() {
@Override
public List<HttpMessageConverter<?>> getConverters() {
return converters;
}
};
}
示例11: getDefaultWxMessageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
/**
* 只考虑微信的消息转换,后期可以优化
* 其实这里完全可以使用系统的Bean,但是这里我想特殊处理,只对微信消息做转换,所以定制化了几个converter
*
* @return dummy
*/
private HttpMessageConverters getDefaultWxMessageConverters() {
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
stringConverter.setWriteAcceptCharset(false);
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
Jaxb2RootElementHttpMessageConverter xmlConverter = new Jaxb2RootElementHttpMessageConverter();
AllEncompassingFormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
ResourceHttpMessageConverter resourceConverter = new ResourceHttpMessageConverter();
HttpMessageConverters wxMessageConverters = new HttpMessageConverters(stringConverter, jsonConverter, xmlConverter, formConverter, resourceConverter);
return wxMessageConverters;
}
示例12: customConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters customConverters() {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new FunctionalSyntaxHttpMessageConverter());
converters.add(new ManchesterSyntaxHttpMessageConverter());
converters.add(new OwlXmlHttpMessageConverter());
converters.add(new RdfXmlOntologyHttpMessageConverter());
converters.add(new TurtleOntologyHttpMessageConverter());
return new HttpMessageConverters(converters);
}
示例13: compensableFeignDecoder
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@org.springframework.context.annotation.Primary
@org.springframework.context.annotation.Bean
public feign.codec.Decoder compensableFeignDecoder(@Autowired feign.codec.Decoder decoder,
@Autowired ObjectFactory<HttpMessageConverters> objectFactory) {
CompensableFeignDecoder feignDecoder = new CompensableFeignDecoder(decoder);
feignDecoder.setObjectFactory(objectFactory);
return feignDecoder;
}
示例14: compensableFeignDecoder
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@org.springframework.context.annotation.Primary
@org.springframework.context.annotation.Bean
public feign.codec.Decoder compensableFeignDecoder(@Autowired ObjectFactory<HttpMessageConverters> objectFactory) {
CompensableFeignDecoder feignDecoder = new CompensableFeignDecoder();
feignDecoder.setObjectFactory(objectFactory);
return feignDecoder;
}
示例15: messageConverters
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; //导入依赖的package包/类
@Bean
public HttpMessageConverters messageConverters(ObjectMapper objectMapper) {
return new HttpMessageConverters(
// Prevent default converters
false,
// Have Jackson2 converter as the sole converter
Arrays.<HttpMessageConverter<?>>asList(new MappingJackson2HttpMessageConverter(objectMapper)));
}