Open
Description
Hey guys.
I need to deserialize an array which holds many objects of many different types.
The type of the object inside the array is defined by a property which I can use to find the appropriate constructor. The problem is I don't how to make class-transform do this:
interface SomeAbstract{}
class Concrete1 implements SomeAbstract {
type = 'concrete1'
}
class Concrete2 implements SomeAbstract {
type = 'concrete2'
}
class SerializableObject {
@Type((opt) => {
const myobj = <any>opt.object
if(myobj.type == 'concrete1') return Concrete1
if(myobj.type == 'concrete2') return Concrete1
throw 'unkown type!'
})
manyTypes: SomeAbstract[]
}
The problem happens because opt.object
refers to the array itself, and not each item of the array. How can I overcome this?
Regards.