@UsesJava8 class StreamConverter extends java.lang.Object implements ConditionalGenericConverter
Stream
to and from a collection or array, converting the
element type if necessary.GenericConverter.ConvertiblePair
Modifier and Type | Field and Description |
---|---|
private ConversionService |
conversionService |
private static java.util.Set<GenericConverter.ConvertiblePair> |
CONVERTIBLE_TYPES |
private static TypeDescriptor |
STREAM_TYPE |
Constructor and Description |
---|
StreamConverter(ConversionService conversionService) |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
convert(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType)
Convert the source object to the targetType described by the
TypeDescriptor . |
private java.lang.Object |
convertFromStream(java.util.stream.Stream<?> source,
TypeDescriptor streamType,
TypeDescriptor targetType) |
private java.lang.Object |
convertToStream(java.lang.Object source,
TypeDescriptor sourceType,
TypeDescriptor streamType) |
private static java.util.Set<GenericConverter.ConvertiblePair> |
createConvertibleTypes() |
java.util.Set<GenericConverter.ConvertiblePair> |
getConvertibleTypes()
Return the source and target types that this converter can convert between.
|
boolean |
matches(TypeDescriptor sourceType,
TypeDescriptor targetType)
Should the conversion from
sourceType to targetType currently under
consideration be selected? |
boolean |
matchesFromStream(TypeDescriptor elementType,
TypeDescriptor targetType)
Validate that a
Collection of the elements held within the stream can be
converted to the specified targetType . |
boolean |
matchesToStream(TypeDescriptor elementType,
TypeDescriptor sourceType)
Validate that the specified
sourceType can be converted to a Collection of
the type of the stream elements. |
private static final TypeDescriptor STREAM_TYPE
private static final java.util.Set<GenericConverter.ConvertiblePair> CONVERTIBLE_TYPES
private final ConversionService conversionService
public StreamConverter(ConversionService conversionService)
public java.util.Set<GenericConverter.ConvertiblePair> getConvertibleTypes()
GenericConverter
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.
getConvertibleTypes
in interface GenericConverter
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType)
ConditionalConverter
sourceType
to targetType
currently under
consideration be selected?matches
in interface ConditionalConverter
sourceType
- the type descriptor of the field we are converting fromtargetType
- the type descriptor of the field we are converting topublic boolean matchesFromStream(TypeDescriptor elementType, TypeDescriptor targetType)
Collection
of the elements held within the stream can be
converted to the specified targetType
.elementType
- the type of the stream elementstargetType
- the type to convert topublic boolean matchesToStream(TypeDescriptor elementType, TypeDescriptor sourceType)
sourceType
can be converted to a Collection
of
the type of the stream elements.elementType
- the type of the stream elementssourceType
- the type to convert frompublic java.lang.Object convert(java.lang.Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
GenericConverter
TypeDescriptor
.convert
in interface GenericConverter
source
- the source object to convert (may be null
)sourceType
- the type descriptor of the field we are converting fromtargetType
- the type descriptor of the field we are converting toprivate java.lang.Object convertFromStream(java.util.stream.Stream<?> source, TypeDescriptor streamType, TypeDescriptor targetType)
private java.lang.Object convertToStream(java.lang.Object source, TypeDescriptor sourceType, TypeDescriptor streamType)
private static java.util.Set<GenericConverter.ConvertiblePair> createConvertibleTypes()