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

How to use
isAssignableTo
method
in
org.springframework.core.convert.TypeDescriptor

Best Java code snippets using org.springframework.core.convert.TypeDescriptor.isAssignableTo (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

/**
 * Return the default converter if no converter is found for the given sourceType/targetType pair.
 * <p>Returns a NO_OP Converter if the source type is assignable to the target type.
 * Returns {@code null} otherwise, indicating no suitable converter could be found.
 * @param sourceType the source type to convert from
 * @param targetType the target type to convert to
 * @return the default generic converter that will perform the conversion
 */
@Nullable
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
  return (sourceType.isAssignableTo(targetType) ? NO_OP_CONVERTER : null);
}
origin: spring-projects/spring-framework

private boolean isNestedAssignable(@Nullable TypeDescriptor nestedTypeDescriptor,
    @Nullable TypeDescriptor otherNestedTypeDescriptor) {
  return (nestedTypeDescriptor == null || otherNestedTypeDescriptor == null ||
      nestedTypeDescriptor.isAssignableTo(otherNestedTypeDescriptor));
}
origin: org.springframework/spring-core

/**
 * Return the default converter if no converter is found for the given sourceType/targetType pair.
 * <p>Returns a NO_OP Converter if the source type is assignable to the target type.
 * Returns {@code null} otherwise, indicating no suitable converter could be found.
 * @param sourceType the source type to convert from
 * @param targetType the target type to convert to
 * @return the default generic converter that will perform the conversion
 */
@Nullable
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
  return (sourceType.isAssignableTo(targetType) ? NO_OP_CONVERTER : null);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (sourceType.isAssignableTo(STREAM_TYPE)) {
    return convertFromStream((Stream<?>) source, sourceType, targetType);
  }
  if (targetType.isAssignableTo(STREAM_TYPE)) {
    return convertToStream(source, sourceType, targetType);
  }
  // Should not happen
  throw new IllegalStateException("Unexpected source/target types");
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  boolean byteBufferTarget = targetType.isAssignableTo(BYTE_BUFFER_TYPE);
  if (sourceType.isAssignableTo(BYTE_BUFFER_TYPE)) {
    return (byteBufferTarget || matchesFromByteBuffer(targetType));
  }
  return (byteBufferTarget && matchesToByteBuffer(sourceType));
}
origin: spring-projects/spring-framework

@Nullable
private Object convertFromByteBuffer(ByteBuffer source, TypeDescriptor targetType) {
  byte[] bytes = new byte[source.remaining()];
  source.get(bytes);
  if (targetType.isAssignableTo(BYTE_ARRAY_TYPE)) {
    return bytes;
  }
  return this.conversionService.convert(bytes, BYTE_ARRAY_TYPE, targetType);
}
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

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

private boolean isNestedAssignable(@Nullable TypeDescriptor nestedTypeDescriptor,
    @Nullable TypeDescriptor otherNestedTypeDescriptor) {
  return (nestedTypeDescriptor == null || otherNestedTypeDescriptor == null ||
      nestedTypeDescriptor.isAssignableTo(otherNestedTypeDescriptor));
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (!sourceType.isAssignableTo(this.printerObjectType)) {
    source = this.conversionService.convert(source, sourceType, this.printerObjectType);
  }
  if (source == null) {
    return "";
  }
  return this.printer.print(source, LocaleContextHolder.getLocale());
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  boolean byteBufferTarget = targetType.isAssignableTo(BYTE_BUFFER_TYPE);
  if (source instanceof ByteBuffer) {
    ByteBuffer buffer = (ByteBuffer) source;
    return (byteBufferTarget ? buffer.duplicate() : convertFromByteBuffer(buffer, targetType));
  }
  if (byteBufferTarget) {
    return convertToByteBuffer(source, sourceType);
  }
  // Should not happen
  throw new IllegalStateException("Unexpected source/target types");
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  if (sourceType.isAssignableTo(targetType)) {
    return source;
  }
  if (Array.getLength(source) == 0) {
    return null;
  }
  Object firstElement = Array.get(source, 0);
  return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  if (sourceType.isAssignableTo(targetType)) {
    return source;
  }
  Collection<?> sourceCollection = (Collection<?>) source;
  if (sourceCollection.isEmpty()) {
    return null;
  }
  Object firstElement = sourceCollection.iterator().next();
  return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType);
}
origin: spring-projects/spring-framework

@Nullable
private Object handleConverterNotFound(
    @Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    assertNotPrimitiveTargetType(sourceType, targetType);
    return null;
  }
  if ((sourceType == null || sourceType.isAssignableTo(targetType)) &&
      targetType.getObjectType().isInstance(source)) {
    return source;
  }
  throw new ConverterNotFoundException(sourceType, targetType);
}
origin: spring-projects/spring-framework

@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (sourceType.isAssignableTo(STREAM_TYPE)) {
    return matchesFromStream(sourceType.getElementTypeDescriptor(), targetType);
  }
  if (targetType.isAssignableTo(STREAM_TYPE)) {
    return matchesToStream(targetType.getElementTypeDescriptor(), sourceType);
  }
  return false;
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  String text = (String) source;
  if (!StringUtils.hasText(text)) {
    return null;
  }
  Object result;
  try {
    result = this.parser.parse(text, LocaleContextHolder.getLocale());
  }
  catch (IllegalArgumentException ex) {
    throw ex;
  }
  catch (Throwable ex) {
    throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
  }
  TypeDescriptor resultType = TypeDescriptor.valueOf(result.getClass());
  if (!resultType.isAssignableTo(targetType)) {
    result = this.conversionService.convert(result, resultType, targetType);
  }
  return result;
}
origin: org.springframework/spring-context

@Override
@SuppressWarnings("unchecked")
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (!sourceType.isAssignableTo(this.printerObjectType)) {
    source = this.conversionService.convert(source, sourceType, this.printerObjectType);
  }
  if (source == null) {
    return "";
  }
  return this.printer.print(source, LocaleContextHolder.getLocale());
}
origin: spring-projects/spring-framework

@Test
public void isAssignableElementTypes() throws Exception {
  assertTrue(new TypeDescriptor(getClass().getField("listField")).isAssignableTo(new TypeDescriptor(getClass().getField("listField"))));
  assertTrue(new TypeDescriptor(getClass().getField("notGenericList")).isAssignableTo(new TypeDescriptor(getClass().getField("listField"))));
  assertTrue(new TypeDescriptor(getClass().getField("listField")).isAssignableTo(new TypeDescriptor(getClass().getField("notGenericList"))));
  assertFalse(new TypeDescriptor(getClass().getField("isAssignableElementTypes")).isAssignableTo(new TypeDescriptor(getClass().getField("listField"))));
  assertTrue(TypeDescriptor.valueOf(List.class).isAssignableTo(new TypeDescriptor(getClass().getField("listField"))));
}
origin: spring-projects/spring-framework

@Test
public void isAssignableMapKeyValueTypes() throws Exception {
  assertTrue(new TypeDescriptor(getClass().getField("mapField")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(new TypeDescriptor(getClass().getField("notGenericMap")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(new TypeDescriptor(getClass().getField("mapField")).isAssignableTo(new TypeDescriptor(getClass().getField("notGenericMap"))));
  assertFalse(new TypeDescriptor(getClass().getField("isAssignableMapKeyValueTypes")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(TypeDescriptor.valueOf(Map.class).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
}
origin: spring-projects/spring-framework

@Test
public void isAssignableTypes() {
  assertTrue(TypeDescriptor.valueOf(Integer.class).isAssignableTo(TypeDescriptor.valueOf(Number.class)));
  assertFalse(TypeDescriptor.valueOf(Number.class).isAssignableTo(TypeDescriptor.valueOf(Integer.class)));
  assertFalse(TypeDescriptor.valueOf(String.class).isAssignableTo(TypeDescriptor.valueOf(String[].class)));
}
org.springframework.core.convertTypeDescriptorisAssignableTo

Javadoc

Returns true if an object of this type descriptor can be assigned to the location described by the given type descriptor.

For example, valueOf(String.class).isAssignableTo(valueOf(CharSequence.class))returns true because a String value can be assigned to a CharSequence variable. On the other hand, valueOf(Number.class).isAssignableTo(valueOf(Integer.class))returns false because, while all Integers are Numbers, not all Numbers are Integers.

For arrays, collections, and maps, element and key/value types are checked if declared. For example, a List<String> field value is assignable to a Collection<CharSequence> field, but List<Number> is not assignable to List<Integer>.

Popular methods of TypeDescriptor

  • valueOf
    Create a new type descriptor from the given type.Use this to instruct the conversion system to conve
  • getType
    The type of the backing class, method parameter, field, or property described by this TypeDescriptor
  • <init>
    Create a new type descriptor from a Property.Use this constructor when a source or target conversion
  • forObject
    Create a new type descriptor for an object.Use this factory method to introspect a source object bef
  • getObjectType
    Variation of #getType() that accounts for a primitive type by returning its object wrapper type.This
  • getElementTypeDescriptor
    If this type is an array, returns the array's component type. If this type is a Stream, returns the
  • isArray
    Is this type an array type?
  • isCollection
    Is this type a Collection type?
  • nested
  • getMapValueTypeDescriptor
    If this type is a Map, creates a mapValue TypeDescriptorfrom the provided map value.Narrows the #get
  • getMapKeyTypeDescriptor
    If this type is a Map, creates a mapKey TypeDescriptorfrom the provided map key. Narrows the #getMap
  • elementTypeDescriptor
    If this type is a Collection or an array, creates a element TypeDescriptor from the provided collect
  • getMapKeyTypeDescriptor,
  • elementTypeDescriptor,
  • getAnnotations,
  • isMap,
  • equals,
  • getAnnotation,
  • isPrimitive,
  • narrow,
  • toString

Popular in Java

  • Updating database using SQL prepared statement
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • ImageIO (javax.imageio)
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Best plugins for Eclipse
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