Custom toJSON and toObject Implementation Produces Object Instead of Plain Value #15084
Open
1 task done
Labels
new feature
This change adds new functionality, like a new method or class
Milestone
Prerequisites
Mongoose version
7.6.3
Node.js version
22.10
MongoDB version
5
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
I'm encountering an issue with implementing custom
toJSON
andtoObject
behavior for a custom type. My goal is to produce different outputs when converting the custom type's value—specifically, I want to output a plain number or string instead of the object representation.However, despite my efforts, the result always includes the object representation, such as:
value: CustomType { value: 1 },
.Below is a minimal reproduction of the issue:
I would greatly appreciate any guidance on resolving this issue or understanding why the current implementation doesn't work as expected.
The text was updated successfully, but these errors were encountered: