@@ -83,9 +83,8 @@ public class TypeDescriptor implements Serializable {
|
||||
Assert.notNull(methodParameter, "MethodParameter must not be null");
|
||||
this.resolvableType = ResolvableType.forMethodParameter(methodParameter);
|
||||
this.type = this.resolvableType.resolve(methodParameter.getParameterType());
|
||||
this.annotations = (methodParameter.getParameterIndex() == -1 ?
|
||||
nullSafeAnnotations(methodParameter.getMethodAnnotations()) :
|
||||
nullSafeAnnotations(methodParameter.getParameterAnnotations()));
|
||||
this.annotations = nullSafeAnnotations(methodParameter.getParameterIndex() == -1 ?
|
||||
methodParameter.getMethodAnnotations() :methodParameter.getParameterAnnotations());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +383,7 @@ public class TypeDescriptor implements Serializable {
|
||||
* @throws IllegalStateException if this type is not a {@code java.util.Map}
|
||||
*/
|
||||
public TypeDescriptor getMapKeyTypeDescriptor() {
|
||||
Assert.state(isMap(), "Not a java.util.Map");
|
||||
Assert.state(isMap(), "Not a [java.util.Map]");
|
||||
return getRelatedIfResolvable(this, this.resolvableType.asMap().getGeneric(0));
|
||||
}
|
||||
|
||||
@@ -419,7 +418,7 @@ public class TypeDescriptor implements Serializable {
|
||||
* @throws IllegalStateException if this type is not a {@code java.util.Map}
|
||||
*/
|
||||
public TypeDescriptor getMapValueTypeDescriptor() {
|
||||
Assert.state(isMap(), "Not a java.util.Map");
|
||||
Assert.state(isMap(), "Not a [java.util.Map]");
|
||||
return getRelatedIfResolvable(this, this.resolvableType.asMap().getGeneric(1));
|
||||
}
|
||||
|
||||
@@ -529,9 +528,9 @@ public class TypeDescriptor implements Serializable {
|
||||
* @return the collection type descriptor
|
||||
*/
|
||||
public static TypeDescriptor collection(Class<?> collectionType, TypeDescriptor elementTypeDescriptor) {
|
||||
Assert.notNull(collectionType, "collectionType must not be null");
|
||||
Assert.notNull(collectionType, "Collection type must not be null");
|
||||
if (!Collection.class.isAssignableFrom(collectionType)) {
|
||||
throw new IllegalArgumentException("collectionType must be a java.util.Collection");
|
||||
throw new IllegalArgumentException("Collection type must be a [java.util.Collection]");
|
||||
}
|
||||
ResolvableType element = (elementTypeDescriptor != null ? elementTypeDescriptor.resolvableType : null);
|
||||
return new TypeDescriptor(ResolvableType.forClassWithGenerics(collectionType, element), null, null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,15 +27,16 @@ public interface ConverterRegistry {
|
||||
|
||||
/**
|
||||
* Add a plain converter to this registry.
|
||||
* The convertible sourceType/targetType pair is derived from the Converter's parameterized types.
|
||||
* The convertible source/target type pair is derived from the Converter's parameterized types.
|
||||
* @throws IllegalArgumentException if the parameterized types could not be resolved
|
||||
*/
|
||||
void addConverter(Converter<?, ?> converter);
|
||||
|
||||
/**
|
||||
* Add a plain converter to this registry.
|
||||
* The convertible sourceType/targetType pair is specified explicitly.
|
||||
* Allows for a Converter to be reused for multiple distinct pairs without having to create a Converter class for each pair.
|
||||
* The convertible source/target type pair is specified explicitly.
|
||||
* <p>Allows for a Converter to be reused for multiple distinct pairs without
|
||||
* having to create a Converter class for each pair.
|
||||
* @since 3.1
|
||||
*/
|
||||
void addConverter(Class<?> sourceType, Class<?> targetType, Converter<?, ?> converter);
|
||||
@@ -47,13 +48,13 @@ public interface ConverterRegistry {
|
||||
|
||||
/**
|
||||
* Add a ranged converter factory to this registry.
|
||||
* The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types.
|
||||
* @throws IllegalArgumentException if the parameterized types could not be resolved.
|
||||
* The convertible source/target type pair is derived from the ConverterFactory's parameterized types.
|
||||
* @throws IllegalArgumentException if the parameterized types could not be resolved
|
||||
*/
|
||||
void addConverterFactory(ConverterFactory<?, ?> converterFactory);
|
||||
void addConverterFactory(ConverterFactory<?, ?> factory);
|
||||
|
||||
/**
|
||||
* Remove any converters from sourceType to targetType.
|
||||
* Remove any converters from {@code sourceType} to {@code targetType}.
|
||||
* @param sourceType the source type
|
||||
* @param targetType the target type
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,8 +97,10 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
@Override
|
||||
public void addConverter(Converter<?, ?> converter) {
|
||||
ResolvableType[] typeInfo = getRequiredTypeInfo(converter, Converter.class);
|
||||
Assert.notNull(typeInfo, "Unable to the determine sourceType <S> and targetType " +
|
||||
"<T> which your Converter<S, T> converts between; declare these generic types.");
|
||||
if (typeInfo == null) {
|
||||
throw new IllegalArgumentException("Unable to determine source type <S> and target type <T> for your " +
|
||||
"Converter [" + converter.getClass().getName() + "]; does the class parameterize those types?");
|
||||
}
|
||||
addConverter(new ConverterAdapter(converter, typeInfo[0], typeInfo[1]));
|
||||
}
|
||||
|
||||
@@ -115,11 +117,13 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
|
||||
ResolvableType[] typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
|
||||
Assert.notNull(typeInfo, "Unable to the determine source type <S> and target range type R which your " +
|
||||
"ConverterFactory<S, R> converts between; declare these generic types.");
|
||||
addConverter(new ConverterFactoryAdapter(converterFactory,
|
||||
public void addConverterFactory(ConverterFactory<?, ?> factory) {
|
||||
ResolvableType[] typeInfo = getRequiredTypeInfo(factory, ConverterFactory.class);
|
||||
if (typeInfo == null) {
|
||||
throw new IllegalArgumentException("Unable to determine source type <S> and target type <T> for your " +
|
||||
"ConverterFactory [" + factory.getClass().getName() + "]; does the class parameterize those types?");
|
||||
}
|
||||
addConverter(new ConverterFactoryAdapter(factory,
|
||||
new ConvertiblePair(typeInfo[0].resolve(), typeInfo[1].resolve())));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 1.2.6
|
||||
* @see Resource#getInputStream()
|
||||
* @see java.io.Reader
|
||||
* @see java.nio.charset.Charset
|
||||
*/
|
||||
@@ -142,8 +143,8 @@ public class EncodedResource implements InputStreamSource {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a {@code java.io.InputStream} for the specified resource, ignoring any
|
||||
* specified {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
|
||||
* Open an {@code InputStream} for the specified resource, ignoring any specified
|
||||
* {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
|
||||
* @throws IOException if opening the InputStream failed
|
||||
* @see #requiresReader()
|
||||
* @see #getReader()
|
||||
|
||||
Reference in New Issue
Block a user