import { defaultTypeResolver } from './deserializer'; import { CustomDeserializerParams, CustomSerializerParams, TypeHintEmitter, TypeResolver } from './metadata'; import { OptionsBase } from './options-base'; import { defaultTypeEmitter } from './serializer'; import { Constructor, IndexedObject, Serializable } from './types'; export declare type JsonTypes = Object | boolean | string | number | null | undefined; export { defaultTypeResolver, defaultTypeEmitter }; export interface MappedTypeConverters { /** * Use this deserializer to convert a JSON value to the type. */ deserializer?: ((json: any, params: CustomDeserializerParams) => T | null | undefined) | null; /** * Use this serializer to convert a type back to JSON. */ serializer?: ((value: T | null | undefined, params: CustomSerializerParams) => any) | null; } export interface ITypedJSONSettings extends OptionsBase { /** * Sets the handler callback to invoke on errors during serializing and deserializing. * Re-throwing errors in this function will halt serialization/deserialization. * The default behavior is to log errors to the console. */ errorHandler?: ((e: Error) => void) | null; /** * Maps a type to their respective (de)serializer. Prevents you from having to repeat * (de)serializers. Register additional types with `TypedJSON.mapType`. */ mappedTypes?: Map, MappedTypeConverters> | null; /** * Sets a callback that determines the constructor of the correct sub-type of polymorphic * objects while deserializing. * The default behavior is to read the type-name from the '__type' property of 'sourceObject', * and look it up in 'knownTypes'. * The constructor of the sub-type should be returned. */ typeResolver?: TypeResolver | null; nameResolver?: ((ctor: Function) => string) | null; /** * Sets a callback that writes type-hints to serialized objects. * The default behavior is to write the type-name to the '__type' property, if a derived type * is present in place of a base type. */ typeHintEmitter?: TypeHintEmitter | null; /** * Sets the amount of indentation to use in produced JSON strings. * Default value is 0, or no indentation. */ indent?: number | null; replacer?: ((key: string, value: any) => any) | null; knownTypes?: Array> | null; } export declare class TypedJSON { private static _globalConfig; private serializer; private deserializer; private globalKnownTypes; private indent; private rootConstructor; private errorHandler; private nameResolver; private replacer?; /** * Creates a new TypedJSON instance to serialize (stringify) and deserialize (parse) object * instances of the specified root class type. * @param rootConstructor The constructor of the root class type. * @param settings Additional configuration settings. */ constructor(rootConstructor: Serializable, settings?: ITypedJSONSettings); static parse(object: any, rootType: Serializable, settings?: ITypedJSONSettings): T | undefined; static parseAsArray(object: any, elementType: Serializable, settings?: ITypedJSONSettings, dimensions?: 1): Array; static parseAsArray(object: any, elementType: Serializable, settings: ITypedJSONSettings | undefined, dimensions: 2): Array>; static parseAsArray(object: any, elementType: Serializable, settings: ITypedJSONSettings | undefined, dimensions: 3): Array>>; static parseAsArray(object: any, elementType: Serializable, settings: ITypedJSONSettings | undefined, dimensions: 4): Array>>>; static parseAsArray(object: any, elementType: Serializable, settings: ITypedJSONSettings | undefined, dimensions: 5): Array>>>>; static parseAsSet(object: any, elementType: Serializable, settings?: ITypedJSONSettings): Set; static parseAsMap(object: any, keyType: Serializable, valueType: Serializable, settings?: ITypedJSONSettings): Map; static toPlainJson(object: T, rootType: Serializable, settings?: ITypedJSONSettings): JsonTypes; static toPlainArray(object: Array, elementType: Serializable, dimensions?: 1, settings?: ITypedJSONSettings): Array; static toPlainArray(object: Array>, elementType: Serializable, dimensions: 2, settings?: ITypedJSONSettings): Array>; static toPlainArray(object: Array>>, elementType: Serializable, dimensions: 3, settings?: ITypedJSONSettings): Array>>; static toPlainArray(object: Array>>>, elementType: Serializable, dimensions: 4, settings?: ITypedJSONSettings): Array>>>; static toPlainArray(object: Array>>>>, elementType: Serializable, dimensions: 5, settings?: ITypedJSONSettings): Array>>>>; static toPlainArray(object: Array, elementType: Serializable, dimensions: number, settings?: ITypedJSONSettings): Array; static toPlainSet(object: Set, elementType: Serializable, settings?: ITypedJSONSettings): Array | undefined; static toPlainMap(object: Map, keyCtor: Serializable, valueCtor: Serializable, settings?: ITypedJSONSettings): IndexedObject | Array<{ key: any; value: any; }> | undefined; static stringify(object: T, rootType: Serializable, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array, elementType: Serializable, dimensions?: 1, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array>, elementType: Serializable, dimensions: 2, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array>>, elementType: Serializable, dimensions: 3, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array>>>, elementType: Serializable, dimensions: 4, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array>>>>, elementType: Serializable, dimensions: 5, settings?: ITypedJSONSettings): string; static stringifyAsArray(object: Array, elementType: Serializable, dimensions: number, settings?: ITypedJSONSettings): string; static stringifyAsSet(object: Set, elementType: Serializable, settings?: ITypedJSONSettings): string; static stringifyAsMap(object: Map, keyCtor: Serializable, valueCtor: Serializable, settings?: ITypedJSONSettings): string; static setGlobalConfig(config: ITypedJSONSettings): void; /** * Map a type to its (de)serializer. */ static mapType(type: Serializable, converters: MappedTypeConverters): void; /** * Configures TypedJSON through a settings object. * @param settings The configuration settings object. */ config(settings?: ITypedJSONSettings): void; mapType(type: Serializable, converters: MappedTypeConverters): void; /** * Converts a JSON string to the root class type. * @param object The JSON to parse and convert. * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown). * @returns Deserialized T or undefined if there were errors. */ parse(object: any): T | undefined; parseAsArray(object: any, dimensions?: 1): Array; parseAsArray(object: any, dimensions: 2): Array>; parseAsArray(object: any, dimensions: 3): Array>>; parseAsArray(object: any, dimensions: 4): Array>>>; parseAsArray(object: any, dimensions: 5): Array>>>>; parseAsArray(object: any, dimensions: number): Array; parseAsSet(object: any): Set; parseAsMap(object: any, keyConstructor: Serializable): Map; /** * Converts an instance of the specified class type to a plain JSON object. * @param object The instance to convert to a JSON string. * @returns Serialized object or undefined if an error has occured. */ toPlainJson(object: T): JsonTypes; toPlainArray(object: Array, dimensions?: 1): Array; toPlainArray(object: Array>, dimensions: 2): Array>; toPlainArray(object: Array>>, dimensions: 3): Array>>; toPlainArray(object: Array>>>, dimensions: 4): Array>>>; toPlainArray(object: Array>>>>, dimensions: 5): Array>>>>; toPlainSet(object: Set): Array | undefined; toPlainMap(object: Map, keyConstructor: Serializable): IndexedObject | Array<{ key: any; value: any; }> | undefined; /** * Converts an instance of the specified class type to a JSON string. * @param object The instance to convert to a JSON string. * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown). * @returns String with the serialized object or an empty string if an error has occured, but * the errorHandler did not throw. */ stringify(object: T): string; stringifyAsArray(object: Array, dimensions?: 1): string; stringifyAsArray(object: Array>, dimensions: 2): string; stringifyAsArray(object: Array>>, dimensions: 3): string; stringifyAsArray(object: Array>>>, dimensions: 4): string; stringifyAsArray(object: Array>>>>, dimensions: 5): string; stringifyAsSet(object: Set): string; stringifyAsMap(object: Map, keyConstructor: Serializable): string; private getKnownTypes; private _mapKnownTypes; private setSerializationStrategies; } //# sourceMappingURL=parser.d.ts.map