Package org.springframework.core.convert.converter

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


      if (ann == null) {
        throw new IllegalStateException(
            "Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
      }
      AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
      GenericConverter converter = cachedParsers.get(converterKey);
      if (converter == null) {
        Parser<?> parser = this.annotationFormatterFactory.getParser(
            converterKey.getAnnotation(), converterKey.getFieldType());
        converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
        cachedParsers.put(converterKey, converter);
      }
      return converter.convert(source, sourceType, targetType);
    }
View Full Code Here


      List<Class<?>> sourceCandidates = getClassHierarchy(sourceType.getType());
      List<Class<?>> targetCandidates = getClassHierarchy(targetType.getType());
      for (Class<?> sourceCandidate : sourceCandidates) {
        for (Class<?> targetCandidate : targetCandidates) {
          ConvertiblePair convertiblePair = new ConvertiblePair(sourceCandidate, targetCandidate);
          GenericConverter converter = getRegisteredConverter(sourceType, targetType, convertiblePair);
          if (converter != null) {
            return converter;
          }
        }
      }
View Full Code Here

        TypeDescriptor targetType, ConvertiblePair convertiblePair) {

      // Check specifically registered converters
      ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
      if (convertersForPair != null) {
        GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
        if (converter != null) {
          return converter;
        }
      }
      // Check ConditionalGenericConverter that match all types
View Full Code Here

  public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
    Assert.notNull(targetType, "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

            return (T) new Bar();
          }
        };
      }
    });
    converters.add(new GenericConverter() {
      @Override
      public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, Baz.class));
      }
      @Override
View Full Code Here

  }

  @Test
  public void shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter() {
    GenericConversionService conversionService = new GenericConversionService();
    GenericConverter converter = new GenericConverter() {
      @Override
      public Set<ConvertiblePair> getConvertibleTypes() {
        return null;
      }
      @Override
View Full Code Here

      return convertNullSource(sourceType, targetType);     
    }
    if (targetType == TypeDescriptor.NULL) {
      return null;
    }
    GenericConverter converter = getConverter(sourceType, targetType);
    if (converter == null) {
      throw new ConverterNotFoundException(sourceType, targetType);
    }
    return ConversionUtils.invokeConverter(converter, source, sourceType, targetType);
  }
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.