Package org.springframework.core.convert.converter.GenericConverter

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


   * @param target the target type to be converted to, must not be {@literal null}.
   * @param isReading whether to force to consider the converter for reading.
   * @param isWriting whether to force to consider the converter for writing.
   */
  public ConverterRegistration(Class<?> source, Class<?> target, boolean isReading, boolean isWriting) {
    this(new ConvertiblePair(source, target), isReading, isWriting);
  }
View Full Code Here


      }
      return convertersForPair;
    }

    public void remove(Class<?> sourceType, Class<?> targetType) {
      converters.remove(new ConvertiblePair(sourceType, targetType));
    }
View Full Code Here

    private GenericConverter getRegisteredConverter(TypeDescriptor sourceType, TypeDescriptor targetType,
        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

      }
      return convertersForPair;
    }

    public void remove(Class<?> sourceType, Class<?> targetType) {
      this.converters.remove(new ConvertiblePair(sourceType, targetType));
    }
View Full Code Here

      // Search the full type hierarchy
      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

  public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
    ResolvableType[] typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
    Assert.notNull("Unable to the determine sourceType <S> and targetRangeType R which your " +
        "ConverterFactory<S, R> converts between; declare these generic types.");
    addConverter(new ConverterFactoryAdapter(converterFactory,
        new ConvertiblePair(typeInfo[0].resolve(), typeInfo[1].resolve())));
  }
View Full Code Here

    private final ResolvableType targetType;

    public ConverterAdapter(Converter<?, ?> converter, ResolvableType sourceType, ResolvableType targetType) {
      this.converter = (Converter<Object, Object>) converter;
      this.typeInfo = new ConvertiblePair(sourceType.resolve(Object.class), targetType.resolve(Object.class));
      this.targetType = targetType;
    }
View Full Code Here

  @Test
  @SuppressWarnings("rawtypes")
  public void shouldConvertStringToObject() throws Exception {
    Set<ConvertiblePair> types = this.converter.getConvertibleTypes();
    assertThat(types.size(), is(1));
    ConvertiblePair pair = types.iterator().next();
    assertThat(pair.getSourceType(), is(equalTo((Class) String.class)));
    assertThat(pair.getTargetType(), is(equalTo((Class) Object.class)));
  }
View Full Code Here

  Class<?> getCustomTarget(Class<?> sourceType, Class<?> expectedTargetType, Iterable<ConvertiblePair> pairs) {
    Assert.notNull(sourceType);
    Assert.notNull(pairs);

    ConvertiblePair expectedTypePair = new ConvertiblePair(sourceType, expectedTargetType != null ? expectedTargetType
        : Any.class);

    if (cache.containsKey(expectedTypePair)) {
      Class<?> cachedTargetType = cache.get(expectedTypePair);
      return cachedTargetType != Any.class ? cachedTargetType : null;
View Full Code Here

      throw new IllegalArgumentException("Unsupported Converter type! Expected either GenericConverter if Converter.");
    }
  }

  private void register(ConvertibleContext context) {
    ConvertiblePair pair = context.getConvertible();
    if (context.isReading()) {
      readingPairs.add(pair);
    }
    if (context.isWriting()) {
      writingPairs.add(pair);
      customSimpleTypes.add(pair.getSourceType());
    }
  }
View Full Code Here

TOP

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

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.