@@ -101,8 +101,10 @@ def create_map(self, type_from: type, type_to: type, mapping: Dict =None):
101
101
102
102
if (type (type_from ) is not type ):
103
103
raise ObjectMapperException (f"type_from must be a type" )
104
+
104
105
if (type (type_to ) is not type ):
105
106
raise ObjectMapperException (f"type_to must be a type" )
107
+
106
108
if (mapping is not None and not isinstance (mapping , Dict )):
107
109
raise ObjectMapperException (f"mapping, if provided, must be a Dict type" )
108
110
@@ -162,7 +164,7 @@ def map(self, from_obj, to_type: type=type(None), ignore_case: bool=False, allow
162
164
raise ObjectMapperException (f"No mapping defined for { key_from } to { key_to } " )
163
165
key_to_cls = self .mappings [key_from ][key_to ][0 ]
164
166
custom_mappings = self .mappings [key_from ][key_to ][1 ]
165
-
167
+
166
168
# Currently, all target class data members need to have default value
167
169
# Object with __init__ that carries required non-default arguments are not supported
168
170
inst = key_to_cls ()
@@ -173,14 +175,14 @@ def not_private(s):
173
175
def not_excluded (s ):
174
176
return not (excluded and s in excluded )
175
177
176
- def is_included (s ):
177
- return included and s in included
178
+ def is_included (s , mapping ):
179
+ return ( included and s in included ) or ( mapping and s in mapping )
178
180
179
181
from_obj_attributes = getmembers (from_obj , lambda a : not isroutine (a ))
180
182
from_obj_dict = {k : v for k , v in from_obj_attributes }
181
183
182
184
to_obj_attributes = getmembers (inst , lambda a : not isroutine (a ))
183
- to_obj_dict = {k : v for k , v in to_obj_attributes if not_excluded (k ) and (not_private (k ) or is_included (k ))}
185
+ to_obj_dict = {k : v for k , v in to_obj_attributes if not_excluded (k ) and (not_private (k ) or is_included (k , custom_mappings ))}
184
186
185
187
if ignore_case :
186
188
from_props = CaseDict (from_obj_dict )
0 commit comments