List of usage examples for org.springframework.format.number NumberFormatAnnotationFormatterFactory NumberFormatAnnotationFormatterFactory
NumberFormatAnnotationFormatterFactory
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); }// w ww .j a v a2 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
private void addFormattersForFieldAnnotation(DefaultFormattingConversionService conversionService) { conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); conversionService.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory()); }