Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plainToClass - discriminator is deleted in plain/source object #239

Open
hohler opened this issue Mar 1, 2019 · 1 comment · May be fixed by #1118
Open

plainToClass - discriminator is deleted in plain/source object #239

hohler opened this issue Mar 1, 2019 · 1 comment · May be fixed by #1118

Comments

@hohler
Copy link

hohler commented Mar 1, 2019

When using plainToClass with a plain object in combination with @type and a discriminator, it will delete the discriminator from that plain object.
A workaround is either to clone the object, or to have keepDiscriminatorProperty set to true on the @type definition. But then it will also be kept in the target object.

I think the root cause is in TransformOperationExecutor.ts on line 51:
if (!targetType.options.keepDiscriminatorProperty) delete subValue[targetType.options.discriminator.property];

I can't make a fix / PR right now because of lack of time, but I like to have the issue documented here.

@alexpls
Copy link

alexpls commented Apr 18, 2019

@hohler I could replicate this by adding the following test: b402d62

I'd be happy to work on a PR to fix this once the project is under active maintenance again.

@kol-93 kol-93 linked a pull request Feb 21, 2022 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants