Skip to content

question: classToClass of different types object with null value fails #518

@kafkapre

Description

@kafkapre

Hello I tried example of Providing more than one type option classes (https://github.com/typestack/class-transformer#providing-more-than-one-type-option).

When I call eg.

classToClass( plainToClass(Album, JSON.parse( "{\n" + " \"id\": 1,\n" + \"name\": \"foo\",\n" + " \"topPhoto\": {\n" + " \"id\": 9,\n" + " \"filename\": \"cool_wale.jpg\",\n" + " \"depth\": 1245,\n" + " \"__type\": \"underwater\"\n" + " }\n" + "}" ))

it works, but when topPhoto is null it fails. Eg.

classToClass( plainToClass(Album, JSON.parse( "{\n" + " \"id\": 1,\n" + " \"name\": \"foo\",\n" + " \"topPhoto\": null" + "}") ))
In documentation is written that discriminator must be defined (which is not in this case). Is there any workaround to pass this code without error (I want to avoid any wrapper classes)? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: cannot reproduceBug reports which cannot be reproduced.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions