Package org.springframework.core.convert.converter

Examples of org.springframework.core.convert.converter.GenericConverter


    Class<?> type = converter.getClass();
    boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
    boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

    if (converter instanceof GenericConverter) {
      GenericConverter genericConverter = (GenericConverter) converter;
      for (GenericConverter.ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
        register(new ConverterRegistration(pair, isReading, isWriting));
      }
    } else if (converter instanceof Converter) {
      Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
      register(new ConverterRegistration(arguments[0], arguments[1], isReading, isWriting));
View Full Code Here


  public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
    Assert.notNull(targetType,"The targetType to convert to cannot be null");
    if (sourceType == null) {
      return true;
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    return (converter != null);
  }
View Full Code Here

  public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
    Assert.notNull(targetType, "The targetType to convert to cannot be null");
    if (sourceType == null) {
      return true;
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    return (converter == NO_OP_CONVERTER);
  }
View Full Code Here

    }
    if (source != null && !sourceType.getObjectType().isInstance(source)) {
      throw new IllegalArgumentException("The source to convert from must be an instance of " +
          sourceType + "; instead it was a " + source.getClass().getName());
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    if (converter != null) {
      Object result = ConversionUtils.invokeConverter(converter, source, sourceType, targetType);
      return handleResult(sourceType, targetType, result);
    }
    return handleConverterNotFound(source, sourceType, targetType);
View Full Code Here

   * no suitable converter was found
   * @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
   */
  protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) {
    ConverterCacheKey key = new ConverterCacheKey(sourceType, targetType);
    GenericConverter converter = this.converterCache.get(key);
    if (converter != null) {
      return (converter != NO_MATCH ? converter : null);
    }

    converter = this.converters.find(sourceType, targetType);
View Full Code Here

      // Search the full type hierarchy
      List<TypeDescriptor> sourceCandidates = getTypeHierarchy(sourceType);
      List<TypeDescriptor> targetCandidates = getTypeHierarchy(targetType);
      for (TypeDescriptor sourceCandidate : sourceCandidates) {
        for (TypeDescriptor targetCandidate : targetCandidates) {
          GenericConverter converter = getRegisteredConverter(
              sourceType, targetType, sourceCandidate, targetCandidate);
          if(converter != null) {
            return converter;
          }
        }
View Full Code Here

        TypeDescriptor sourceCandidate, TypeDescriptor targetCandidate) {

      // Check specifically registered converters
      ConvertersForPair convertersForPair = converters.get(new ConvertiblePair(
        sourceCandidate.getType(), targetCandidate.getType()));
      GenericConverter converter = convertersForPair == null ? null
        : convertersForPair.getConverter(sourceType, targetType);
      if (converter != null) {
        return converter;
      }
View Full Code Here

    TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
    if (targetElementType == TypeDescriptor.NULL || sourceType.isAssignableTo(targetElementType)) {
      target.add(source);
    }
    else {
      GenericConverter converter = this.conversionService.getConverter(sourceType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceType, targetElementType);
      }
      target.add(ConversionUtils.invokeConverter(converter, source, sourceType, targetElementType));
    }
View Full Code Here

    if (sourceType.isAssignableTo(targetElementType)) {
      return fields;
    }
    else {
      Object target = Array.newInstance(targetElementType.getType(), fields.length);
      GenericConverter converter = this.conversionService.getConverter(sourceType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceType, targetElementType);
      }
      for (int i = 0; i < fields.length; i++) {
        Array.set(target, i, ConversionUtils.invokeConverter(converter, fields[i], sourceType, targetElementType));
View Full Code Here

    Object target = Array.newInstance(targetElementType.getType(), 1);
    if (sourceType.isAssignableTo(targetElementType)) {
      Array.set(target, 0, source);
    }
    else {
      GenericConverter converter = this.conversionService.getConverter(sourceType, targetElementType);
      if (converter == null) {
        throw new ConverterNotFoundException(sourceType, targetElementType);
      }
      Array.set(target, 0, ConversionUtils.invokeConverter(converter, source, sourceType, targetElementType));
    }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.converter.GenericConverter

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.