当前位置: 首页>>代码示例>>Java>>正文


Java GsonHttpMessageConverter类代码示例

本文整理汇总了Java中org.springframework.http.converter.json.GsonHttpMessageConverter的典型用法代码示例。如果您正苦于以下问题:Java GsonHttpMessageConverter类的具体用法?Java GsonHttpMessageConverter怎么用?Java GsonHttpMessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GsonHttpMessageConverter类属于org.springframework.http.converter.json包,在下文中一共展示了GsonHttpMessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: AllEncompassingFormHttpMessageConverter

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
public AllEncompassingFormHttpMessageConverter() {
	addPartConverter(new SourceHttpMessageConverter<Source>());

	if (jaxb2Present && !jackson2Present) {
		addPartConverter(new Jaxb2RootElementHttpMessageConverter());
	}

	if (jackson2Present) {
		addPartConverter(new MappingJackson2HttpMessageConverter());
	}
	else if (gsonPresent) {
		addPartConverter(new GsonHttpMessageConverter());
	}

	if (jackson2XmlPresent) {
		addPartConverter(new MappingJackson2XmlHttpMessageConverter());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AllEncompassingFormHttpMessageConverter.java

示例2: customConverters

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的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);
}
 
开发者ID:runelite,项目名称:runelite,代码行数:19,代码来源:CustomConfiguration.java

示例3: AbstractRequest

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
/** Creates a new instance of AbstractRequest. Initializes the required fields
 * 
 */

public AbstractRequest() {
	this.serverAddress = AFTConfigurationProperties.getServerAddress() + "api/";		
	this.sessionContext = SessionContext.INSTANCE;	
	restTemplate = new RestTemplate();		
	
	//Create the gson object to decode Json messages
	Gson gson = new GsonBuilder().setDateFormat(DateFormat.LONG)
			.registerTypeAdapter(Date.class, new JsonDateMillisecondsEpochDeserializer())
			.registerTypeAdapter(byte[].class, new AndroidJsonByteArrayBase64Adapter())
			.registerTypeAdapter(UserInfo.class, new UserInfoAdapter())
			.create();
	
	//create the Gson message converter for spring, and set its Gson
	GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
	converter.setGson(gson);
	
	//add the gson message converter to the rest template
	List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
	messageConverters.add(converter);
	restTemplate.setMessageConverters(messageConverters);
}
 
开发者ID:mwcaisse,项目名称:AndroidFT,代码行数:26,代码来源:AbstractRequest.java

示例4: createRestTemplate

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Override
public RestTemplate createRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    
    // web services support json responses
    GsonHttpMessageConverter jsonConverter = new GsonHttpMessageConverter();

    List<MediaType> mediaTypes = new ArrayList<MediaType>();
    mediaTypes.add(MediaType.TEXT_HTML);
    jsonConverter.setSupportedMediaTypes(mediaTypes);
    
    final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters();
    listHttpMessageConverters.add(jsonConverter);
    
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
    interceptors.add(new AcceptHeaderHttpClientInterceptor());
    restTemplate.setInterceptors(interceptors);
    
    restTemplate.setMessageConverters(listHttpMessageConverters);
    return restTemplate;
}
 
开发者ID:NeilBrideau,项目名称:PhishStream,代码行数:22,代码来源:PhishInGsonSpringAndroidSpiceService.java

示例5: getGsonConverter

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
/**
 * Get a registered GsonHttpMessageConverter from RestTemplate
 * @param restTemplate RestTemplate
 * @return Optional GsonHttpMessageConverter, empty if not registered
 */
private static Optional<GsonHttpMessageConverter> getGsonConverter(RestTemplate restTemplate) {
	for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
		if (GsonHttpMessageConverter.class.isAssignableFrom(converter.getClass())) {
			return Optional.of((GsonHttpMessageConverter) converter);
		}
	}
	return Optional.empty();
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:14,代码来源:SpringGsonConfiguration.java

示例6: createGsonHttpMessageConverter

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
private static GsonHttpMessageConverter createGsonHttpMessageConverter() {
  Gson gson = new GsonBuilder()
      .registerTypeAdapter(Date.class,
          (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(
              json.getAsJsonPrimitive().getAsLong()))
      .registerTypeAdapter(Date.class,
          (JsonSerializer<Date>) (date, type, jsonSerializationContext) -> new JsonPrimitive(
              date.getTime()))
      .create();
  GsonHttpMessageConverter gsonConverter = new GsonHttpMessageConverter();
  gsonConverter.setGson(gson);
  return gsonConverter;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:14,代码来源:RestConfig.java

示例7: configureMessageConverters

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
{
    Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().setDateFormat("dd.MM.yyyy").create();
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    converters.add(converter);
    super.configureMessageConverters(converters);
}
 
开发者ID:Witerium,项目名称:stuffEngine,代码行数:10,代码来源:WebAppConfig.java

示例8: messageConverters

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的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;
    }
  };
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:16,代码来源:HttpMessageConverterConfiguration.java

示例9: RestTemplate

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
/**
 * Create a new instance of the {@link RestTemplate} using default settings.
 * Default {@link HttpMessageConverter}s are initialized.
 */
public RestTemplate() {
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(new StringHttpMessageConverter());
	this.messageConverters.add(new ResourceHttpMessageConverter());
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());

	if (romePresent) {
		this.messageConverters.add(new AtomFeedHttpMessageConverter());
		this.messageConverters.add(new RssChannelHttpMessageConverter());
	}

	if (jackson2XmlPresent) {
		this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
	}
	else if (jaxb2Present) {
		this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
	}

	if (jackson2Present) {
		this.messageConverters.add(new MappingJackson2HttpMessageConverter());
	}
	else if (gsonPresent) {
		this.messageConverters.add(new GsonHttpMessageConverter());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:RestTemplate.java

示例10: configureMessageConverters

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new ResourceHttpMessageConverter());

    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();

    converter.setGson(gson());
    converters.add(converter);
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:10,代码来源:WebConfig.java

示例11: getStation

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
public StationDTO getStation() throws RestClientException, WebServiceStatusFailException {

        ResponseEntity<StationDTO> response;

        try {
            HttpEntity<?> request;
            request = new HttpEntity<Object>(getRequestHeaders());

            GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
            converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_PLAIN));
            getRestTemplate().getMessageConverters().add(converter);

            response = getRestTemplate().exchange( membersURL + radioStationURL, HttpMethod.GET, request, StationDTO.class);
            if (response.getStatusCode() != HttpStatus.OK) {
                throw new WebServiceStatusFailException();
            }
        } catch (RestClientException e) {
            Log.d("ServiceStation", "getStation", e);
            throw e;
        }

        return response.getBody();
    }
 
开发者ID:ficiverson,项目名称:radiocom-android,代码行数:24,代码来源:ServiceStation.java

示例12: gsonHttpMessageConverter

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
	GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
	converter.setGson(gson);
	return converter;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:GsonHttpMessageConvertersConfiguration.java

示例13: noGson

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Test
public void noGson() throws Exception {
	this.context.register(HttpMessageConvertersAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBeansOfType(Gson.class).isEmpty()).isTrue();
	assertThat(this.context.getBeansOfType(GsonHttpMessageConverter.class).isEmpty())
			.isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:HttpMessageConvertersAutoConfigurationTests.java

示例14: defaultGsonConverter

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Test
public void defaultGsonConverter() throws Exception {
	this.context.register(GsonAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class);
	this.context.refresh();
	assertConverterBeanExists(GsonHttpMessageConverter.class,
			"gsonHttpMessageConverter");

	assertConverterBeanRegisteredWithHttpMessageConverters(
			GsonHttpMessageConverter.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:HttpMessageConvertersAutoConfigurationTests.java

示例15: jacksonIsPreferredByDefaultWhenBothGsonAndJacksonAreAvailable

import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入依赖的package包/类
@Test
public void jacksonIsPreferredByDefaultWhenBothGsonAndJacksonAreAvailable() {
	this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class);
	this.context.refresh();
	assertConverterBeanExists(MappingJackson2HttpMessageConverter.class,
			"mappingJackson2HttpMessageConverter");
	assertConverterBeanRegisteredWithHttpMessageConverters(
			MappingJackson2HttpMessageConverter.class);
	assertThat(this.context.getBeansOfType(GsonHttpMessageConverter.class)).isEmpty();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:HttpMessageConvertersAutoConfigurationTests.java


注:本文中的org.springframework.http.converter.json.GsonHttpMessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。