Examples of canConvert()


Examples of org.springframework.core.convert.ConversionService.canConvert()

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(convertedValue);
      if (conversionService.canConvert(sourceTypeDesc, typeDescriptor)) {
        return (T) conversionService.convert(convertedValue, sourceTypeDesc, typeDescriptor);
      }
    }

    // Value not of required type?
View Full Code Here

Examples of org.springframework.core.convert.ConversionService.canConvert()

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(convertedValue);
      TypeDescriptor targetTypeDesc = typeDescriptor.forElementType(requiredType);
      if (conversionService.canConvert(sourceTypeDesc, targetTypeDesc)) {
        return (T) conversionService.convert(convertedValue, sourceTypeDesc, targetTypeDesc);
      }
    }

    // Value not of required type?
View Full Code Here

Examples of org.springframework.core.convert.ConversionService.canConvert()

    }
    @Test
    public void injectionForConversionService() {
        final Config config = assertInjected("-conversion");
        final ConversionService conversionService = config.neo4jTemplate.getConversionService();
        assertEquals(true, conversionService.canConvert(Enum.class,String.class));
        assertEquals(true, conversionService.canConvert(Config.class, Integer.class));
    }

    private Config assertInjected(String testCase) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests" + testCase + "-context.xml");
View Full Code Here

Examples of org.springframework.core.convert.support.DefaultConversionService.canConvert()

  }

  @Test
  public void testWithConversionService() {
    ConversionService conversionService = new DefaultConversionService();
    assertTrue(conversionService.canConvert(String.class, MediaType.class));
    MediaType mediaType = MediaType.parseMediaType("application/xml");
    assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
  }

  @Test
View Full Code Here

Examples of org.springframework.core.convert.support.DefaultConversionService.canConvert()

  }

  @Test
  public void testWithConversionService() {
    ConversionService conversionService = new DefaultConversionService();
    assertTrue(conversionService.canConvert(String.class, MimeType.class));
    MimeType mimeType = MimeType.valueOf("application/xml");
    assertEquals(mimeType, conversionService.convert("application/xml", MimeType.class));
  }

  @Test
View Full Code Here

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

  @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

Examples of org.springframework.expression.TypeConverter.canConvert()

        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, TYPE_STRING)) {
            return super.convertToString(configuration, processingContext, object);
        }
        return (String) typeConverter.convertValue(object, objectTypeDescriptor, TYPE_STRING);

    }
View Full Code Here

Examples of org.springframework.expression.TypeConverter.canConvert()

            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeDescriptor targetTypeDescriptor = TypeDescriptor.valueOf(targetClass);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, targetTypeDescriptor)) {
            return super.convertOther(configuration, processingContext, object, targetClass);
        }
        return (T) typeConverter.convertValue(object, objectTypeDescriptor, targetTypeDescriptor);

    }
View Full Code Here

Examples of org.springframework.expression.TypeConverter.canConvert()

        if (object == null) {
            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, TYPE_STRING)) {
            return super.convertToString(configuration, processingContext, object);
        }
        return (String) typeConverter.convertValue(object, objectTypeDescriptor, TYPE_STRING);

    }
View Full Code Here

Examples of org.springframework.expression.TypeConverter.canConvert()

            return null;
        }
        final TypeDescriptor objectTypeDescriptor = TypeDescriptor.forObject(object);
        final TypeDescriptor targetTypeDescriptor = TypeDescriptor.valueOf(targetClass);
        final TypeConverter typeConverter = getSpringConversionService(processingContext);
        if (typeConverter == null || !typeConverter.canConvert(objectTypeDescriptor, targetTypeDescriptor)) {
            return super.convertOther(configuration, processingContext, object, targetClass);
        }
        return (T) typeConverter.convertValue(object, objectTypeDescriptor, targetTypeDescriptor);

    }
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.