Package org.osgi.util.converter
Class CustomConverterImpl.ConvertingWrapper
- java.lang.Object
-
- org.osgi.util.converter.CustomConverterImpl.ConvertingWrapper
-
- All Implemented Interfaces:
Converting
,InternalConverting
,Specifying<Converting>
- Enclosing class:
- CustomConverterImpl
private class CustomConverterImpl.ConvertingWrapper extends java.lang.Object implements InternalConverting
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
defaultValue
private InternalConverting
del
private boolean
hasDefault
private java.lang.Object
object
-
Constructor Summary
Constructors Constructor Description ConvertingWrapper(java.lang.Object obj, InternalConverting c)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Converting
defaultValue(java.lang.Object defVal)
The default value to use when the object cannot be converted or in case of conversion from anull
value.Converting
keysIgnoreCase()
When converting between map-like types use case-insensitive mapping of keys.void
setConverter(Converter c)
Set the current converter.Converting
sourceAs(java.lang.Class<?> type)
Treat the source object as the specified class.Converting
sourceAsBean()
Treat the source object as a JavaBean.Converting
sourceAsDTO()
Treat the source object as a DTO even if the source object has methods or is otherwise not recognized as a DTO.Converting
targetAs(java.lang.Class<?> cls)
Treat the target object as the specified class.Converting
targetAsBean()
Treat the target object as a JavaBean.Converting
targetAsDTO()
Treat the target object as a DTO even if it has methods or is otherwise not recognized as a DTO.<T> T
to(java.lang.Class<T> cls)
Specify the target object type for the conversion as a class object.<T> T
to(java.lang.reflect.Type type)
Specify the target object type as a Java Reflection Type object.<T> T
to(TypeReference<T> ref)
Specify the target object type as aTypeReference
.java.lang.String
toString()
Converting
view()
Return a live view over the backing object that reflects any changes to the original object.
-
-
-
Field Detail
-
del
private final InternalConverting del
-
object
private final java.lang.Object object
-
defaultValue
private volatile java.lang.Object defaultValue
-
hasDefault
private volatile boolean hasDefault
-
-
Constructor Detail
-
ConvertingWrapper
ConvertingWrapper(java.lang.Object obj, InternalConverting c)
-
-
Method Detail
-
view
public Converting view()
Description copied from interface:Specifying
Return a live view over the backing object that reflects any changes to the original object. This is only possible with conversions toMap
,Collection
,List
andSet
. The live view object will cease to be live as soon as modifications are made to it. Note that conversions to an interface or annotation will always produce a live view that cannot be modified. This modifier has no effect with conversions to other types.- Specified by:
view
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
defaultValue
public Converting defaultValue(java.lang.Object defVal)
Description copied from interface:Specifying
The default value to use when the object cannot be converted or in case of conversion from anull
value.- Specified by:
defaultValue
in interfaceSpecifying<Converting>
- Parameters:
defVal
- The default value.- Returns:
- The current
Converting
object so that additional calls can be chained.
-
keysIgnoreCase
public Converting keysIgnoreCase()
Description copied from interface:Specifying
When converting between map-like types use case-insensitive mapping of keys.- Specified by:
keysIgnoreCase
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
setConverter
public void setConverter(Converter c)
Description copied from interface:InternalConverting
Set the current converter.- Specified by:
setConverter
in interfaceInternalConverting
- Parameters:
c
- The current converter.
-
sourceAs
public Converting sourceAs(java.lang.Class<?> type)
Description copied from interface:Specifying
Treat the source object as the specified class. This can be used to disambiguate a type if it implements multiple interfaces or extends multiple classes.- Specified by:
sourceAs
in interfaceSpecifying<Converting>
- Parameters:
type
- The class to treat the object as.- Returns:
- The current
Converting
object so that additional calls can be chained.
-
sourceAsBean
public Converting sourceAsBean()
Description copied from interface:Specifying
Treat the source object as a JavaBean. By default objects will not be treated as JavaBeans, this has to be specified using this method.- Specified by:
sourceAsBean
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
sourceAsDTO
public Converting sourceAsDTO()
Description copied from interface:Specifying
Treat the source object as a DTO even if the source object has methods or is otherwise not recognized as a DTO.- Specified by:
sourceAsDTO
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
targetAs
public Converting targetAs(java.lang.Class<?> cls)
Description copied from interface:Specifying
Treat the target object as the specified class. This can be used to disambiguate a type if it implements multiple interfaces or extends multiple classes.- Specified by:
targetAs
in interfaceSpecifying<Converting>
- Parameters:
cls
- The class to treat the object as.- Returns:
- The current
Converting
object so that additional calls can be chained.
-
targetAsBean
public Converting targetAsBean()
Description copied from interface:Specifying
Treat the target object as a JavaBean. By default objects will not be treated as JavaBeans, this has to be specified using this method.- Specified by:
targetAsBean
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
targetAsDTO
public Converting targetAsDTO()
Description copied from interface:Specifying
Treat the target object as a DTO even if it has methods or is otherwise not recognized as a DTO.- Specified by:
targetAsDTO
in interfaceSpecifying<Converting>
- Returns:
- The current
Converting
object so that additional calls can be chained.
-
to
public <T> T to(java.lang.Class<T> cls)
Description copied from interface:Converting
Specify the target object type for the conversion as a class object.- Specified by:
to
in interfaceConverting
- Parameters:
cls
- The class to convert to.- Returns:
- The converted object.
-
to
public <T> T to(TypeReference<T> ref)
Description copied from interface:Converting
Specify the target object type as aTypeReference
. If the target class carries generics information a TypeReference should be used as this preserves the generic information whereas a Class object has this information erased. Example use:List<String> result = converter.convert(Arrays.asList(1, 2, 3)) .to(new TypeReference<List<String>>() {});
- Specified by:
to
in interfaceConverting
- Parameters:
ref
- A type reference to the object being converted to.- Returns:
- The converted object.
-
to
public <T> T to(java.lang.reflect.Type type)
Description copied from interface:Converting
Specify the target object type as a Java Reflection Type object.- Specified by:
to
in interfaceConverting
- Parameters:
type
- A Type object to represent the target type to be converted to.- Returns:
- The converted object.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-