Skip to content

Instantly share code, notes, and snippets.

@pichillilorenzo
Created May 3, 2020 19:53
Show Gist options
  • Save pichillilorenzo/608c1e6aec1bae769d02adb115b9d045 to your computer and use it in GitHub Desktop.
Save pichillilorenzo/608c1e6aec1bae769d02adb115b9d045 to your computer and use it in GitHub Desktop.
@JsonClassType() example
import { JsonClassType } from 'jackson-js';
class Foo2 { }
class Foo {
@JsonClassType({type: () => [Number]})
barNumber: number;
@JsonClassType({type: () => [String]})
barString: string;
@JsonClassType({type: () => [Foo2]})
barFoo2: Foo2;
@JsonClassType({type: () => [Array, [Number]]})
barNumberArray: number[] = [];
@JsonClassType({type: () => [Array, [Foo2]]})
barFoo2Array: Foo2[] = [];
@JsonClassType({type: () => [Map, [String, Foo2]]})
barMap: Map<string, Foo2> = new Map();
@JsonClassType({type: () => [Object, [String, Foo2]]})
barObjectLiteral: Record<string, Foo2> = {};
@JsonClassType({type: () => [Set, [String]]})
barSet: Set<string> = new Set();
@JsonClassType({type: () => [Array, [Set, [Foo2]]]})
barMix: Array<Set<Foo2>> = [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment