3
3
# Object Mapper
4
4
5
5
** Version**
6
- 1.0.6
6
+ 1.1.0
7
7
8
8
** Author**
9
9
marazt
@@ -15,45 +15,46 @@ marazt
15
15
The MIT License (MIT)
16
16
17
17
** Last updated**
18
- 28 October 2018
18
+ 10 June 2019
19
19
20
20
** Package Download**
21
21
https://pypi.python.org/pypi/object-mapper
22
+
22
23
---
23
24
24
25
## Versions
25
26
27
+ ** 1.1.0 - 2019/06/10**
28
+
29
+ - Add basic support for nested object, thanks [ @direbearform ] ( https://github.com/direbearform )
30
+
26
31
** 1.0.6 - 2018/10/28**
27
32
28
- * Added ability to specify excluded fields, thanks [ @uralov ] ( https://github.com/uralov )
33
+ - Added ability to specify excluded fields, thanks [ @uralov ] ( https://github.com/uralov )
29
34
30
35
** 1.0.5 - 2018/02/21**
31
36
32
- * Support for dynamic properties [ @nijm ] ( https://github.com/nijm )
37
+ - Support for dynamic properties [ @nijm ] ( https://github.com/nijm )
33
38
34
39
** 1.0.4 - 2017/11/03**
35
40
36
- * Migration to new Pypi.org deployment
41
+ - Migration to new Pypi.org deployment
37
42
38
43
** 1.0.3 - 2015/05/15**
39
44
40
- * Added support for None mapping [ @ramiabughazaleh ] ( https://github.com/ramiabughazaleh )
41
-
45
+ - Added support for None mapping [ @ramiabughazaleh ] ( https://github.com/ramiabughazaleh )
42
46
43
47
** 1.0.2 - 2015/05/06**
44
48
45
- * Added support for case insensitivity mapping [ @ramiabughazaleh ] ( https://github.com/ramiabughazaleh )
46
-
49
+ - Added support for case insensitivity mapping [ @ramiabughazaleh ] ( https://github.com/ramiabughazaleh )
47
50
48
51
** 1.0.1 - 2015/02/19**
49
52
50
- * Fix of the package information
51
-
53
+ - Fix of the package information
52
54
53
55
** 1.0.0 - 2015/02/19**
54
56
55
- * Initial version
56
-
57
+ - Initial version
57
58
58
59
## About
59
60
@@ -64,80 +65,80 @@ It helps you to create objects between project layers (data layer, service layer
64
65
65
66
1 . ** Mapping of the properties without mapping definition**
66
67
67
- In this case are mapped only these properties of the target class which
68
- are in target and source classes. Other properties are not mapped.
69
- Suppose we have class ` A ` with attributes ` name ` and ` last_name `
70
- and class ` B ` with attribute ` name ` .
71
- Initialization of the ObjectMapper will be:
68
+ In this case are mapped only these properties of the target class which
69
+ are in target and source classes. Other properties are not mapped.
70
+ Suppose we have class ` A ` with attributes ` name ` and ` last_name `
71
+ and class ` B ` with attribute ` name ` .
72
+ Initialization of the ObjectMapper will be:
72
73
73
- ``` python
74
- mapper = ObjectMapper()
75
- mapper.create_map(A, B)
76
- instance_b = mapper.map(A(), B)
77
- ```
74
+ ``` python
75
+ mapper = ObjectMapper()
76
+ mapper.create_map(A, B)
77
+ instance_b = mapper.map(A(), B)
78
+ ```
78
79
79
- In this case, value of A.name will be copied into B.name.
80
+ In this case, value of A.name will be copied into B.name.
80
81
81
82
2 . ** Mapping with defined mapping functions**
82
83
83
- Suppose we have class ` A ` with attributes ` first_name ` and ` last_name `
84
- , class ` B ` with attribute ` full_name ` and class ` C ` with attribute reverse_name.
85
- And want to map it in a way ` B.full_name = A.first_name + A.last_name ` and
86
- ` C.reverse_name = A.last_name + A.first_name `
87
- Initialization of the ObjectMapper will be:
84
+ Suppose we have class ` A ` with attributes ` first_name ` and ` last_name `
85
+ , class ` B ` with attribute ` full_name ` and class ` C ` with attribute reverse_name.
86
+ And want to map it in a way ` B.full_name = A.first_name + A.last_name ` and
87
+ ` C.reverse_name = A.last_name + A.first_name `
88
+ Initialization of the ObjectMapper will be:
88
89
89
- ``` python
90
- mapper = ObjectMapper()
91
- mapper.create_map(A, B, {' name' : lambda a : a.first_name + " " + a.last_name})
92
- mapper.create_map(A, C, {' name' : lambda a : a.last_name + " " + a.first_name})
90
+ ``` python
91
+ mapper = ObjectMapper()
92
+ mapper.create_map(A, B, {' name' : lambda a : a.first_name + " " + a.last_name})
93
+ mapper.create_map(A, C, {' name' : lambda a : a.last_name + " " + a.first_name})
93
94
94
- instance_b = mapper.map(A(), B)
95
- instance_c = mapper.map(A(), C)
96
- ```
95
+ instance_b = mapper.map(A(), B)
96
+ instance_c = mapper.map(A(), C)
97
+ ```
97
98
98
- In this case, to the ` B.name ` will be mapped ` A.first_name + " " + A.last_name `
99
- In this case, to the ` C.name ` will be mapped ` A.last_name + " " + A.first_name `
99
+ In this case, to the ` B.name ` will be mapped ` A.first_name + " " + A.last_name `
100
+ In this case, to the ` C.name ` will be mapped ` A.last_name + " " + A.first_name `
100
101
101
102
3 . ** Mapping suppression**
102
103
103
- For some purposes, it can be needed to suppress some mapping.
104
- Suppose we have class ` A ` with attributes ` name ` and ` last_name `
105
- and class ` B ` with attributes ` name ` and ` last_name ` .
106
- And we want to map only the ` A.name ` into ` B.name ` , but not ` A.last_name ` to
107
- ` B.last_name `
108
- Initialization of the ObjectMapper will be:
104
+ For some purposes, it can be needed to suppress some mapping.
105
+ Suppose we have class ` A ` with attributes ` name ` and ` last_name `
106
+ and class ` B ` with attributes ` name ` and ` last_name ` .
107
+ And we want to map only the ` A.name ` into ` B.name ` , but not ` A.last_name ` to
108
+ ` B.last_name `
109
+ Initialization of the ObjectMapper will be:
109
110
110
- ``` python
111
- mapper = ObjectMapper()
112
- mapper.create_map(A, B, {' last_name' : None })
111
+ ``` python
112
+ mapper = ObjectMapper()
113
+ mapper.create_map(A, B, {' last_name' : None })
113
114
114
- instance_b = mapper.map(A(), B)
115
- ```
115
+ instance_b = mapper.map(A(), B)
116
+ ```
116
117
117
- In this case, value of A.name will be copied into ` B.name ` automatically by the attribute name ` name ` .
118
- Attribute ` A.last_name ` will be not mapped thanks the suppression (lambda function is None).
118
+ In this case, value of A.name will be copied into ` B.name ` automatically by the attribute name ` name ` .
119
+ Attribute ` A.last_name ` will be not mapped thanks the suppression (lambda function is None).
119
120
120
121
4 . ** Case insensitive mapping**
121
122
122
- Suppose we have class ` A ` with attributes ` Name ` and ` Age ` and
123
- class ` B ` with attributes ` name ` and ` age ` and we want to map ` A ` to ` B ` in a way
124
- ` B.name ` = ` A.Name ` and ` B.age ` = ` A.Age `
125
- Initialization of the ObjectMapper will be:
123
+ Suppose we have class ` A ` with attributes ` Name ` and ` Age ` and
124
+ class ` B ` with attributes ` name ` and ` age ` and we want to map ` A ` to ` B ` in a way
125
+ ` B.name ` = ` A.Name ` and ` B.age ` = ` A.Age `
126
+ Initialization of the ObjectMapper will be:
126
127
127
- ``` python
128
- mapper = ObjectMapper()
129
- mapper.create_map(A, B)
130
- instance_b = mapper.map(A(), B, ignore_case = True )
131
- ```
128
+ ``` python
129
+ mapper = ObjectMapper()
130
+ mapper.create_map(A, B)
131
+ instance_b = mapper.map(A(), B, ignore_case = True )
132
+ ```
132
133
133
- In this case, the value of A.Name will be copied into B.name and
134
- the value of A.Age will be copied into B.age.
134
+ In this case, the value of A.Name will be copied into B.name and
135
+ the value of A.Age will be copied into B.age.
135
136
136
- ** Note:** You can find more examples in tests package
137
+ ** Note:** You can find more examples in tests package
137
138
138
139
## Installation
139
140
140
- * Download this project
141
- * Download from Pypi: https://pypi.python.org/pypi/object-mapper
141
+ - Download this project
142
+ - Download from Pypi: https://pypi.python.org/pypi/object-mapper
142
143
143
- ### ENJOY IT!
144
+ ### ENJOY IT!
0 commit comments