Skip to content

Commit 1b2ac72

Browse files
authored
Merge pull request #83 from shakilsiraj/feature/ignore-name-check
Feature - ignore name metadata
2 parents 66c9872 + 9eda9af commit 1b2ac72

12 files changed

+211316
-32396
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Lets have a look at an example:
4343
```typescript
4444
class SimpleRoster {
4545
@JsonProperty()
46-
private name: String;
46+
private name: String = undefined;
4747
@JsonProperty()
48-
private worksOnWeekend: Boolean;
48+
private worksOnWeekend: Boolean = undefined;
4949
@JsonProperty()
50-
private numberOfHours: Number;
50+
private numberOfHours: Number = undefined;
5151
@JsonProperty({type:Date})
5252
private systemDate: Date;
5353

@@ -140,7 +140,33 @@ and make sure to import it in a global place, like app.ts:
140140
import "reflect-metadata";
141141
```
142142
If you are using Angular 2 you should already have this shim installed.
143+
143144
## Things to remember
145+
146+
### Ignoring `name` metadata during de-serialization
147+
If you have an use case where you want to not use `name` metadata using de-serialization, the you cna turn if off by setting `ignoreNameMetadata` to true (default is false). Here is an example usage:
148+
149+
```typescript
150+
class Event {
151+
@JsonProperty()
152+
id: number = undefined;
153+
@JsonProperty({ name: "geo-location" })
154+
location = "old";
155+
}
156+
157+
const json = {
158+
id: "1",
159+
location: "Canberra",
160+
};
161+
162+
const testInstance: Event = ObjectMapper.deserialize(Event, json, {ignoreNameMetadata: true});
163+
expect(testInstance.location).toBe("Canberra");
164+
165+
const serialized = ObjectMapper.serialize(testInstance);
166+
aexpect(serialized).toBe('{"id":"1","geo-location":"Canberra"}');
167+
168+
```
169+
144170
### Enum serialization and de-serialization
145171
You can use `enum` data type by specifying the `type` property of @JsonProperty decorator.
146172
You will need to use `Serializer` and `Deserializer` to make the enum work correctly.

0 commit comments

Comments
 (0)