Closed Sygun closed 2 months ago
Hi @Sygun,
I had a few minutes to check out this issue and found that it should be working. There are tests for this specific scenario.
What I see in your example is that you call plainToInstance
, but you have the transformer with option { toPlainOnly: true }
, so it will not run in this example.
Could you solve this issue or moved on with a different solution? If you still need help with this could you provide a bit more information on how to reproduce this behavior?
Edit: You need to add the @Expose
decorator to the @Transform
to run.
I believe this question has been answered and seems inactive, so I close the issue.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I was integrating the class-transformer library into my project to leverage its capabilities for transforming plain objects into class instances with complex transformations. My goal was to utilize the
@Transform
decorator for custom transformations and to pass specific transformation options through the plainToInstance function. Here's an example to illustrate my approach:The problem:
While attempting to achieve the above, I encountered an issue where the
options
passed toplainToInstance
were not being reflected inside the@Transform
decorator function. Despite passing{ excludeExtraneousValues: true, groups: ['no-datetime-transform'] }
as options, within the @Transform decorator, the options object appears to only contain default values rather than the ones explicitly provided. This behavior deviates from my expectations, as I anticipated that the options object accessible within the@Transform
decorator would mirror the options passed toplainToInstance
.This unexpected behavior is impacting my ability to perform conditional transformations based on the provided options, limiting the flexibility and utility of the class-transformer in my project. I have confirmed that my project dependencies are up to date, and I have followed the documentation and examples provided by class-transformer closely to ensure my implementation is correct.
I am seeking guidance on whether this is a known limitation, a bug, or if there is an alternative approach to achieving the desired outcome where
@Transform
decorator functions can access and utilize the transformation options passed toplainToInstance
. Any insights, workarounds, or fixes would be greatly appreciated.