| Modifier and Type | Class and Description |
|---|---|
class |
Lang._MappingStage.__SpecialMappingStage |
| Modifier and Type | Method and Description |
|---|---|
Lang._MappingStage |
conversionHint(Class<?> type,
Object hint)
Add conversion hint associated with class.
|
Lang._MappingStage |
conversionHints(Map<Class,Object> conversionHints)
Add conversion hints indexed by class.
|
Lang._MappingStage |
filter(String filterSpec)
Specify filter spec for this mapping process.
|
Lang._MappingStage |
ignoreError()
Indicate ignore exceptions encountered during mapping process.
|
Lang._MappingStage |
ignoreGlobalFilter()
Indicate this mapping process shall ignore global filter settings in
OsglConfig. |
Lang._MappingStage |
instanceFactory(Lang.Function<Class,?> instanceFactory)
Specify a function used to create new instance during mapping process.
|
Lang._MappingStage |
keywordMatching()
Indicate field mapping shall based on
Keyword match. |
Lang._MappingStage |
looseMatching()
Alias of
keywordMatching() |
Lang._MappingStage |
map(Map<String,String> mapping)
Deprecated.
|
Lang._MappingStage.__SpecialMappingStage |
map(String sourceField)
Deprecated.
|
Lang._MappingStage.__SpecialMappingStage |
mapHead(String sourceField) |
Lang._MappingStage |
rootClass(Class<?> rootClass)
Specify the root class of target bean when getting the fields.
|
Lang._MappingStage |
semantic(DataMapper.Semantic semantic)
Change mapping semantic of this mapping stage.
|
Lang._MappingStage |
strictMatching()
Indicate field mapping shall be exactly string equal test.
|
Lang._MappingStage |
targetGenericType(Type type)
Specify target generic type.
|
Lang._MappingStage |
targetGenericType(TypeReference typeReference)
Specify target generic type by
TypeReference. |
<T> T |
to(Class<T> targetClass)
Commit the mapping stage and trigger the mapping process on an new instance created from the
targetClass specified. |
<T> T |
to(T target)
Commit the mapping stage and trigger the mapping process, return the target been copied.
|
Lang._MappingStage |
withConverter(Collection<Lang.TypeConverter> converters)
Apply a collection of
type converters during the mapping process. |
Lang._MappingStage |
withConverter(Lang.TypeConverter converter,
Lang.TypeConverter... otherConverters)
Apply type converters during the mapping process.
|
Lang._MappingStage |
withHeadMapping(Map<String,String> mapping) |
Lang._MappingStage |
withKeyTransformer(Keyword.Style targetStyle) |
Lang._MappingStage |
withKeyTransformer(Lang.Function transformer) |
Lang._MappingStage |
withSpecialNameMappings(Map<String,String> specialNameMappings)
Specify special name mapping rules.
|
public Lang._MappingStage semantic(DataMapper.Semantic semantic)
Change mapping semantic of this mapping stage.
semantic - the new mapping semantic to be usedpublic Lang._MappingStage rootClass(Class<?> rootClass)
Specify the root class of target bean when getting the fields.
For example, if your entity class extends from ModelBase, and you do not want to copy the ModelBase defined fields, then you can set ModelBase.class as root case:
$.copy(source).rootClass(ModelBase.class).to(target);
rootClass - The root classLang.fieldsOf(Class, Class, boolean)public Lang._MappingStage targetGenericType(TypeReference typeReference)
Specify target generic type by TypeReference.
This make is it easy to specify a generic type for target generic type. For example,
Map<String, User> userMap = $.map(sourceMap)
.targetGenericType(new TypeReference(Map<String, User>) {})
.to(new HashMap());
typeReference - the type reference.targetGenericType(Type)public Lang._MappingStage targetGenericType(Type type)
Specify target generic type.
This might be helpful if the target type is a container, e.g. Map or List. With the generic type specified the data mapper can handle the type matching for the container’s component types, like key and value type of a map or element type of a list.
Note the type specified must be an instance of ParameterizedType in order to effect.
type - the target generic type@Deprecated public Lang._MappingStage map(Map<String,String> mapping)
This method is deprecated. Please use withHeadMapping(Map) instead
public Lang._MappingStage withHeadMapping(Map<String,String> mapping)
@Deprecated public Lang._MappingStage.__SpecialMappingStage map(String sourceField)
This is deprecated. Please use mapHead(String) instead
public Lang._MappingStage.__SpecialMappingStage mapHead(String sourceField)
public Lang._MappingStage withConverter(Lang.TypeConverter converter, Lang.TypeConverter... otherConverters)
Apply type converters during the mapping process. If the mapping semantic is map then it allows to do type convert if source type cannot be assigned to target type.
By default it will use built-in or registered type converters in the global type converter registry.
This method allows it to provide additional type converters in addition to built-in or registered type converters in the global registry.
converter - the first type converterotherConverters - the rest type converterspublic Lang._MappingStage withConverter(Collection<Lang.TypeConverter> converters)
Apply a collection of type converters during the mapping process.
converters - A collection of type converters.public Lang._MappingStage conversionHint(Class<?> type, Object hint)
Add conversion hint associated with class.
A conversion hint could be used to manipulate conversion process employed by the mapping process when semantic. For example if the mapping process might need to map a string to a Date, it can specify the format as:
$.map(postData).conversionHint(Date.class, "yyyy-MM-dd").to(Order);
The above code will ensure the string property (if named matched) be parsed into Date using format “yyyy-MM-dd”.
type - hint - Lang.convert(Object)public Lang._MappingStage conversionHints(Map<Class,Object> conversionHints)
Add conversion hints indexed by class.
conversionHints - A map of conversion hintsconversionHint(Class, Object)public Lang._MappingStage instanceFactory(Lang.Function<Class,?> instanceFactory)
Specify a function used to create new instance during mapping process.
If not specified, then it will use OsglConfig.globalInstanceFactory()
instanceFactory - the new instance factorypublic Lang._MappingStage strictMatching()
Indicate field mapping shall be exactly string equal test.
public Lang._MappingStage looseMatching()
Alias of keywordMatching()
public Lang._MappingStage keywordMatching()
Indicate field mapping shall based on Keyword match.
Say the following names are assumed to be matching to each other:
fooBarfoo_barpublic Lang._MappingStage filter(String filterSpec)
Specify filter spec for this mapping process.
Example of filter spec:
-foo - do not map on field named foo-foo.bar - do not map on field named bar in a embedded field named fooname,email - map only fields name and emailfilterSpec - the filter spec indicates which fields shall be subject or waived in the mapping process.public Lang._MappingStage ignoreGlobalFilter()
Indicate this mapping process shall ignore global filter settings in OsglConfig.
OsglConfig.addGlobalMappingFilter(String),
OsglConfig.addGlobalMappingFilters(String, String...)public Lang._MappingStage withSpecialNameMappings(Map<String,String> specialNameMappings)
Specify special name mapping rules.
The rules shall be a string to string map with key be the target field name, and value be the source field name. For example, if it shall map id in source bean to no in the target bean, the map shall be
Map<String, String> rules = new HashMap();
rules.put("no", "id");
$.deepCopy(src).withSpecialNameMappings(rules).to(tgt);
specialNameMappings - a Map of name mapping rules.public Lang._MappingStage withKeyTransformer(Lang.Function transformer)
public Lang._MappingStage withKeyTransformer(Keyword.Style targetStyle)
public Lang._MappingStage ignoreError()
Indicate ignore exceptions encountered during mapping process.
For certain case you know that copy between source and target will fail as they were not the same type object and some fields might encounter type mismatch issue, however you do want to copy the fields that are able to be copied, in this scenario you can dictate copy process to ignore error:
$.deepCopy(source).ignoreError().to(target);
public <T> T to(T target)
Commit the mapping stage and trigger the mapping process, return the target been copied.
Generally the returned instance should be the same instance of to passed in. However when copied to an array which has less elements than the source array or collection, an new array instance with the same component type with to will be created and populated. The original to array will be left unchanged. The return value is the new array instance.
T - the generic type parameter of the target.target - target objectto if to is an arraypublic <T> T to(Class<T> targetClass)
Commit the mapping stage and trigger the mapping process on an new instance created from the targetClass specified.
T - the generic type parameter of targetClasstargetClass - the class used to create target instanceto(Object)Copyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.