Skip to content

Support for "pure object references" #178

Description

@emilianodenis

Hi,

A nice to have would be a support for pure JSON references.

I mean objects that are simply { $ref: 1 }.

An example:

@jsonObject
export class A {
  constructor() {}

  @jsonMember
  public name: string;

  @jsonMember
  public id: number;
}

@jsonObject
export class B {
  constructor() {}

  @jsonMember
  public prop1: A;

  @jsonMember
  public prop2: A;
}

    const obj: any = {
      $id: 1,
      prop1: {
        $id: 2,
        name: "test1",
        id: 100
      },
      prop2: {
        $id: 3,
        name: "test2",
        id: 101
      }
    };

    const objRef: any = {
      $id: 4,
      prop1: {
        $id: 5,
        name: "test1",
        id: 100
      },
      prop2: { $ref: 5 }
    };

    const res1 = TypedJSON.parse(obj, B);
    const res2 = TypedJSON.parse(objRef, B);

In this case, res1 is properly serialized. But for res2, prop1 is fine while prop2 is an empty object.

Stackblitz with a more complete example: https://stackblitz.com/edit/angular-ivy-yoqexv

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions