Skip to content

Commit

Permalink
fix(json-mapper): add missing options declaration in JsonMapperCtx in…
Browse files Browse the repository at this point in the history
…terface
  • Loading branch information
Romakita committed Mar 27, 2024
1 parent 46a3fec commit 045665d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/docs/json-mapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::

Expand Down Expand Up @@ -318,7 +318,7 @@ and import the mapper in your application.
</Tab>
</Tabs>

::: warn
::: warning

Ts.ED doesn't transform Date to date format or hours format because it depends on each project guidelines.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export interface JsonMapperCtx<T = any, C = any> {
collectionType: Type<C> | undefined;
type: Type<T> | T;
next: JsonMapperNext;
options: {
format?: string;
};
}

export interface JsonMapperNext {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 045665d

Please sign in to comment.