OpenAPI JSON Serializer
This serializer processes JSON payloads for the OpenAPIHandler and supports native data types.
Extending Native Data Types
Customize serialization by creating your own StandardOpenAPICustomJsonSerializer and adding it to the customJsonSerializers option.
Define Your Custom Serializer
tsimport type { StandardOpenAPICustomJsonSerializer } from '@orpc/openapi-client/standard' export classUser{ constructor( public readonlyid: string, public readonlyname: string, public readonlyemail: string, public readonlyage: number, ) {}toJSON() { return {id: this.id,name: this.name,email: this.email,age: this.age, } } } export constuserSerializer: StandardOpenAPICustomJsonSerializer = {condition:data=>datainstanceofUser,serialize:data=>data.toJSON(), }Use Your Custom Serializer
tsconsthandler= newOpenAPIHandler(router, {customJsonSerializers: [userSerializer], }) constgenerator= newOpenAPIGenerator({customJsonSerializers: [userSerializer], })INFO
It is recommended to add custom serializers to the
OpenAPIGeneratorfor consistent serialization in the OpenAPI document.
