S - Type of the optional field to map from.D - Type of the optional field to map to.public class GuavaOptionalConverter<S,D> extends Object implements Converter<com.google.common.base.Optional<S>,com.google.common.base.Optional<D>>
Converter which will convert one Optional field into another optional field.
For those that wish to support the Java 8 java.util.Optional class, the code is exactly the
same as this class apart from the static methods to construct the Optional classes.
| Constructor and Description |
|---|
GuavaOptionalConverter(Type<S> sourceType,
Type<D> destinationType)
Construct a new Optional converter configured to convert an Optional field
to another
Optional field. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canConvert(Type<?> sourceType,
Type<?> destinationType)
Answers whether this converter can be used to handle the conversion of
sourceType to destinationType. |
com.google.common.base.Optional<D> |
convert(com.google.common.base.Optional<S> optionalSource,
Type<? extends com.google.common.base.Optional<D>> destinationType,
MappingContext mappingContext)
Perform the conversion of
source into a new instance of
destinationType. |
Type<com.google.common.base.Optional<S>> |
getAType() |
Type<com.google.common.base.Optional<D>> |
getBType() |
void |
setMapperFacade(MapperFacade mapper)
Store an instance of the current MapperFacade which may be used in
mapping of nested types.
|
public GuavaOptionalConverter(Type<S> sourceType, Type<D> destinationType)
Optional field.sourceType - Type the source Optional field contains.destinationType - Type the destination Optional field will contain.public boolean canConvert(Type<?> sourceType, Type<?> destinationType)
ConvertersourceType to destinationType.canConvert in interface Converter<com.google.common.base.Optional<S>,com.google.common.base.Optional<D>>public com.google.common.base.Optional<D> convert(com.google.common.base.Optional<S> optionalSource, Type<? extends com.google.common.base.Optional<D>> destinationType, MappingContext mappingContext)
Convertersource into a new instance of
destinationType.convert in interface Converter<com.google.common.base.Optional<S>,com.google.common.base.Optional<D>>optionalSource - the source object to be converteddestinationType - the destination type to producemappingContext - since converters now have access to MapperFacade,
they have to pass mapping contextdestinationTypepublic void setMapperFacade(MapperFacade mapper)
ConvertersetMapperFacade in interface Converter<com.google.common.base.Optional<S>,com.google.common.base.Optional<D>>mapper - the current MapperFacadepublic Type<com.google.common.base.Optional<S>> getAType()
getAType in interface MappedTypePair<com.google.common.base.Optional<S>,com.google.common.base.Optional<D>>Copyright © 2019 Glasnost. All rights reserved.