Property default values
Closed this issue · 2 comments
zoechi commented
Thanks a lot for this library!
Is there a way to provide default values for properties?
@jsonObject
export class Foo {
@jsonMember
bar:string = 'bar';
}
does not work for me.
If the value is not provided in the JSON the property is undefined
.
MatthiasKunnen commented
This seems to be working fine for me with TypedJSON 1.5.2.
@jsonObject
class Foo {
@jsonMember
bar: string = 'bar';
}
TypedJSON.parse({}, Foo); // Foo { bar: 'bar' }
TypedJSON.parse({bar: undefined}, Foo); // Foo { bar: 'bar' }
TypedJSON.parse({bar: null}, Foo); // Foo { bar: 'bar' }
zoechi commented
Thanks for looking into it! I'll check again and reopen if I can provide a simple reproduction.