Example usage for org.springframework.data.convert JodaTimeConverters getConvertersToRegister

List of usage examples for org.springframework.data.convert JodaTimeConverters getConvertersToRegister

Introduction

In this page you can find the example usage for org.springframework.data.convert JodaTimeConverters getConvertersToRegister.

Prototype

public static Collection<Converter<?, ?>> getConvertersToRegister() 

Source Link

Document

Returns the converters to be registered.

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);
    }/*from   w ww  .  j a  v  a  2 s.  co  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;
}