typestack / class-transformer

Decorator-based transformation, serialization, and deserialization between objects and classes.
MIT License
6.83k stars 500 forks source link

question: Is there an option to not modify a property and keep its internal getters as it is? #865

Open GorvGoyl opened 3 years ago

GorvGoyl commented 3 years ago

classToPlain method is removing internal getters from the object property.

These getters comes from firestore.Timestamp so I can't set @Expose on these.

As you can see, property updated has 2 methods nanoseconds(get){} and seconds(get){}.

image

After running through classToPlain, these 2 methods get removed:

image

Due to these missing getters, updated property gets stored in Firestore as object { _nanoseconds:xxx, _seconds:xxx } instead of Timestamp.

I tried setting @Transform and returning the object as it is but classToPlain still removed the getters.

@Transform(({ value }) => (value), { toPlainOnly: true })
updated: FirebaseFirestore.Timestamp;

How to tell classToPlain to not touch a property while transformation i.e. don't remove any methods set to it?

LaysDragon commented 1 year ago

well I want to use class-transformer as some kind of dto convertor in my application,to mapping its to half-pure plain object,but it seems not really design to work with environment that have their own primitive type. This issue is similar to #1148