|
2 | 2 | """
|
3 | 3 | Copyright (C) 2015, marazt. All rights reserved.
|
4 | 4 | """
|
5 |
| -from mapper.object_mapper_exception import ObjectMapperException |
| 5 | +from enum import Enum |
| 6 | +from inspect import getmembers, isroutine, isclass |
| 7 | + |
6 | 8 | from mapper.casedict import CaseDict
|
7 |
| -from inspect import getmembers, isroutine |
| 9 | +from mapper.object_mapper_exception import ObjectMapperException |
| 10 | + |
8 | 11 |
|
9 | 12 | class ObjectMapper(object):
|
10 | 13 | """
|
@@ -91,8 +94,8 @@ def create_map(self, type_from, type_to, mapping=None):
|
91 | 94 |
|
92 | 95 | :return: None
|
93 | 96 | """
|
94 |
| - key_from = type_from.__name__ |
95 |
| - key_to = type_to.__name__ |
| 97 | + key_from = type_from |
| 98 | + key_to = type_to |
96 | 99 |
|
97 | 100 | if mapping is None:
|
98 | 101 | mapping = {}
|
@@ -165,7 +168,17 @@ def not_excluded(s):
|
165 | 168 |
|
166 | 169 | else:
|
167 | 170 | # try find property with the same name in the source
|
168 |
| - if prop in from_props: |
| 171 | + if prop not in from_props: |
| 172 | + continue |
| 173 | + |
| 174 | + prop_to_type = type(from_props[prop]) |
| 175 | + |
| 176 | + if isclass(prop_to_type) and \ |
| 177 | + not issubclass(prop_to_type, Enum) and \ |
| 178 | + prop_to_type is not type(None) and \ |
| 179 | + not __builtins__.get(type(from_props[prop]).__name__): |
| 180 | + self.map(from_props[prop], key_to, allow_none=allow_none) |
| 181 | + else: |
169 | 182 | setattr(inst, prop, from_props[prop])
|
170 | 183 | # case when target attribute is not mapped (can be extended)
|
171 | 184 | else:
|
|
0 commit comments