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

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

Introduction

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

Prototype

public DefaultFormattingConversionService(boolean registerDefaultFormatters) 

Source Link

Document

Create a new DefaultFormattingConversionService with the set of DefaultConversionService#addDefaultConverters default converters and, based on the value of registerDefaultFormatters , the set of #addDefaultFormatters default formatters .

Usage

From source file:de.asgarbayli.rashad.hbd.config.Config.java

@Bean
public FormattingConversionService conversionService() {
    // Create new one and disable defaults
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false);

    // Activate @NumberFormat
    conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

    // Activate @DateTimeFormat
    DateFormatterRegistrar dateFormatterRegistrar = new DateFormatterRegistrar();
    dateFormatterRegistrar.setFormatter(new DateFormatter("yyyy-MM-dd"));
    dateFormatterRegistrar.registerFormatters(conversionService);

    // Return new conversion service to use it as default
    return conversionService;
}

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  .ja v  a 2  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:com.xpeppers.phonedirectory.config.WebAppConfig.java

@Bean
public FormattingConversionService mvcConversionService() {
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false);
    addFormattersForFieldAnnotation(conversionService);
    DateFormatterRegistrar registrar = new DateFormatterRegistrar();
    registrar.setFormatter(new DateFormatter(GLOBAL_DATE_FORMAT));
    registrar.registerFormatters(conversionService);
    return conversionService;
}

From source file:br.com.semanticwot.cd.conf.AppWebConfiguration.java

@Bean
public FormattingConversionService mvcConversionService() { // Mtodo para setar padres de converso
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(true);

    DateFormatterRegistrar registrar = new DateFormatterRegistrar();
    registrar.setFormatter(new DateFormatter("yyyy-MM-dd"));
    registrar.registerFormatters(conversionService);
    return conversionService;
}