UNPKG

@solid-nestjs/rest-api

Version:

solid-nestjs Rest-API utilities

31 lines 981 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransformFromJson = void 0; const class_transformer_1 = require("class-transformer"); /** * Property decorator that transforms a JSON string property into its parsed object form * when deserializing (i.e., converting plain objects to class instances). * * If the property value is a valid JSON string, it will be parsed using `JSON.parse`. * If parsing fails, the original value is returned. * * @returns A property decorator to be used with class-transformer. * * @example * ```typescript * class ExampleDto { * @TransformFromJson() * public data: any; * } * ``` */ const TransformFromJson = () => (0, class_transformer_1.Transform)(({ value }) => { try { return JSON.parse(value); } catch (e) { return value; } }, { toClassOnly: true }); exports.TransformFromJson = TransformFromJson; //# sourceMappingURL=transform-from-json.decorator.js.map