Skip to content

ClassSerializerInterceptorOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/common/serializer/class-serializer.interceptor.ts

Part of: Common

ClassSerializerInterceptorOptions configures the transformer implementation used by NestJS's ClassSerializerInterceptor. Its transformerPackage field allows applications to provide a compatible serialization package, such as class-transformer, when customizing response serialization behavior.

Properties

PropertyType
transformerPackageTransformerPackage

Diagram

mermaid
graph LR
  A[Controller Response] --> B[ClassSerializerInterceptor]
  B --> C[ClassSerializerInterceptorOptions]
  C --> D[transformerPackage]
  D --> E[Transformer Package]
  E --> F[Serialized HTTP Response]

Usage

ts
import { ClassSerializerInterceptor } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import * as classTransformer from 'class-transformer';

const serializerOptions = {
  transformerPackage: classTransformer,
};

const serializerInterceptor = new ClassSerializerInterceptor(
  new Reflector(),
  serializerOptions,
);

// Register globally or apply with @UseInterceptors(serializerInterceptor).

AI Coding Instructions

  • Provide a transformerPackage implementation compatible with the APIs expected by ClassSerializerInterceptor.
  • Use class-transformer as the standard package unless the application intentionally supplies an alternative compatible implementation.
  • Ensure the configured package is installed and available at runtime; missing transformer dependencies can break response serialization.
  • Apply the interceptor globally or at controller/route level when serialized DTO output is required.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Injected or called by (1)

  • ClassSerializerInterceptorpackages/common/serializer/class-serializer.interceptor.ts:34

Was this page helpful?

Download as PDF
ClassSerializerInterceptorOptions — NestJS head-to-head