本文整理汇总了Java中org.springframework.http.converter.json.GsonHttpMessageConverter.setGson方法的典型用法代码示例。如果您正苦于以下问题:Java GsonHttpMessageConverter.setGson方法的具体用法?Java GsonHttpMessageConverter.setGson怎么用?Java GsonHttpMessageConverter.setGson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.converter.json.GsonHttpMessageConverter
的用法示例。
在下文中一共展示了GsonHttpMessageConverter.setGson方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}
};
}
示例6: 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);
}
示例7: 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
示例8: createGsonHttpMessageConverter
import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入方法依赖的package包/类
private GsonHttpMessageConverter createGsonHttpMessageConverter() {
Gson gsonWithConverter = new GsonBuilder()
.registerTypeHierarchyAdapter(HashableEntity.class, new HashIdJsonAdapter())
.registerTypeAdapter(LocalDate.class, new LocalDateJsonAdapter())
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonAdapter())
.create();
GsonHttpMessageConverter gsonConverter = new GsonHttpMessageConverter();
gsonConverter.setGson(gsonWithConverter);
return gsonConverter;
}
示例9: createGsonHttpMessageConverter
import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入方法依赖的package包/类
@Bean
public GsonHttpMessageConverter createGsonHttpMessageConverter() {
Gson gson = new GsonBuilder()
.setDateFormat(gsonDateFormat)
.setExclusionStrategies(new AnnotationExeclusionStrategy())
.create();
GsonHttpMessageConverter gsonConverter = new GsonHttpMessageConverter();
gsonConverter.setGson(gson);
return gsonConverter;
}
示例10: customGsonMessageConverter
import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入方法依赖的package包/类
@Bean
public GsonHttpMessageConverter customGsonMessageConverter(Gson gson) {
GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
converter.setGson(gson);
return converter;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:HttpMessageConvertersAutoConfigurationTests.java
示例11: gsonHttpMessageConverter
import org.springframework.http.converter.json.GsonHttpMessageConverter; //导入方法依赖的package包/类
@Bean
public GsonHttpMessageConverter gsonHttpMessageConverter() {
GsonHttpMessageConverter converter = new GsonHttpMessageConverterWithValidate();
converter.setGson(gson());
return converter;
}