diff --git a/docs/docs/json-mapper.md b/docs/docs/json-mapper.md index afb5e81195b..651bdf1ed63 100644 --- a/docs/docs/json-mapper.md +++ b/docs/docs/json-mapper.md @@ -110,7 +110,7 @@ It means, if you missed decorating one or more properties on your model, these p ## Ignore properties (deprecated) -::: warn deprecated +::: warning deprecated This decorator is deprecated. Use @@Groups@@ decorator instead of. ::: @@ -318,7 +318,7 @@ and import the mapper in your application. -::: warn +::: warning Ts.ED doesn't transform Date to date format or hours format because it depends on each project guidelines. diff --git a/packages/specs/json-mapper/src/interfaces/JsonMapperMethods.ts b/packages/specs/json-mapper/src/interfaces/JsonMapperMethods.ts index f69abb33d62..65fc095473f 100644 --- a/packages/specs/json-mapper/src/interfaces/JsonMapperMethods.ts +++ b/packages/specs/json-mapper/src/interfaces/JsonMapperMethods.ts @@ -4,6 +4,9 @@ export interface JsonMapperCtx { collectionType: Type | undefined; type: Type | T; next: JsonMapperNext; + options: { + format?: string; + }; } export interface JsonMapperNext { diff --git a/packages/specs/json-mapper/test/integration/date.integration.spec.ts b/packages/specs/json-mapper/test/integration/date.integration.spec.ts index a5c17edd7f3..6d0d4e3a24c 100644 --- a/packages/specs/json-mapper/test/integration/date.integration.spec.ts +++ b/packages/specs/json-mapper/test/integration/date.integration.spec.ts @@ -1,12 +1,12 @@ import {isBoolean} from "@tsed/core"; import {DateFormat} from "@tsed/schema"; -import {JsonMapper, JsonMapperContext, JsonMapperMethods, serialize} from "../../src/index"; +import {JsonMapper, JsonMapperCtx, JsonMapperMethods, serialize} from "../../src/index"; @JsonMapper(Date) export class DateMapper implements JsonMapperMethods { - deserialize(data: string | number, ctx: JsonMapperContext): Date; - deserialize(data: boolean | null | undefined, ctx: JsonMapperContext): boolean | null | undefined; - deserialize(data: any, ctx: JsonMapperContext): any { + deserialize(data: string | number, ctx: JsonMapperCtx): Date; + deserialize(data: boolean | null | undefined, ctx: JsonMapperCtx): boolean | null | undefined; + deserialize(data: any, ctx: JsonMapperCtx): any { // don't convert unexpected data. In normal case, Ajv reject unexpected data. // But by default, we have to skip data deserialization and let user to apply // the right mapping @@ -17,7 +17,7 @@ export class DateMapper implements JsonMapperMethods { return new Date(data); } - serialize(object: Date, ctx: JsonMapperContext): any { + serialize(object: Date, ctx: JsonMapperCtx): any { const date = new Date(object); switch (ctx.options.format) {