Skip to main content
Version: 5.9

SerializationContext <T>

Helper that allows to keep track of where we are currently at when serializing complex entity graph with cycles. Before we process a property, we call visit that checks if it is not a cycle path (but allows to pass cycles that are defined in populate hint). If not, we proceed and call leave afterwards.

Index

Constructors

constructor

  • new SerializationContext<T>(populate?: PopulateOptions<T>[]): SerializationContext<T>
  • Type parameters

    • T

    Parameters

    • populate: PopulateOptions<T>[] = []

    Returns SerializationContext<T>

Properties

readonlypath

path: [string, string][] = []

readonlyvisited

visited: Set<Partial<any>> = ...

Methods

close

  • close(): void
  • Returns void

leave

  • leave<U>(entityName: string, prop: string): void
  • Type parameters

    • U

    Parameters

    • entityName: string
    • prop: string

    Returns void

visit

  • visit(entityName: string, prop: string): boolean
  • Parameters

    • entityName: string
    • prop: string

    Returns boolean

staticpropagate

  • propagate(root: SerializationContext<Partial<any>>, entity: Partial<any>, isVisible: (meta: EntityMetadata<any>, prop: string) => boolean): void
  • When initializing new context, we need to propagate it to the whole entity graph recursively.


    Parameters

    • root: SerializationContext<Partial<any>>
    • entity: Partial<any>
    • isVisible: (meta: EntityMetadata<any>, prop: string) => boolean

      Returns void