Top Description Fields Constructors Methods
org.springframework.core.convert.support

pack-priv final Class IdToEntityConverter

extends Object
implements ConditionalGenericConverter
Class Inheritance
All Implemented Interfaces
org.springframework.core.convert.converter.ConditionalGenericConverter, org.springframework.core.convert.converter.ConditionalConverter, org.springframework.core.convert.converter.GenericConverter
Imports
java.lang.reflect.Method, .Modifier, java.util.Collections, .Set, org.springframework.core.convert.ConversionService, .TypeDescriptor, org.springframework.core.convert.converter.ConditionalGenericConverter, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils

Converts an entity identifier to an entity reference by calling a static finder method on the target entity type.

For this converter to match, the finder method must be static, have the signature find[EntityName]([IdType]), and return an instance of the desired entity type.

Authors
Keith Donald, Juergen Hoeller
Since
3.0

Field Summary

Modifier and TypeField and Description
private final ConversionService

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
convert(Object
the source object to convert (may be null)
source
,
TypeDescriptor
the type descriptor of the field we are converting from
sourceType
,
TypeDescriptor
the type descriptor of the field we are converting to
targetType
)

Implements org.springframework.core.convert.converter.GenericConverter.convert.

Convert the source object to the targetType described by the TypeDescriptor.

public Set<GenericConverter.ConvertiblePair>
getConvertibleTypes()

Implements org.springframework.core.convert.converter.GenericConverter.getConvertibleTypes.

Return the source and target types that this converter can convert between.

private String
getEntityName(Class<?> entityClass)

private Method
getFinder(Class<?> entityClass)

public boolean
matches(TypeDescriptor
the type descriptor of the field we are converting from
sourceType
,
TypeDescriptor
the type descriptor of the field we are converting to
targetType
)

Implements org.springframework.core.convert.converter.ConditionalConverter.matches.

Should the conversion from sourceType to targetType currently under consideration be selected?

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionServiceback to summary
private final ConversionService conversionService

Constructor Detail

IdToEntityConverterback to summary
public IdToEntityConverter(ConversionService conversionService)

Method Detail

convertback to summary
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType)

Implements org.springframework.core.convert.converter.GenericConverter.convert.

Doc from org.springframework.core.convert.converter.GenericConverter.convert.

Convert the source object to the targetType described by the TypeDescriptor.

Parameters
source:Object

the source object to convert (may be null)

sourceType:TypeDescriptor

the type descriptor of the field we are converting from

targetType:TypeDescriptor

the type descriptor of the field we are converting to

Returns:Object

the converted object

Annotations
@Override
@Nullable
getConvertibleTypesback to summary
public Set<GenericConverter.ConvertiblePair> getConvertibleTypes()

Implements org.springframework.core.convert.converter.GenericConverter.getConvertibleTypes.

Doc from org.springframework.core.convert.converter.GenericConverter.getConvertibleTypes.

Return the source and target types that this converter can convert between.

Each entry is a convertible source-to-target type pair.

For conditional converters this method may return null to indicate all source-to-target pairs should be considered.

Annotations
@Override
getEntityNameback to summary
private String getEntityName(Class<?> entityClass)
getFinderback to summary
private Method getFinder(Class<?> entityClass)
Annotations
@Nullable
matchesback to summary
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType)

Implements org.springframework.core.convert.converter.ConditionalConverter.matches.

Doc from org.springframework.core.convert.converter.ConditionalConverter.matches.

Should the conversion from sourceType to targetType currently under consideration be selected?

Parameters
sourceType:TypeDescriptor

the type descriptor of the field we are converting from

targetType:TypeDescriptor

the type descriptor of the field we are converting to

Returns:boolean

true if conversion should be performed, false otherwise

Annotations
@Override