Skip to content

feature: Option to skip default transformation with Transform decorator #719

Open
@fschucht

Description

@fschucht

Description

We are using class-transformer to serialize & deserialize messages sent between microservices. In our specific case we need to convert a mongo object id to a buffer and then convert it back to an object id. This almost works perfectly except that a default transformation is applied which turns the object id into an object:

Pseudo code:

class Message {
  @Transform(encodeObjectId, { toClassOnly: true }) // Transform a object id to a buffer
  @Transform(decodeObjectId, { toPlainOnly: true }) // Transforms a buffer to a object id
  _id: Buffer;
}

const encoded = plainToClass(Message, { _id: new ObjectId() })
const decoded = classToPlain(encoded)

In this example decoded will be { _id: { _bsontype: 'ObjectID', id: <Buffer 60 93 c5 68 a5 21 45 11 1f 10 1a bb> } } rather than the object id we transformed to.

Proposed solution

It would be great if Transform would accept a skipDefaultTransformations option to allow returning the raw value of the transformation without any hidden transformations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions