String date to Object Date
basvandenheuvel opened this issue · 1 comments
basvandenheuvel commented
Hi,
From my backend i retrieve a date as a string, i would like to make it a Date object in my frontend. The following 2 options do NOT work:
@JsonProperty('date')
Date: Date;
@JsonProperty({clazz: Date, name: 'date'})
Date: Date;
Any ideas or is this not possible?
kobiburnley commented
You should use a "customConverter" :
const dateConverter: ICustomConverter = {
fromJson(data: any): any {
return new Date(data);
},
toJson(data: any): any {
return 'some-date';
}
};
@JsonProperty({name: 'dob', customConverter: dateConverter})
dateOfBirth: Date = undefined;