@Test public void defaultGsonConverter() throws Exception { this.context.register(GsonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class); this.context.refresh(); assertConverterBeanExists(GsonHttpMessageConverter.class, "gsonHttpMessageConverter"); assertConverterBeanRegisteredWithHttpMessageConverters( GsonHttpMessageConverter.class); }
@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(); }
@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(); }
@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); }
private void load(Class<?> config, String... environment) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, environment); if (config != null) { context.register(config); } context.register(GsonAutoConfiguration.class, JestAutoConfiguration.class); context.refresh(); this.context = context; }
@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()); }
@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()); }