Search in sources :

Example 6 with ConfigurableConversionService

use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-data-mongodb by spring-projects.

the class MongoConvertersUnitTests method convertsUrisToString.

// DATAMONGO-2210
@Test
void convertsUrisToString() {
    MongoCustomConversions conversions = new MongoCustomConversions();
    assertThat(conversions.getSimpleTypeHolder().isSimpleType(URI.class)).isTrue();
    ConfigurableConversionService conversionService = new DefaultConversionService();
    conversions.registerConvertersIn(conversionService);
    assertThat(conversionService.convert(URI.create("/segment"), String.class)).isEqualTo("/segment");
    assertThat(conversionService.convert("/segment", URI.class)).isEqualTo(URI.create("/segment"));
}
Also used : ConfigurableConversionService(org.springframework.core.convert.support.ConfigurableConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.jupiter.api.Test)

Example 7 with ConfigurableConversionService

use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-framework by spring-projects.

the class AbstractPropertyResolver method getConversionService.

@Override
public ConfigurableConversionService getConversionService() {
    // Need to provide an independent DefaultConversionService, not the
    // shared DefaultConversionService used by PropertySourcesPropertyResolver.
    ConfigurableConversionService cs = this.conversionService;
    if (cs == null) {
        synchronized (this) {
            cs = this.conversionService;
            if (cs == null) {
                cs = new DefaultConversionService();
                this.conversionService = cs;
            }
        }
    }
    return cs;
}
Also used : ConfigurableConversionService(org.springframework.core.convert.support.ConfigurableConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService)

Aggregations

ConfigurableConversionService (org.springframework.core.convert.support.ConfigurableConversionService)7 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)4 Test (org.junit.jupiter.api.Test)3 ConversionService (org.springframework.core.convert.ConversionService)3 ApplicationConversionService (org.springframework.boot.convert.ApplicationConversionService)2 StandardEnvironment (org.springframework.core.env.StandardEnvironment)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 DateFormat (java.text.DateFormat)1 Format (java.text.Format)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Locale (java.util.Locale)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Matchers (org.hamcrest.Matchers)1 DateTime (org.joda.time.DateTime)1 Assert.assertThat (org.junit.Assert.assertThat)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1