-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Is there any way this library supports polymorphism?
e.g.
import { JsonProperty, Serializable, deserialize, serialize } from 'ts-jackson';
@Serializable()
class Polymorphic {}
@Serializable()
export class PolyA extends Polymorphic {
@JsonProperty()
name: string = 'PolyA';
@JsonProperty()
isSomethng: boolean = false;
}
@Serializable()
export class PolyB extends Polymorphic {
@JsonProperty()
name: string = 'PolyB';
@JsonProperty()
value: number = 50;
}
@Serializable()
export class HasPolymorphic {
@JsonProperty({
elementType: Polymorphic
})
public polys: Polymorphic[] = [];
}
const instance = new HasPolymorphic();
instance.polys.push(new PolyA());
instance.polys.push(new PolyB());
console.dir(instance);
const serialized = serialize(instance); // Uncaught TypeError: Cannot convert undefined or null to object
console.log(serialized);
const deserialized = deserialize(serialized, HasPolymorphic);
console.dir(deserialized);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels