Java 类org.springframework.http.converter.json.GsonHttpMessageConverter 实例源码

项目:spring4-understanding    文件:AllEncompassingFormHttpMessageConverter.java   
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());
    }
}
项目:runelite    文件:CustomConfiguration.java   
@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);
}
项目:AndroidFT    文件:AbstractRequest.java   
/** 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);
}
项目:PhishStream    文件:PhishInGsonSpringAndroidSpiceService.java   
@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;
}
项目:holon-json    文件:SpringGsonConfiguration.java   
/**
 * 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();
}
项目:logistimo-web-service    文件:RestConfig.java   
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;
}
项目:stuffEngine    文件:WebAppConfig.java   
@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);
}
项目:apollo-custom    文件:HttpMessageConverterConfiguration.java   
@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;
    }
  };
}
项目:apollo    文件:HttpMessageConverterConfiguration.java   
@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;
    }
  };
}
项目:spring4-understanding    文件:RestTemplate.java   
/**
 * 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());
    }
}
项目:WebIDE-Backend    文件:WebConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new ResourceHttpMessageConverter());

    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();

    converter.setGson(gson());
    converters.add(converter);
}
项目:radiocom-android    文件:ServiceStation.java   
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();
    }
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:GsonHttpMessageConvertersConfiguration.java   
@Bean
@ConditionalOnMissingBean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    return converter;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void defaultGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void gsonCanBePreferredWhenBothGsonAndJacksonAreAvailable() {
    this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.http.converters.preferred-json-mapper:gson");
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");
    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
    assertThat(this.context.getBeansOfType(MappingJackson2HttpMessageConverter.class))
            .isEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void customGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class, GsonConverterConfig.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "customGsonMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:spring-boot-concourse    文件:GsonHttpMessageConvertersConfiguration.java   
@Bean
@ConditionalOnMissingBean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    return converter;
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@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();
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void defaultGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@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();
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void gsonCanBePreferredWhenBothGsonAndJacksonAreAvailable() {
    this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.http.converters.preferred-json-mapper:gson");
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");
    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
    assertThat(this.context.getBeansOfType(MappingJackson2HttpMessageConverter.class))
            .isEmpty();
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void customGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class, GsonConverterConfig.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "customGsonMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:contestparser    文件:GsonHttpMessageConvertersConfiguration.java   
@Bean
@ConditionalOnMissingBean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    return converter;
}
项目:contestparser    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void noGson() throws Exception {
    this.context.register(HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertTrue(this.context.getBeansOfType(Gson.class).isEmpty());
    assertTrue(this.context.getBeansOfType(GsonHttpMessageConverter.class).isEmpty());
}
项目:contestparser    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void defaultGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:contestparser    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void jacksonIsPreferredByDefaultWhenBothGsonAndJacksonAreAvailable() {
    this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(MappingJackson2HttpMessageConverter.class,
            "mappingJackson2HttpMessageConverter");
    assertConverterBeanRegisteredWithHttpMessageConverters(
            MappingJackson2HttpMessageConverter.class);
    assertEquals(0,
            this.context.getBeansOfType(GsonHttpMessageConverter.class).size());
}
项目:contestparser    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void gsonCanBePreferredWhenBothGsonAndJacksonAreAvailable() {
    this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.http.converters.preferred-json-mapper:gson");
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "gsonHttpMessageConverter");
    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
    assertEquals(0, this.context
            .getBeansOfType(MappingJackson2HttpMessageConverter.class).size());
}
项目:contestparser    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Test
public void customGsonConverter() throws Exception {
    this.context.register(GsonAutoConfiguration.class, GsonConverterConfig.class,
            HttpMessageConvertersAutoConfiguration.class);
    this.context.refresh();
    assertConverterBeanExists(GsonHttpMessageConverter.class,
            "customGsonMessageConverter");

    assertConverterBeanRegisteredWithHttpMessageConverters(
            GsonHttpMessageConverter.class);
}
项目:JSAndroidApp    文件:RestMethods.java   
public static RestTemplate getRestTemplate()
{
    RestTemplate restTemplate = new RestTemplate();

    restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
    return restTemplate;
}
项目:STLCourts-api    文件:GsonConfiguration.java   
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;
}
项目:spring-scaffy    文件:DefaultWebConfig.java   
@Bean
public GsonHttpMessageConverter createGsonHttpMessageConverter() {

    Gson gson = new GsonBuilder()
    .setDateFormat(gsonDateFormat)
    .setExclusionStrategies(new AnnotationExeclusionStrategy())
    .create();

    GsonHttpMessageConverter gsonConverter = new GsonHttpMessageConverter();

    gsonConverter.setGson(gson);

    return gsonConverter;
}
项目:codekvast    文件:WebappControllerTest.java   
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.webappController = new WebappController(webappService, settings);
    this.mockMvc = MockMvcBuilders.standaloneSetup(webappController)
                                  .setMessageConverters(new GsonHttpMessageConverter(), new StringHttpMessageConverter())
                                  .build();
}
项目:codekvast    文件:AgentControllerTest.java   
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.mockMvc = MockMvcBuilders.standaloneSetup(agentController)
                                  .setMessageConverters(new GsonHttpMessageConverter(), new StringHttpMessageConverter())
                                  .build();
}
项目:StockAnalyze    文件:GaeRestTemplate.java   
public GaeRestTemplate(Type responseType, ResponseErrorHandler errorHandler, List<ClientHttpRequestInterceptor> interceptors) {
    this.setErrorHandler(errorHandler);
    this.setInterceptors(interceptors);

    final GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    if (responseType != null) {
        converter.setType(responseType);
    }

    this.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Bean
public GsonHttpMessageConverter customGsonMessageConverter(Gson gson) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    return converter;
}
项目:eiffel-remrem-generate    文件:GsonHttpMessageConverterConfig.java   
@Bean
public GsonHttpMessageConverter gsonHttpMessageConverter() {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverterWithValidate();
    converter.setGson(gson());
    return converter;
}
项目:spring-boot-concourse    文件:HttpMessageConvertersAutoConfigurationTests.java   
@Bean
public GsonHttpMessageConverter customGsonMessageConverter(Gson gson) {
    GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
    converter.setGson(gson);
    return converter;
}
项目:stool    文件:WebMvcConfiguration.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new GsonHttpMessageConverter());
}