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

pack-priv Class StreamConverter

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.util.Collection, .Collections, .HashSet, .List, .Set, java.util.stream.Collectors, .Stream, org.springframework.core.convert.ConversionService, .TypeDescriptor, org.springframework.core.convert.converter.ConditionalGenericConverter, org.springframework.lang.Nullable

Converts a Stream to and from a collection or array, converting the element type if necessary.
Author
Stephane Nicoll
Since
4.2

Field Summary

Modifier and TypeField and Description
private final ConversionService
private static final Set<GenericConverter.ConvertiblePair>
private static final TypeDescriptor

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.
private Object
convertFromStream(Stream<?> source, TypeDescriptor streamType, TypeDescriptor targetType)

private Object
convertToStream(Object source, TypeDescriptor sourceType, TypeDescriptor streamType)

private static Set<GenericConverter.ConvertiblePair>
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.
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?
public boolean
matchesFromStream(TypeDescriptor
the type of the stream elements
elementType
,
TypeDescriptor
the type to convert to
targetType
)

Validate that a Collection of the elements held within the stream can be converted to the specified targetType.

public boolean
matchesToStream(TypeDescriptor
the type of the stream elements
elementType
,
TypeDescriptor
the type to convert from
sourceType
)

Validate that the specified sourceType can be converted to a Collection of the type of the stream elements.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conversionServiceback to summary
private final ConversionService conversionService
CONVERTIBLE_TYPESback to summary
private static final Set<GenericConverter.ConvertiblePair> CONVERTIBLE_TYPES
STREAM_TYPEback to summary
private static final TypeDescriptor STREAM_TYPE

Constructor Detail

StreamConverterback to summary
public StreamConverter(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
convertFromStreamback to summary
private Object convertFromStream(Stream<?> source, TypeDescriptor streamType, TypeDescriptor targetType)
Annotations
@Nullable
convertToStreamback to summary
private Object convertToStream(Object source, TypeDescriptor sourceType, TypeDescriptor streamType)
createConvertibleTypesback to summary
private static Set<GenericConverter.ConvertiblePair> createConvertibleTypes()
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
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
matchesFromStreamback to summary
public boolean matchesFromStream(TypeDescriptor elementType, TypeDescriptor targetType)

Validate that a Collection of the elements held within the stream can be converted to the specified targetType.

Parameters
elementType:TypeDescriptor

the type of the stream elements

targetType:TypeDescriptor

the type to convert to

matchesToStreamback to summary
public boolean matchesToStream(TypeDescriptor elementType, TypeDescriptor sourceType)

Validate that the specified sourceType can be converted to a Collection of the type of the stream elements.

Parameters
elementType:TypeDescriptor

the type of the stream elements

sourceType:TypeDescriptor

the type to convert from