How to use the typedjson.TypedJSON function in typedjson

To help you get started, we’ve selected a few typedjson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opf / openproject / frontend / src / app / modules / bim / bcf / api / topics / bcf-topic.resource.spec.ts View on Github external
it('can parse from the API returned JSON', () => {
    const serializer = new TypedJSON(BcfTopicResource);
    const subject = serializer.parse(topic_object)!;

    expect(subject).toBeInstanceOf(BcfTopicResource);
    ['guid', 'topic_type', 'topic_status', 'priority', 'reference_links', 'title',
      'index', 'labels', 'creation_author', 'modified_author', 'assigned_to', 'stage',
      'description'].forEach((item) => expect((subject as any)[item]).toEqual((topic_object as any)[item]));

    // Expect dates
    expect(subject.creation_date).toEqual(moment(topic_object.creation_date));
    expect(subject.modified_date).toEqual(moment(topic_object.modified_date));
    expect(subject.due_date.format('YYYY-MM-DD')).toEqual(topic_object.due_date);

    expect(serializer.toPlainJson(subject)).toEqual(topic_object);
  });
});
github opf / openproject / frontend / src / app / modules / bim / bcf / api / bcf-api-request.service.ts View on Github external
protected deserialize(data:any):T {
    if (this.resourceClass) {
      const serializer = new TypedJSON(this.resourceClass);
      return serializer.parse(data)!;
    } else {
      return data;
    }
  }
}

typedjson

Typed JSON parsing and serializing for TypeScript that preserves type information, using decorators. Parse JSON into actual class instances.

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Similar packages