Function JsonComplexProperty

  • Decorator for complex-type properties to be (de)serialized correctly. Use this if the property is of a non-array type that needs recursive (de)serialization.

    Uses only the name property of the params.

    Usage examples:

    import { JsonClass, JsonMapper, JsonProperty, JsonComplexProperty } from '@mdcc/at-json';

    @JsonClass()
    class SubClass
    {
    @JsonProperty()
    foo: string;
    }

    @JsonClass()
    class MyClass
    {
    @JsonComplexProperty(SubClass)
    sub1: SubClass;

    @JsonComplexProperty(SubClass, 'extSub2')
    sub2: SubClass;
    }

    const backendObject = {
    sub1: { foo: 'bar' },
    extSub2: { foo: 'baz' }
    };
    const mapper = new JsonMapper();
    const deserialized = mapper.deserialize<MyClass>(MyClass, backendObject);

    // sub1 keeps the same name
    assert.isInstanceOf(deserialized.sub1, SubClass);
    assert.equal(deserialized.sub1.foo, 'bar');

    // extSub2 became sub2
    assert.isInstanceOf(deserialized.sub2, SubClass);
    assert.equal(deserialized.sub2.foo, 'baz');

    const backendObjectSerialized = mapper.serialize(deserialized);
    // reverse conversion was performed
    assert.deepEqual(backendObjectSerialized, backendObject);

    Type Parameters

    • T

    Parameters

    Returns PropertyDecorator

    the decorator for the property.

    Export

Generated using TypeDoc