Skip to content

Feature - ignore name metadata #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Lets have a look at an example:
```typescript
class SimpleRoster {
@JsonProperty()
private name: String;
private name: String = undefined;
@JsonProperty()
private worksOnWeekend: Boolean;
private worksOnWeekend: Boolean = undefined;
@JsonProperty()
private numberOfHours: Number;
private numberOfHours: Number = undefined;
@JsonProperty({type:Date})
private systemDate: Date;

Expand Down Expand Up @@ -140,7 +140,33 @@ and make sure to import it in a global place, like app.ts:
import "reflect-metadata";
```
If you are using Angular 2 you should already have this shim installed.

## Things to remember

### Ignoring `name` metadata during de-serialization
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:

```typescript
class Event {
@JsonProperty()
id: number = undefined;
@JsonProperty({ name: "geo-location" })
location = "old";
}

const json = {
id: "1",
location: "Canberra",
};

const testInstance: Event = ObjectMapper.deserialize(Event, json, {ignoreNameMetadata: true});
expect(testInstance.location).toBe("Canberra");

const serialized = ObjectMapper.serialize(testInstance);
aexpect(serialized).toBe('{"id":"1","geo-location":"Canberra"}');

```

### Enum serialization and de-serialization
You can use `enum` data type by specifying the `type` property of @JsonProperty decorator.
You will need to use `Serializer` and `Deserializer` to make the enum work correctly.
Expand Down
Loading
Loading