Package org.springframework.core.convert.support

Examples of org.springframework.core.convert.support.GenericConversionService


  Spr7839Controller controller = new Spr7839Controller();

  @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

    evaluateAndCheckError("null and true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
    evaluateAndCheckError("!null", SpelMessage.TYPE_CONVERSION_ERROR, 1, "null", "boolean");
    evaluateAndCheckError("null ? 'foo' : 'bar'", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");

    // with null conversion (null -> false)
    GenericConversionService conversionService = new GenericConversionService() {
      @Override
      protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
        return targetType.getType() == Boolean.class ? false : null;
      }
    };
View Full Code Here

  @Test
  @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

  @Test
  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

   * Create the ConversionService instance returned by this factory bean.
   * <p>Creates a simple {@link GenericConversionService} instance by default.
   * Subclasses may override to customize the ConversionService instance that gets created.
   */
  protected GenericConversionService createConversionService() {
    return new GenericConversionService();
  }
View Full Code Here

  private final SampleBean sample = new SampleBean();

  @Test
  public void customConversion() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() {
      @Override
      public String convert(SampleBean source) {
        return "foo bar";
      }
    });
View Full Code Here

  }

  @Test
  public void customConversionServiceFailure() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    GenericConversionService conversionService = new GenericConversionService();
    assertFalse("conversion service should fail to convert payload",
        conversionService.canConvert(Integer.class, String.class));
    instance.setConversionService(conversionService);
    instance.afterPropertiesSet();

    InvocableHandlerMethod invocableHandlerMethod =
        createInvocableHandlerMethod(instance, "simpleString", String.class);
View Full Code Here

  @Override
  protected <E extends GenericEntity<Long, ?>> void doImportItem(
      Map<String, Map<String, GenericEntity<Long, ?>>> idsMapping, Workbook workbook, Class<E> clazz) {
    Sheet sheet = workbook.getSheet(getSheetName(clazz));
    if (sheet != null) {
      GenericConversionService conversionService = getConversionService(workbook, idsMapping);

      Map<String, GenericEntity<Long, ?>> idsMappingForClass = new HashMap<String, GenericEntity<Long, ?>>();
      idsMapping.put(clazz.getName(), idsMappingForClass);

      for (Class<?> referencedClass : getOtherReferencedClasses(clazz)) {
View Full Code Here

    }
  }

  protected GenericConversionService getConversionService(Workbook workbook,
      Map<String, Map<String, GenericEntity<Long, ?>>> idsMapping) {
    GenericConversionService service = new GenericConversionService();

    GenericEntityConverter genericEntityConverter = new GenericEntityConverter(importDataDao, workbook,
        new HashMap<Class<?>, Class<?>>(0), idsMapping);
    genericEntityConverter.setConversionService(service);
    service.addConverter(genericEntityConverter);

    service.addConverter(new ProjectConverter());
    service.addConverter(new ArtifactConverter());
    service.addConverter(new ExternalLinkWrapperConverter());

    DefaultConversionService.addDefaultConverters(service);

    return service;
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.support.GenericConversionService

Copyright © 2018 www.massapicom. 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.