Skip to content

Instantly share code, notes, and snippets.

@pichillilorenzo
Created May 3, 2020 19:12
Show Gist options
  • Save pichillilorenzo/122ae36dfc67e1b40a5f24c26f41c662 to your computer and use it in GitHub Desktop.
Save pichillilorenzo/122ae36dfc67e1b40a5f24c26f41c662 to your computer and use it in GitHub Desktop.
@JsonAppend() example
import { JsonProperty, JsonClassType, ObjectMapper, JsonAppend } from 'jackson-js';
@JsonAppend({attrs: [{
value: 'version',
}]})
class User {
@JsonProperty() @JsonClassType({type: () => [Number]})
id: number;
@JsonProperty() @JsonClassType({type: () => [String]})
email: string;
constructor(id: number, email: string) {
this.id = id;
this.email = email;
}
}
const user = new User(1, 'john.alfa@gmail.com');
const objectMapper = new ObjectMapper();
const jsonData = objectMapper.stringify<User>(user, {
attributes: {
version: 1.2
}
});
console.log(jsonData);
// {"id":1,"email":"john.alfa@gmail.com","version":1.2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment