Skip to content

Commit be5b3bf

Browse files
author
direbearform
committed
support for nested map
1 parent b02c6d6 commit be5b3bf

File tree

4 files changed

+243
-112
lines changed

4 files changed

+243
-112
lines changed

README.md

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Object Mapper
44

55
**Version**
6-
1.0.6
6+
1.1.0
77

88
**Author**
99
marazt
@@ -15,45 +15,46 @@ marazt
1515
The MIT License (MIT)
1616

1717
**Last updated**
18-
28 October 2018
18+
10 June 2019
1919

2020
**Package Download**
2121
https://pypi.python.org/pypi/object-mapper
22+
2223
---
2324

2425
## Versions
2526

27+
**1.1.0 - 2019/06/10**
28+
29+
- Add basic support for nested object, thanks [@direbearform](https://github.com/direbearform)
30+
2631
**1.0.6 - 2018/10/28**
2732

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)
2934

3035
**1.0.5 - 2018/02/21**
3136

32-
* Support for dynamic properties [@nijm](https://github.com/nijm)
37+
- Support for dynamic properties [@nijm](https://github.com/nijm)
3338

3439
**1.0.4 - 2017/11/03**
3540

36-
* Migration to new Pypi.org deployment
41+
- Migration to new Pypi.org deployment
3742

3843
**1.0.3 - 2015/05/15**
3944

40-
* Added support for None mapping [@ramiabughazaleh](https://github.com/ramiabughazaleh)
41-
45+
- Added support for None mapping [@ramiabughazaleh](https://github.com/ramiabughazaleh)
4246

4347
**1.0.2 - 2015/05/06**
4448

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)
4750

4851
**1.0.1 - 2015/02/19**
4952

50-
* Fix of the package information
51-
53+
- Fix of the package information
5254

5355
**1.0.0 - 2015/02/19**
5456

55-
* Initial version
56-
57+
- Initial version
5758

5859
## About
5960

@@ -64,80 +65,80 @@ It helps you to create objects between project layers (data layer, service layer
6465

6566
1. **Mapping of the properties without mapping definition**
6667

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:
7273

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+
```
7879

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.
8081

8182
2. **Mapping with defined mapping functions**
8283

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:
8889

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})
9394

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+
```
9798

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`
100101

101102
3. **Mapping suppression**
102103

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:
109110

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})
113114

114-
instance_b = mapper.map(A(), B)
115-
```
115+
instance_b = mapper.map(A(), B)
116+
```
116117

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).
119120

120121
4. **Case insensitive mapping**
121122

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:
126127

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+
```
132133

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.
135136

136-
**Note:** You can find more examples in tests package
137+
**Note:** You can find more examples in tests package
137138

138139
## Installation
139140

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
142143

143-
### ENJOY IT!
144+
### ENJOY IT!

0 commit comments

Comments
 (0)