Skip to content

TemporalMapper

@tsed/json-mapper

Usage

typescript
import { TemporalMapper } from "@tsed/json-mapper";

See /packages/specs/json-mapper/src/components/TemporalMapper.ts.

Overview

ts
class TemporalMapper implements JsonMapperMethods {
    deserialize(data: string | number, ctx: JsonMapperCtx): unknown;
    deserialize(data: boolean | null | undefined, ctx: JsonMapperCtx): boolean | null | undefined;
    serialize(object: {
        toString(): string;
    } | null | undefined): any;
}

Description

Mapper for the Temporal.* types (Instant, ZonedDateTime, PlainDate, PlainDateTime, PlainTime, PlainYearMonth, PlainMonthDay, Duration).

Every Temporal type exposes a static from(string) factory and an ISO-8601 toString(), so a single mapper handles all of them: serialize() calls toString(), and deserialize() rebuilds the concrete type read from ctx.type (the deserializer sets it to the registered constructor).

Registration is guarded by a runtime Temporal check so importing @tsed/json-mapper stays safe on runtimes that don't expose the global Temporal object.

deserialize

ts
deserialize(data: string | number, ctx: JsonMapperCtx): unknown;

deserialize

ts
deserialize(data: boolean | null | undefined, ctx: JsonMapperCtx): boolean | null | undefined;

serialize

ts
serialize(object: {
     toString(): string;
 } | null | undefined): any;

Released under the MIT License.