entity
entity copied to clipboard
`.toJson(as_string: true)` for nested entities
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.