Package org.springframework.core.convert.support

Examples of org.springframework.core.convert.support.GenericConversionService.addConverter()


  @InitBinder
  void registerConverters(WebDataBinder binder) {
    if (binder.getConversionService() instanceof GenericConversionService) {
      GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
      conversionService.addConverter(getLoanSharkConverter());
    }
  }

  @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
  @ResponseBody
View Full Code Here


  public static class Config {

    @Bean
    public ConversionService webSocketConversionService() {
      GenericConversionService conversionService = new DefaultConversionService();
      conversionService.addConverter(new MyTypeToStringConverter());
      conversionService.addConverter(new MyTypeToBytesConverter());
      conversionService.addConverter(new StringToMyTypeConverter());
      conversionService.addConverter(new BytesToMyTypeConverter());
      return conversionService;
    }
View Full Code Here

    @Bean
    public ConversionService webSocketConversionService() {
      GenericConversionService conversionService = new DefaultConversionService();
      conversionService.addConverter(new MyTypeToStringConverter());
      conversionService.addConverter(new MyTypeToBytesConverter());
      conversionService.addConverter(new StringToMyTypeConverter());
      conversionService.addConverter(new BytesToMyTypeConverter());
      return conversionService;
    }
View Full Code Here

    @Bean
    public ConversionService webSocketConversionService() {
      GenericConversionService conversionService = new DefaultConversionService();
      conversionService.addConverter(new MyTypeToStringConverter());
      conversionService.addConverter(new MyTypeToBytesConverter());
      conversionService.addConverter(new StringToMyTypeConverter());
      conversionService.addConverter(new BytesToMyTypeConverter());
      return conversionService;
    }

  }
View Full Code Here

    public ConversionService webSocketConversionService() {
      GenericConversionService conversionService = new DefaultConversionService();
      conversionService.addConverter(new MyTypeToStringConverter());
      conversionService.addConverter(new MyTypeToBytesConverter());
      conversionService.addConverter(new StringToMyTypeConverter());
      conversionService.addConverter(new BytesToMyTypeConverter());
      return conversionService;
    }

  }
View Full Code Here

  @Test
  public void prototypeCreationReevaluatesExpressions() {
    GenericApplicationContext ac = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    GenericConversionService cs = new GenericConversionService();
    cs.addConverter(String.class, String.class, new Converter<String, String>() {
      @Override
      public String convert(String source) {
        return source.trim();
      }
    });
View Full Code Here

  @Before
  public void setUp() {
    ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
    GenericConversionService service = new DefaultConversionService();
    service.addConverter(new Converter<String, NestedBean>() {
      @Override
      public NestedBean convert(String source) {
        return new NestedBean(source);
      }
    });
View Full Code Here

  @Test
  public void testCustomConverter() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    GenericConversionService conversionService = new DefaultConversionService();
    conversionService.addConverter(new Converter<String, Float>() {
      @Override
      public Float convert(String source) {
        try {
          NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
          return nf.parse(source).floatValue();
View Full Code Here

  @Deprecated
  public void test() throws Exception {
    AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
    ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
    GenericConversionService service = new DefaultConversionService();
    service.addConverter(new ColorConverter());
    binder.setConversionService(service);
    adapter.setWebBindingInitializer(binder);
    Spr7766Controller controller = new Spr7766Controller();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/colors");
View Full Code Here

  public void test_binaryPlusWithTimeConverted() {

    final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);

    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new Converter<Time, String>() {
      @Override
      public String convert(Time source) {
        return format.format(source);
      }
    });
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.