Options
All
  • Public
  • Public/Protected
  • All
Menu

This is the main class. Tyson is typically used by first constructing a Tyson instance and then invoking toJson or fromJson methods on it.

Here is an example:

const tyson = new Tyson(); // or builder
const target = new MyType();
const json = tyson.toJson(target); // serializes target to JSON
const target2 = tyson.fromJson(json, MyType); // deserializes JSON into target2
export
class

Tyson

Hierarchy

  • Tyson

Index

Constructors

constructor

Properties

Private _factories

_factories: Array<TypeAdapterFactory>

Private _serializeNulls

_serializeNulls: boolean = Constants.DEFAULT_SERIALIZE_NULLS

Private _typeTokenCache

_typeTokenCache: Map<string, TypeAdapter<any>>

Accessors

serializeNulls

serializeNulls:

Methods

fromJson

  • fromJson<T>(json: any[], type: any[]): any[]
  • fromJson<T>(json: any[], type: ClassType<T>): T[]
  • fromJson<T>(json: object, type: ClassType<T>): T
  • This method deserializes the specified JSON into an object|array of the specified type.

    template

    T the type of the desired object|array

    memberof

    Tyson

    Type parameters

    • T

    Parameters

    • json: any[]

      the JSON object|array used during deserialization

    • type: any[]

      a class|array of T

    Returns any[]

    an object|array of type T. Returns undefined if json or type are undefined.

  • Type parameters

    • T

    Parameters

    Returns T[]

  • Type parameters

    • T

    Parameters

    Returns T

getAdapter

  • Returns the type adapter for the specified typeToken. This method uses a cache to avoid re-creating a new adapter for a previously requested TypeToken.

    template

    T

    throws

    Will throw an error if Tyson cannot deserialize / serialize typeToken

    memberof

    Tyson

    Type parameters

    • T

    Parameters

    Returns TypeAdapter<T>

    a TypeAdapter of T

toJson

  • toJson(src: any[], type: ClassType<any> | any[]): any[]
  • toJson(src: object, type?: ClassType<any>): any
  • This method serializes the specified object, into its equivalent JSON representation.

    memberof

    Tyson

    Parameters

    • src: any[]

      the object|array for which JSON representation is to be created

    • type: ClassType<any> | any[]

      the specific type of src (required for arrays)

    Returns any[]

    JSON representation of src

  • Parameters

    Returns any

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc