You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have database entity class that i want to serialize and store to db as a record. Before serializing I want Date types to be converted to ISO String and have a custom transformer to do that. When I use instanceToPlain to convert this to plain object I see the transformer is getting invoked but its getting reset back to Date object.
classUser{id: numbername: string
@Type(()=>Date)
@Transform(({ value })=>value.toISOString(),{toPlainOnly: true})
@Transform(({ value })=>newDate(value),{toClassOnly: true})date: Dateconstructor(user: Partial<User>){this.id=user.id??0this.name=user.name??''this.date=user.date??newDate()}}constuser=newUser({})constobj=instanceToPlain(user)console.log(typeofobj.date,obj.dateinstanceofDate)// type should be string but getting as date
finalValue=value[transformKey]===finalValue ? subValue : finalValue;// final value is string till this point as it got from custom transformationfinalValue=this.transform(subSource,finalValue,type,arrayType,isSubValueMap,level+1);// it got converted back to Date object here
The text was updated successfully, but these errors were encountered:
Description
I have database entity class that i want to serialize and store to db as a record. Before serializing I want Date types to be converted to ISO String and have a custom transformer to do that. When I use
instanceToPlain
to convert this to plain object I see the transformer is getting invoked but its getting reset back to Date object.https://github.com/typestack/class-transformer/blob/develop/sample/sample5-custom-transformer/User.ts you can use this itself as an example.
The problem seems to be https://github.com/typestack/class-transformer/blob/develop/src/TransformOperationExecutor.ts#L327
The text was updated successfully, but these errors were encountered: