Java Examples for org.springframework.format.support.DefaultFormattingConversionService

The following java examples will help you to understand the usage of org.springframework.format.support.DefaultFormattingConversionService. These source code samples are taken from different open source projects.

Example 1
Project: fullstop-master  File: RestControllerTestSupport.java View source code
protected void configure(final StandaloneMockMvcBuilder mockMvcBuilder) {
    mockMvcBuilder.setCustomArgumentResolvers(mockMvcCustomArgumentResolvers());
    mockMvcBuilder.setMessageConverters(mockMvcMessageConverters());
    final DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    mockMvcBuilder.setConversionService(conversionService);
}
Example 2
Project: cas-master  File: CasCoreUtilConfiguration.java View source code
@PostConstruct
public void init() {
    final ConfigurableApplicationContext ctx = applicationContextProvider().getConfigurableApplicationContext();
    final DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(true);
    conversionService.setEmbeddedValueResolver(new CasConfigurationEmbeddedValueResolver(ctx));
    ctx.getEnvironment().setConversionService(conversionService);
    final ConfigurableEnvironment env = (ConfigurableEnvironment) ctx.getParent().getEnvironment();
    env.setConversionService(conversionService);
    final ConverterRegistry registry = (ConverterRegistry) DefaultConversionService.getSharedInstance();
    registry.addConverter(zonedDateTimeToStringConverter());
}
Example 3
Project: extdirectspring-master  File: ConfigurationService.java View source code
@Override
public void afterPropertiesSet() {
    if (this.configuration == null) {
        this.configuration = new Configuration();
    }
    if (this.configuration.getJsonHandler() != null) {
        this.jsonHandler = this.configuration.getJsonHandler();
    }
    if (this.jsonHandler == null) {
        this.jsonHandler = new JsonHandler();
    }
    if (this.routerExceptionHandler == null) {
        this.routerExceptionHandler = new DefaultRouterExceptionHandler(this);
    }
    if (this.configuration.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT && this.configuration.getBatchedMethodsExecutorService() == null) {
        this.configuration.setBatchedMethodsExecutorService(Executors.newFixedThreadPool(5));
    }
    if (this.configuration.getConversionService() == null) {
        Map<String, ConversionService> conversionServices = this.context.getBeansOfType(ConversionService.class);
        if (conversionServices.isEmpty()) {
            this.configuration.setConversionService(new DefaultFormattingConversionService());
        } else if (conversionServices.size() == 1) {
            this.configuration.setConversionService(conversionServices.values().iterator().next());
        } else {
            if (conversionServices.containsKey("mvcConversionService")) {
                this.configuration.setConversionService(conversionServices.get("mvcConversionService"));
            } else {
                for (ConversionService conversionService : conversionServices.values()) {
                    if (conversionService instanceof FormattingConversionService) {
                        this.configuration.setConversionService(conversionService);
                        break;
                    }
                }
                if (this.configuration.getConversionService() == null) {
                    this.configuration.setConversionService(conversionServices.values().iterator().next());
                }
            }
        }
    }
    Collection<WebArgumentResolver> webResolvers = this.context.getBeansOfType(WebArgumentResolver.class).values();
    this.parametersResolver = new ParametersResolver(this.configuration.getConversionService(), this.jsonHandler, webResolvers);
}
Example 4
Project: spring-data-commons-master  File: CrudRepositoryInvokerUnitTests.java View source code
@SuppressWarnings({ "rawtypes", "unchecked" })
private static RepositoryInvoker getInvokerFor(Object repository, VerifyingMethodInterceptor interceptor) {
    Object proxy = getVerifyingRepositoryProxy(repository, interceptor);
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(repository.getClass().getInterfaces()[0]);
    GenericConversionService conversionService = new DefaultFormattingConversionService();
    return new CrudRepositoryInvoker((CrudRepository) proxy, metadata, conversionService);
}
Example 5
Project: spring-framework-issues-master  File: ReproTests.java View source code
@Test
public void stringToString() {
    TestMap<String, String> source = new TestMap<String, String>();
    source.init();
    source.put("key", "value");
    source.put("key", null);
    TestMapConsumer target = new TestMapConsumer();
    WebDataBinder dataBinder = new WebDataBinder(target, "");
    dataBinder.setConversionService(new DefaultFormattingConversionService());
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("testMap", source);
    dataBinder.bind(pvs);
    // FallbackObjectToStringConverter for key-value pairs
    assertSame(source.keySet().iterator().next(), target.getTestMap().keySet().iterator().next());
    assertSame(source.values().iterator().next(), target.getTestMap().values().iterator().next());
    assertTrue(target.getTestMap().isInitialized());
}
Example 6
Project: enzymeportal-master  File: ApplicationContext.java View source code
@Bean
public FormattingConversionService formattingConversionService() {
    // Use the DefaultFormattingConversionService but do not register defaults
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false);
    // Ensure @NumberFormat is still supported
    conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
    // Register date conversion with a specific global format
    DateFormatterRegistrar registrar = new DateFormatterRegistrar();
    registrar.setFormatter(new DateFormatter("EEE, d MMM yyyy"));
    registrar.setFormatter(new DateFormatter("d MMMMM yyyy"));
    registrar.setFormatter(new DateFormatter("dd MMMMM yyyy - HH:mm"));
    registrar.registerFormatters(conversionService);
    return conversionService;
}
Example 7
Project: spring-boot-master  File: BinderConversionService.java View source code
private static ConversionService createAdditionalConversionService() {
    DefaultFormattingConversionService service = new DefaultFormattingConversionService();
    DefaultConversionService.addCollectionConverters(service);
    service.addConverterFactory(new StringToEnumConverterFactory());
    service.addConverter(new StringToCharArrayConverter());
    service.addConverter(new StringToInetAddressConverter());
    service.addConverter(new InetAddressToStringConverter());
    service.addConverter(new PropertyEditorConverter());
    DateFormatterRegistrar registrar = new DateFormatterRegistrar();
    DateFormatter formatter = new DateFormatter();
    formatter.setIso(DateTimeFormat.ISO.DATE_TIME);
    registrar.setFormatter(formatter);
    registrar.registerFormatters(service);
    return service;
}
Example 8
Project: spring-data-rest-master  File: RepositoryRestMvcConfiguration.java View source code
@Bean
@Qualifier
public DefaultFormattingConversionService defaultConversionService() {
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    // Add Spring Data Commons formatters
    conversionService.addConverter(uriToEntityConverter(conversionService));
    addFormatters(conversionService);
    configurerDelegate.configureConversionService(conversionService);
    return conversionService;
}
Example 9
Project: spring-framework-master  File: DataBinderTests.java View source code
@Test
public void testConversionWithInappropriateStringEditor() {
    DataBinder dataBinder = new DataBinder(null);
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    dataBinder.setConversionService(conversionService);
    dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    NameBean bean = new NameBean("Fred");
    assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
    conversionService.addConverter(new NameBeanConverter());
    assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
Example 10
Project: spring-reactive-master  File: ViewResolutionResultHandlerTests.java View source code
private ViewResolutionResultHandler createResultHandler(List<View> defaultViews, ViewResolver... resolvers) {
    FormattingConversionService service = new DefaultFormattingConversionService();
    service.addConverter(new MonoToCompletableFutureConverter());
    service.addConverter(new ReactorToRxJava1Converter());
    List<ViewResolver> resolverList = Arrays.asList(resolvers);
    ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolverList, service);
    handler.setDefaultViews(defaultViews);
    return handler;
}
Example 11
Project: processFlowProvision-master  File: SpringDataBinderTest.java View source code
@Test
public void testBindListWithGenericType() throws Exception {
    MutablePropertyValues values = new MutablePropertyValues();
    values.addPropertyValue("USERACTION", "RELEASE");
    values.addPropertyValue("ATTACHMENTS[0].attachSequence", "1");
    values.addPropertyValue("ATTACHMENTS[0].attachStatus", "var_status");
    values.addPropertyValue("ATTACHMENTS[0].attachmentID", "var_attachmentID");
    values.addPropertyValue("ATTACHMENTS[0].attachmentDate", "15/02/2012");
    AttachmentListResultBean target = new AttachmentListResultBean();
    DataBinder binder = new DataBinder(target);
    // set the conversion service to convert the date
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    conversionService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
    binder.setConversionService(conversionService);
    binder.bind(values);
    System.out.println(target);
    assertEquals("RELEASE", target.getUSERACTION());
    List attachmentList = target.getATTACHMENTS();
    assertNotNull(attachmentList);
    assertEquals(1, attachmentList.size());
    AttachmentInfo info = (AttachmentInfo) attachmentList.get(0);
    assertEquals("var_attachmentID", info.getAttachmentID());
    assertEquals("var_status", info.getAttachStatus());
    assertEquals(1L, info.getAttachSequence());
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    assertEquals("15/02/2012", dateFormat.format(info.getAttachmentDate()));
}
Example 12
Project: spring-integration-master  File: TestUtils.java View source code
/**
	 * Create a {@link TestApplicationContext} instance
	 * supplied with the basic Spring Integration infrastructure.
	 * @return the {@link TestApplicationContext} instance
	 */
public static TestApplicationContext createTestApplicationContext() {
    TestApplicationContext context = new TestApplicationContext();
    ErrorHandler errorHandler = new MessagePublishingErrorHandler(context);
    ThreadPoolTaskScheduler scheduler = createTaskScheduler(10);
    scheduler.setErrorHandler(errorHandler);
    registerBean("taskScheduler", scheduler, context);
    registerBean("integrationConversionService", new DefaultFormattingConversionService(), context);
    return context;
}
Example 13
Project: saos-master  File: JudgmentsControllerTest.java View source code
@Before
public void setUp() throws Exception {
    testObjectContext = testPersistenceObjectFactory.createTestObjectContext();
    clearAndIndexJudgmentsInSolr(testObjectContext);
    JudgmentsController judgmentsController = new JudgmentsController();
    judgmentsController.setApiSearchService(apiSearchService);
    judgmentsController.setListSuccessRepresentationBuilder(listSuccessRepresentationBuilder);
    judgmentsController.setParametersExtractor(parametersExtractor);
    judgmentsController.setJsonFormatter(jsonFormatter);
    judgmentsController.setMinPageSize(3);
    judgmentsController.setMaxPageSize(50);
    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    conversionService.addFormatterForFieldAnnotation(new LawJournalEntryCodeFormatterFactory(lawJournalEntryCodeExtractor));
    mockMvc = standaloneSetup(judgmentsController).addInterceptors(new AccessControlHeaderHandlerInterceptor()).addInterceptors(new RestrictParamsHandlerInterceptor()).setConversionService(conversionService).build();
}
Example 14
Project: terasoluna-gfw-master  File: ObjectToMapConverterTest.java View source code
@Test
public void testConvert5_at_DateTimeFormat() throws Exception {
    LocalDate date1 = new LocalDate(2015, 4, 1);
    LocalDate localDate1 = new LocalDate(2015, 6, 10);
    LocalDate date2 = new LocalDate(2015, 5, 1);
    LocalDate localDate2 = new LocalDate(2015, 7, 10);
    Map<String, String> map = converter.convert(new DateForm5(date1.toDate(), localDate1, new DateFormItem5(date2.toDate(), localDate2)));
    assertThat(map.size(), is(4));
    assertThat(map, hasEntry("date", "2015-04-01"));
    assertThat(map, hasEntry("localDate", "2015-06-10"));
    assertThat(map, hasEntry("item.date", "2015-05-01"));
    assertThat(map, hasEntry("item.localDate", "2015-07-10"));
    DateForm5 form = new DateForm5();
    WebDataBinder binder = new WebDataBinder(form);
    binder.setConversionService(new DefaultFormattingConversionService());
    binder.bind(new MutablePropertyValues(map));
    assertThat(form.getDate(), is(date1.toDate()));
    assertThat(form.getLocalDate(), is(localDate1));
    assertThat(form.getItem().getDate(), is(date2.toDate()));
    assertThat(form.getItem().getLocalDate(), is(localDate2));
}
Example 15
Project: spring-mvc-showcase-master  File: RedirectControllerTests.java View source code
@Before
public void setup() throws Exception {
    this.mockMvc = standaloneSetup(new RedirectController(new DefaultFormattingConversionService())).alwaysExpect(status().isMovedTemporarily()).build();
}
Example 16
Project: spring-cloud-netflix-master  File: FeignClientsConfiguration.java View source code
@Bean
public FormattingConversionService feignConversionService() {
    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    for (FeignFormatterRegistrar feignFormatterRegistrar : feignFormatterRegistrars) {
        feignFormatterRegistrar.registerFormatters(conversionService);
    }
    return conversionService;
}