congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ConversionService.canConvert
Code IndexAdd Tabnine to your IDE (free)

How to use
canConvert
method
in
org.springframework.core.convert.ConversionService

Best Java code snippets using org.springframework.core.convert.ConversionService.canConvert (Showing top 20 results out of 900)

origin: spring-projects/spring-framework

@Override
public boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
  return this.conversionService.canConvert(sourceType, targetType);
}
origin: spring-projects/spring-framework

/**
 * Validate that a {@link Collection} of the elements held within the stream can be
 * converted to the specified {@code targetType}.
 * @param elementType the type of the stream elements
 * @param targetType the type to convert to
 */
public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(collectionOfElement, targetType);
}
origin: spring-projects/spring-framework

/**
 * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
 * the type of the stream elements.
 * @param elementType the type of the stream elements
 * @param sourceType the type to convert from
 */
public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(sourceType, collectionOfElement);
}
origin: spring-projects/spring-framework

@Override
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
  return canRead(mediaType) && this.conversionService.canConvert(String.class, clazz);
}
origin: spring-projects/spring-framework

@Override
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
  return canWrite(mediaType) && this.conversionService.canConvert(clazz, String.class);
}
origin: spring-projects/spring-framework

private boolean matchesFromByteBuffer(TypeDescriptor targetType) {
  return (targetType.isAssignableTo(BYTE_ARRAY_TYPE) ||
      this.conversionService.canConvert(BYTE_ARRAY_TYPE, targetType));
}
origin: spring-projects/spring-framework

@Override
public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
  return this.service.canConvert(sourceType, targetType);
}
origin: spring-projects/spring-framework

private boolean matchesToByteBuffer(TypeDescriptor sourceType) {
  return (sourceType.isAssignableTo(BYTE_ARRAY_TYPE) ||
      this.conversionService.canConvert(sourceType, BYTE_ARRAY_TYPE));
}
origin: spring-projects/spring-framework

/**
 * Create a new ConvertingPropertyEditorAdapter for a given
 * {@link org.springframework.core.convert.ConversionService}
 * and the given target type.
 * @param conversionService the ConversionService to delegate to
 * @param targetDescriptor the target type to convert to
 */
public ConvertingPropertyEditorAdapter(ConversionService conversionService, TypeDescriptor targetDescriptor) {
  Assert.notNull(conversionService, "ConversionService must not be null");
  Assert.notNull(targetDescriptor, "TypeDescriptor must not be null");
  this.conversionService = conversionService;
  this.targetDescriptor = targetDescriptor;
  this.canConvertToString = conversionService.canConvert(this.targetDescriptor, TypeDescriptor.valueOf(String.class));
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  return (targetType.getElementTypeDescriptor() == null ||
      this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor()));
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  Method finder = getFinder(targetType.getType());
  return (finder != null &&
      this.conversionService.canConvert(sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0])));
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  for (Class<?> interfaceType : ClassUtils.getAllInterfacesForClassAsSet(sourceType.getType())) {
    if (this.conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) {
      return false;
    }
  }
  return true;
}
origin: spring-projects/spring-framework

/**
 * Determine if a given message can be decoded.
 * @see #decode(Object)
 * @see javax.websocket.Decoder.Text#willDecode(String)
 * @see javax.websocket.Decoder.Binary#willDecode(ByteBuffer)
 */
public boolean willDecode(M bytes) {
  return getConversionService().canConvert(getType(), getMessageType());
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (targetType.getResolvableType().hasGenerics()) {
    return this.conversionService.canConvert(sourceType, new GenericTypeDescriptor(targetType));
  }
  else {
    return true;
  }
}
origin: spring-projects/spring-framework

public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
  if (conversionService.canConvert(sourceType, targetType)) {
    return true;
  }
  if (!String.class.isAssignableFrom(sourceType) && !String.class.isAssignableFrom(targetType)) {
    // PropertyEditor cannot convert non-Strings
    return false;
  }
  if (!String.class.isAssignableFrom(sourceType)) {
    return delegate.findCustomEditor(sourceType, null) != null || delegate.getDefaultEditor(sourceType) != null;
  }
  return delegate.findCustomEditor(targetType, null) != null || delegate.getDefaultEditor(targetType) != null;
}
origin: spring-projects/spring-framework

@Override
public boolean canConvert(TypeDescriptor sourceTypeDescriptor, TypeDescriptor targetTypeDescriptor) {
  if (conversionService.canConvert(sourceTypeDescriptor, targetTypeDescriptor)) {
    return true;
  }
  // TODO: what does this mean? This method is not used in SpEL so probably ignorable?
  Class<?> sourceType = sourceTypeDescriptor.getObjectType();
  Class<?> targetType = targetTypeDescriptor.getObjectType();
  return canConvert(sourceType, targetType);
}
origin: spring-projects/spring-framework

@Test
public void createDefaultConversionService() {
  ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
  factory.afterPropertiesSet();
  ConversionService service = factory.getObject();
  assertTrue(service.canConvert(String.class, Integer.class));
}
origin: spring-projects/spring-framework

@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));
}
origin: spring-projects/spring-framework

@Test
public void withConversionService() {
  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));
}
origin: spring-projects/spring-framework

@Override
public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (targetType.getType() == Void.class || targetType.getType() == Void.TYPE) {
    return null;
  }
  if (conversionService.canConvert(sourceType, targetType)) {
    return conversionService.convert(value, sourceType, targetType);
  }
  if (!String.class.isAssignableFrom(sourceType.getType())) {
    PropertyEditor editor = delegate.findCustomEditor(sourceType.getType(), null);
    editor.setValue(value);
    return editor.getAsText();
  }
  return delegate.convertIfNecessary(value, targetType.getType());
}
org.springframework.core.convertConversionServicecanConvert

Javadoc

Returns true if objects of sourceType can be converted to targetType. If this method returns true, it means #convert(Object,Class) is capable of converting an instance of sourceType to targetType. Special note on collections, arrays, and maps types: For conversion between collection, array, and map types, this method will return 'true' even though a convert invocation may still generate a ConversionException if the underlying elements are not convertible. Callers are expected to handle this exceptional case when working with collections and maps.

Popular methods of ConversionService

  • convert
    Convert the given source to the specified targetType. The TypeDescriptors provide additional context

Popular in Java

  • Updating database using SQL prepared statement
  • getResourceAsStream (ClassLoader)
  • getSharedPreferences (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now