Example usage for org.springframework.format.support DefaultFormattingConversionService addConverter

List of usage examples for org.springframework.format.support DefaultFormattingConversionService addConverter

Introduction

In this page you can find the example usage for org.springframework.format.support DefaultFormattingConversionService addConverter.

Prototype

@Override
    public void addConverter(Converter<?, ?> converter) 

Source Link

Usage

From source file:de.cpoepke.demos.neo4j.querydsl.config.SpringConfiguration.java

@Bean
public DefaultFormattingConversionService conversionService() {

    // Use the DefaultFormattingConversionService but do not register defaults
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false);

    // Ensure @NumberFormat is still supported
    conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

    // Joda Time Converter
    for (Converter<?, ?> converter : JodaTimeConverters.getConvertersToRegister()) {
        conversionService.addConverter(converter);
    }/* ww  w  .  j a va2  s. c  o  m*/
    conversionService.addConverter(new DateMidnightToStringConverter());
    conversionService.addConverter(new StringToDateMidnightConverter());
    conversionService.addConverter(new DateMidnightToLongConverter());
    conversionService.addConverter(new LongToDateMidnightConverter());

    // Register date conversion with a specific global format
    JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(conversionService);

    return conversionService;
}

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.java

@Bean
@Qualifier//from  w w  w  .ja  va 2 s  . co  m
public DefaultFormattingConversionService defaultConversionService() {

    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    // Add Spring Data Commons formatters
    conversionService.addConverter(uriToEntityConverter(conversionService));
    addFormatters(conversionService);

    configurerDelegate.configureConversionService(conversionService);
    configureConversionService(conversionService);

    return conversionService;
}