Polymorphism
andreaslarssen opened this issue · 2 comments
andreaslarssen commented
With:
export class ClientErrorResponse {
@serializable(alias('error', raw())) protected _error: {messages: [{message: string}]};
}
export class UnauthorizedResponse extends ClientErrorResponse {}
...and then deserializing UnauthorizedResponse:
deserialize(UnauthorizedResponse, data);
...i get an instance of ClientErrorResponse, not the UnauthorizedResponse I hoped for, but when defining schemas this way:
export const UnauthorizedResponseSchema = {
factory: context => new UnauthorizedResponse(),
extends: ClientErrorResponseSchema,
props: {}
};
export const ClientErrorResponseSchema = {
factory: context => new ClientErrorResponse(),
extends: BaseResponseSchema,
props: {
error: raw()
}
};
...and then:
deserialize(UnauthorizedResponseSchema, error);
...it gives me an instance of UnauthorizedResponse.
Is this cool? Is it something I'm missing?
waliarubal commented
I am facing exact same kind of issue, i am serializing child class and on de-serialization I am receiving object of base class which doesn't has additional properties defined in child class. Seems to me an issue, kindly provide a fix or a workaround.
andreaslarssen commented
Thought I'd look into this. Are there any contrib docs I could look at?