org.springframework.boot.autoconfigure.http.HttpMessageConverters Java Examples
The following examples show how to use
org.springframework.boot.autoconfigure.http.HttpMessageConverters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastJsonConfiguration.java From momo-cloud-permission with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastJsonConfigure(){ FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //日期格式化 fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); //修改配置返回内容的过滤 fastJsonConfig.setSerializerFeatures( // SerializerFeature. WriteMapNullValue,//是否输出值为null的字段,默认为false SerializerFeature.WriteDateUseDateFormat//格式化标签 // SerializerFeature.WriteNullListAsEmpty ,//List字段如果为null,输出为[],而非null // SerializerFeature.DisableCircularReferenceDetect,//消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环) // SerializerFeature.WriteMapNullValue,//是否输出值为null的字段,默认为false。 // SerializerFeature.WriteNullStringAsEmpty//字符类型字段如果为null,输出为"",而非null // SerializerFeature.WriteNullBooleanAsFalse//Boolean字段如果为null,输出为false,而非null ); converter.setFastJsonConfig(fastJsonConfig); //处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(fastMediaTypes); converter.setFastJsonConfig(fastJsonConfig); //将fastjson添加到视图消息转换器列表内 return new HttpMessageConverters(converter); }
Example #2
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example #3
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #4
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #5
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #6
Source File: DownloadClient.java From feign-form with Apache License 2.0 | 6 votes |
@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; } }); }
Example #7
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #8
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #9
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #10
Source File: FastJsonConfiguration.java From momo-cloud-permission with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastJsonConfigure(){ FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //日期格式化 fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); //修改配置返回内容的过滤 fastJsonConfig.setSerializerFeatures( SerializerFeature. WriteMapNullValue,//是否输出值为null的字段,默认为false SerializerFeature.WriteDateUseDateFormat,//格式化标签 SerializerFeature.WriteNullListAsEmpty , //List字段如果为null,输出为[],而非null SerializerFeature.DisableCircularReferenceDetect,//消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环) SerializerFeature.WriteMapNullValue,//是否输出值为null的字段,默认为false。 SerializerFeature.WriteNullStringAsEmpty,//字符类型字段如果为null,输出为"",而非null SerializerFeature.WriteNullBooleanAsFalse//Boolean字段如果为null,输出为false,而非null ); converter.setFastJsonConfig(fastJsonConfig); //处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(fastMediaTypes); converter.setFastJsonConfig(fastJsonConfig); //将fastjson添加到视图消息转换器列表内 return new HttpMessageConverters(converter); }
Example #11
Source File: ApiConfiguration.java From open-cloud with MIT License | 6 votes |
/** * 转换器全局配置 * * @param converters * @return */ @Bean public HttpMessageConverters httpMessageConverters(List<HttpMessageConverter<?>> converters) { MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); // 忽略为空的字段 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.getSerializationConfig().withFeatures( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); /** * 序列换成json时,将所有的long变成string * js中long过长精度丢失 */ SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); jackson2HttpMessageConverter.setObjectMapper(objectMapper); log.info("MappingJackson2HttpMessageConverter [{}]", jackson2HttpMessageConverter); return new HttpMessageConverters(jackson2HttpMessageConverter); }
Example #12
Source File: BeanConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); }
Example #13
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example #14
Source File: BeanConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); }
Example #15
Source File: HttpBasicAuthConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters((HttpMessageConverter<?>) fastJsonHttpMessageConverter); }
Example #16
Source File: CorsConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
/** * 升级版本后, 不加这个 gateway 使用feign会报错,不知道什么原因 * * @return */ @Bean public Decoder feignFormDecoder() { List<HttpMessageConverter<?>> converters = new RestTemplate().getMessageConverters(); ObjectFactory<HttpMessageConverters> factory = () -> new HttpMessageConverters(converters); return new ResponseEntityDecoder(new SpringDecoder(factory)); }
Example #17
Source File: LogisticsApplication.java From logistics-back with MIT License | 5 votes |
@Bean public HttpMessageConverters fastJsonHttpMessageConverters() { // 1.需要定义一个Convert转换消息的对象 FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); // 2.添加fastjson的配置信息,比如是否要格式化返回的json数据 FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); // 3.在convert中添加配置信息 fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #18
Source File: RequestBodyServiceParameterResolver.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@PostConstruct public void init() { HttpMessageConverters httpMessageConverters = this.httpMessageConverters .getIfAvailable(); httpMessageConverterResolver = new HttpMessageConverterResolver( httpMessageConverters == null ? Collections.emptyList() : httpMessageConverters.getConverters(), getClassLoader()); }
Example #19
Source File: HttpConverterLoader.java From mercury with Apache License 2.0 | 5 votes |
@Bean public HttpMessageConverters getMessageConverters() { log.info("Loading HTTP serializers"); HttpConverterJson json = new HttpConverterJson(); HttpConverterXml xml = new HttpConverterXml(); HttpConverterHtml html = new HttpConverterHtml(); HttpConverterText text = new HttpConverterText(); return new HttpMessageConverters(json, xml, html, text); }
Example #20
Source File: ApplicationConfiguration.java From spring-cloud-shop with MIT License | 5 votes |
@Bean public HttpMessageConverters fastJsonConfigure() { FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); converter.setFastJsonConfig(fastJsonConfig); List<MediaType> supportedMediaTypes = new ArrayList<>(); supportedMediaTypes.add(MediaType.APPLICATION_JSON); supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); supportedMediaTypes.add(MediaType.APPLICATION_ATOM_XML); supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED); supportedMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM); supportedMediaTypes.add(MediaType.APPLICATION_PDF); supportedMediaTypes.add(MediaType.APPLICATION_RSS_XML); supportedMediaTypes.add(MediaType.APPLICATION_XHTML_XML); supportedMediaTypes.add(MediaType.APPLICATION_XML); supportedMediaTypes.add(MediaType.IMAGE_GIF); supportedMediaTypes.add(MediaType.IMAGE_JPEG); supportedMediaTypes.add(MediaType.IMAGE_PNG); supportedMediaTypes.add(MediaType.TEXT_EVENT_STREAM); supportedMediaTypes.add(MediaType.TEXT_HTML); supportedMediaTypes.add(MediaType.TEXT_MARKDOWN); supportedMediaTypes.add(MediaType.TEXT_PLAIN); supportedMediaTypes.add(MediaType.TEXT_XML); converter.setSupportedMediaTypes(supportedMediaTypes); return new HttpMessageConverters(converter); }
Example #21
Source File: Application.java From bookmark with MIT License | 5 votes |
@Bean public HttpMessageConverters fastJsonHttpMessageConverters() { // 1.定义一个converters转换消息的对象 FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); // 2.添加fastjson的配置信息,比如: 是否需要格式化返回的json数据 FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); // 3.在converter中添加配置信息 fastConverter.setFastJsonConfig(fastJsonConfig); // 5.返回HttpMessageConverters对象 return new HttpMessageConverters(fastConverter); }
Example #22
Source File: AdminServiceAddressLocator.java From apollo with Apache License 2.0 | 5 votes |
public AdminServiceAddressLocator( final HttpMessageConverters httpMessageConverters, final PortalSettings portalSettings, final RestTemplateFactory restTemplateFactory, final PortalMetaDomainService portalMetaDomainService ) { this.portalSettings = portalSettings; this.restTemplateFactory = restTemplateFactory; this.portalMetaDomainService = portalMetaDomainService; }
Example #23
Source File: HttpMessageConverterConfiguration.java From apollo with Apache License 2.0 | 5 votes |
@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; } }; }
Example #24
Source File: ReservationService.java From spring-cloud-in-action with MIT License | 5 votes |
@Bean public Decoder feignDecoder() { ObjectMapper objectMapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) .registerModule(new Jackson2HalModule()); MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(); jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON)); jacksonConverter.setObjectMapper(objectMapper); ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter); return new ResponseEntityDecoder(new SpringDecoder(objectFactory)); }
Example #25
Source File: SpringCloudSecondaryConfiguration.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
@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; }
Example #26
Source File: SpringCloudConfiguration.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
@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; }
Example #27
Source File: WebConfiguration.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Bean public HttpMessageConverters messageConverters(ObjectMapper objectMapper) { return new HttpMessageConverters( // Prevent default converters false, Arrays.<HttpMessageConverter<?>>asList(new MappingJackson2HttpMessageConverter(objectMapper), new ResourceHttpMessageConverter())); }
Example #28
Source File: MessageConfig.java From framework with Apache License 2.0 | 5 votes |
/** * * Description: <br> * * @author 王伟<br> * @taskId <br> * @return <br> */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { // 1、需要先定义一个 convert 转换消息对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setFeatures(Feature.AllowISO8601DateFormat); fastConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(new StringHttpMessageConverter(), fastConverter); }
Example #29
Source File: SpringCloudConfiguration.java From ByteJTA with GNU Lesser General Public License v3.0 | 5 votes |
@org.springframework.context.annotation.Primary @org.springframework.context.annotation.Bean public feign.codec.Decoder transactionFeignDecoder(@Autowired ObjectFactory<HttpMessageConverters> objectFactory, @Autowired feign.codec.Decoder decoder) { TransactionFeignDecoder feignDecoder = new TransactionFeignDecoder(decoder); feignDecoder.setObjectFactory(objectFactory); return feignDecoder; }
Example #30
Source File: Spring5Application.java From tutorials with MIT License | 5 votes |
@Bean public HttpMessageConverters customConverters() { Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); JsonbHttpMessageConverter jsonbHttpMessageConverter = new JsonbHttpMessageConverter(); messageConverters.add(jsonbHttpMessageConverter); return new HttpMessageConverters(true, messageConverters); }