Java Code Examples for org.springframework.format.FormatterRegistry

The following examples show how to use org.springframework.format.FormatterRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Add formatters appropriate for most environments: including number formatters,
 * JSR-354 Money & Currency formatters, JSR-310 Date-Time and/or Joda-Time formatters,
 * depending on the presence of the corresponding API on the classpath.
 * @param formatterRegistry the service to register default formatters with
 */
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
	// Default handling of number values
	formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());

	// Default handling of monetary values
	if (jsr354Present) {
		formatterRegistry.addFormatter(new CurrencyUnitFormatter());
		formatterRegistry.addFormatter(new MonetaryAmountFormatter());
		formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
	}

	// Default handling of date-time values
	if (jsr310Present) {
		// just handling JSR-310 specific date and time types
		new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	if (jodaTimePresent) {
		// handles Joda-specific types as well as Date, Calendar, Long
		new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
	}
	else {
		// regular DateFormat-based Date, Calendar, Long converters
		new DateFormatterRegistrar().registerFormatters(formatterRegistry);
	}
}
 
Example 2
Source Project: spring-analysis-note   Source File: JodaTimeFormatterRegistrar.java    License: MIT License 5 votes vote down vote up
private void addFormatterForFields(FormatterRegistry registry, Printer<?> printer,
		Parser<?> parser, Class<?>... fieldTypes) {

	for (Class<?> fieldType : fieldTypes) {
		registry.addFormatterForFieldType(fieldType, printer, parser);
	}
}
 
Example 3
Source Project: spring-analysis-note   Source File: DateFormatterRegistrar.java    License: MIT License 5 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	addDateConverters(registry);
	registry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());

	// In order to retain back compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.dateFormatter != null) {
		registry.addFormatter(this.dateFormatter);
		registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
	}
}
 
Example 4
Source Project: tutorials   Source File: WebConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverter(new StringToEmployeeConverter());
    registry.addConverter(new StringToEnumConverter());
    registry.addConverterFactory(new StringToAbstractEntityConverterFactory());
    registry.addConverter(new GenericBigDecimalConverter());
}
 
Example 5
Source Project: onetwo   Source File: BootMvcConfigurerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	
	registry.removeConvertible(String.class, Enum.class);
	registry.addConverterFactory(new IntStringValueToEnumConverterFactory());
	
	registry.addConverterFactory(new IntegerToEnumConverterFactory());
}
 
Example 6
Source Project: find   Source File: DispatcherServletConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void addFormatters(final FormatterRegistry registry) {
    if(converters != null) {
        for(final Converter<?, ?> converter : converters) {
            registry.addConverter(converter);
        }
    }

    registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
 
Example 7
Source Project: java-technology-stack   Source File: DateFormatterRegistrar.java    License: MIT License 5 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	addDateConverters(registry);
	registry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());

	// In order to retain back compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.dateFormatter != null) {
		registry.addFormatter(this.dateFormatter);
		registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
	}
}
 
Example 8
@Override
public void addFormatters(FormatterRegistry registry) {
	registry.addConverter(new Converter<TestBean, String>() {
		@Override
		public String convert(TestBean source) {
			return "converted";
		}
	});
}
 
Example 9
public static void registerAdditionalFormatters(FormatterRegistry registry) {
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
 
Example 10
Source Project: spring-analysis-note   Source File: JodaTimeFormatterRegistrar.java    License: MIT License 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	JodaTimeConverters.registerConverters(registry);

	DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
	DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
	DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateFormatter),
			new LocalDateParser(dateFormatter),
			LocalDate.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(timeFormatter),
			new LocalTimeParser(timeFormatter),
			LocalTime.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateTimeFormatter),
			new LocalDateTimeParser(dateTimeFormatter),
			LocalDateTime.class);

	addFormatterForFields(registry,
			new ReadableInstantPrinter(dateTimeFormatter),
			new DateTimeParser(dateTimeFormatter),
			ReadableInstant.class);

	// In order to retain backwards compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.formatters.containsKey(Type.DATE_TIME)) {
		addFormatterForFields(registry,
				new ReadableInstantPrinter(dateTimeFormatter),
				new DateTimeParser(dateTimeFormatter),
				Date.class, Calendar.class);
	}

	registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
	registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());

	registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
 
Example 11
Source Project: spring-analysis-note   Source File: DateTimeFormatterRegistrar.java    License: MIT License 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	DateTimeConverters.registerConverters(registry);

	DateTimeFormatter df = getFormatter(Type.DATE);
	DateTimeFormatter tf = getFormatter(Type.TIME);
	DateTimeFormatter dtf = getFormatter(Type.DATE_TIME);

	// Efficient ISO_LOCAL_* variants for printing since they are twice as fast...

	registry.addFormatterForFieldType(LocalDate.class,
			new TemporalAccessorPrinter(
					df == DateTimeFormatter.ISO_DATE ? DateTimeFormatter.ISO_LOCAL_DATE : df),
			new TemporalAccessorParser(LocalDate.class, df));

	registry.addFormatterForFieldType(LocalTime.class,
			new TemporalAccessorPrinter(
					tf == DateTimeFormatter.ISO_TIME ? DateTimeFormatter.ISO_LOCAL_TIME : tf),
			new TemporalAccessorParser(LocalTime.class, tf));

	registry.addFormatterForFieldType(LocalDateTime.class,
			new TemporalAccessorPrinter(
					dtf == DateTimeFormatter.ISO_DATE_TIME ? DateTimeFormatter.ISO_LOCAL_DATE_TIME : dtf),
			new TemporalAccessorParser(LocalDateTime.class, dtf));

	registry.addFormatterForFieldType(ZonedDateTime.class,
			new TemporalAccessorPrinter(dtf),
			new TemporalAccessorParser(ZonedDateTime.class, dtf));

	registry.addFormatterForFieldType(OffsetDateTime.class,
			new TemporalAccessorPrinter(dtf),
			new TemporalAccessorParser(OffsetDateTime.class, dtf));

	registry.addFormatterForFieldType(OffsetTime.class,
			new TemporalAccessorPrinter(tf),
			new TemporalAccessorParser(OffsetTime.class, tf));

	registry.addFormatterForFieldType(Instant.class, new InstantFormatter());
	registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
	registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
	registry.addFormatterForFieldType(Year.class, new YearFormatter());
	registry.addFormatterForFieldType(Month.class, new MonthFormatter());
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());

	registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory());
}
 
Example 12
Source Project: jfilter   Source File: FilterRegister.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    // Do nothing
}
 
Example 13
Source Project: spring-analysis-note   Source File: WebFluxConfigurerComposite.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	this.delegates.forEach(delegate -> delegate.addFormatters(registry));
}
 
Example 14
@Override
protected void addFormatters(FormatterRegistry registry) {
	this.configurers.addFormatters(registry);
}
 
Example 15
@Override
protected void installFormatters(FormatterRegistry registry) {
	super.installFormatters(registry);
	// Register survey converters and formatters
}
 
Example 16
@Override
protected void addFormatters(FormatterRegistry registry) {
	this.configurers.addFormatters(registry);
}
 
Example 17
Source Project: spring-analysis-note   Source File: WebMvcConfigurerComposite.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	for (WebMvcConfigurer delegate : this.delegates) {
		delegate.addFormatters(registry);
	}
}
 
Example 18
@Override
public void addFormatters(FormatterRegistry registry) {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(registry);
}
 
Example 19
Source Project: tutorials   Source File: DateTimeFormatConfiguration.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(registry);
}
 
Example 20
Source Project: spring-analysis-note   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public DefaultControllerSpec formatters(Consumer<FormatterRegistry> consumer) {
	this.configurer.formattersConsumer = consumer;
	return this;
}
 
Example 21
Source Project: spring-analysis-note   Source File: DefaultControllerSpec.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	if (this.formattersConsumer != null) {
		this.formattersConsumer.accept(registry);
	}
}
 
Example 22
@Override
public void addFormatters(FormatterRegistry registry) {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(registry);
}
 
Example 23
Source Project: ZTuoExchange_framework   Source File: ApplicationConfig.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverterFactory(new OrdinalToEnumConverterFactory());
    super.addFormatters(registry);
}
 
Example 24
Source Project: bearchoke   Source File: WebMvcConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory());
}
 
Example 25
Source Project: ZTuoExchange_framework   Source File: ApplicationConfig.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverterFactory(new OrdinalToEnumConverterFactory());
    super.addFormatters(registry);
}
 
Example 26
@Override
public void addFormatters(FormatterRegistry registry) {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(registry);
}
 
Example 27
Source Project: springdoc-openapi   Source File: WebMvcConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
	ApplicationConversionService.configure(registry);
}
 
Example 28
Source Project: alchemy   Source File: DateTimeFormatConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(registry);
}
 
Example 29
Source Project: zfile   Source File: WebMvcConfig.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverter(new StorageTypeEnumDeSerializerConvert());
}
 
Example 30
Source Project: ZTuoExchange_framework   Source File: ApplicationConfig.java    License: MIT License 4 votes vote down vote up
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverterFactory(new OrdinalToEnumConverterFactory());
    super.addFormatters(registry);
}