Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

.toJson(as_string: true) for nested entities #18

Open
hkan opened this issue Jan 9, 2022 · 0 comments
Open

.toJson(as_string: true) for nested entities #18

hkan opened this issue Jan 9, 2022 · 0 comments

Comments

@hkan
Copy link
Contributor

hkan commented Jan 9, 2022

class A extends Entity {
    public foo: string = null;
}

class B extends Entity {
    @Type(A)
    children: A[] = null;
}

const instance = EntityBuilder.buildOne<B>(B, {
    children: [
        { foo: 'bar' },
    ],
});

console.log(instance.toJson(true, true));

The code above yields this result:

{
    "children": [
        "{\"foo\": \"bar\"}"
    ]
}

... while the expected result should be:

{
    "children": [
        {
            "foo": "bar"
        }
    ]
}

... because nested entities get converted to string before being assigned to the result object which in the end gets stringified as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant