public class Mapper extends Object
length and should be mapped from the property resource's value at path definition, the mapper will
look up definition.length to get the value for the JavaBean property.
Classes must be JavaBeans. These are simple classes with private fields, accompanied with getters and setters.
The mapper only considers properties which have both a getter and a setter method. Any Java class without
at least one property with both a getter and a setter is not considered as a JavaBean class. Such classes can
be supported by implementing a custom Transformer that performs the conversion from the property resource to
an object of the class' type.
Recursion: the mapping of values to a JavaBean is performed recursively, i.e. a JavaBean may have other JavaBeans as fields at any arbitrary "depth."
Collections are only supported if they are explicitly typed, i.e. a field of List<String>
is supported but List<?> and List<T extends Number> are not supported. Specifically, you may
only declare fields of type List or Set, or a parent type (Collection or Iterable).
Fields of type Map are supported also, with similar limitations. Additionally, maps may only have
String as key type, but no restrictions are imposed on the value type.
JavaBeans may have optional fields. If the mapper cannot map the property resource value to the corresponding
field, it only treats it as a failure if the field's value is null. If the field has a default value assigned
to it on initialization, the default value remains and the mapping process continues. A JavaBean field whose value is
null signifies a failure and stops the mapping process immediately.
| Constructor and Description |
|---|
Mapper()
Creates a new JavaBean mapper with the default configuration.
|
Mapper(MappingErrorHandler mappingErrorHandler,
BeanDescriptionFactory beanDescriptionFactory,
Transformer... transformers)
Creates a new JavaBean mapper with the given elements.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
convertToBean(String path,
PropertyResource resource,
Class<T> clazz)
Converts the value in the property resource at the given path to the provided beans class.
|
protected <T> T |
convertToBean(TypeInformation<T> type,
Object value,
MappingContext context)
Converts the provided value to the requested JavaBeans class if possible.
|
protected Object |
getPropertyValue(TypeInformation typeInformation,
Object value,
MappingContext context)
Returns a value of type
clazz based on the provided value if possible. |
Collection<BeanPropertyDescription> |
getWritableProperties(Class<?> clazz)
Returns the properties of the given bean class that need to be considered when constructing objects.
|
protected Collection<?> |
processCollection(TypeInformation<?> type,
Object value,
MappingContext context) |
protected Map |
processMap(TypeInformation<?> type,
Object value,
MappingContext context) |
protected Object |
processTransformers(TypeInformation typeInformation,
Object value) |
public Mapper()
public Mapper(MappingErrorHandler mappingErrorHandler, BeanDescriptionFactory beanDescriptionFactory, Transformer... transformers)
mappingErrorHandler - handler to use for mapping errorsbeanDescriptionFactory - factory to get bean property descriptions for classestransformers - the transformers to use for mapping valuesTransformers.getDefaultTransformers()@Nullable public <T> T convertToBean(String path, PropertyResource resource, Class<T> clazz)
T - the bean typepath - the path to convert fromresource - the property resource to read fromclazz - the JavaBean class@Nullable protected Object getPropertyValue(TypeInformation typeInformation, @Nullable Object value, MappingContext context)
clazz based on the provided value if possible.typeInformation - type informationvalue - the value to convert fromcontext - the mapping context@Nullable protected Collection<?> processCollection(TypeInformation<?> type, Object value, MappingContext context)
@Nullable protected Map processMap(TypeInformation<?> type, Object value, MappingContext context)
@Nullable protected Object processTransformers(TypeInformation typeInformation, Object value)
@Nullable protected <T> T convertToBean(TypeInformation<T> type, Object value, MappingContext context)
T - the JavaBean typetype - type informationvalue - the value from the property resourcecontext - the mapping contextpublic Collection<BeanPropertyDescription> getWritableProperties(Class<?> clazz)
clazz - the class to get the bean properties fromCopyright © 2016–2018 The AuthMe Team. All rights reserved.