I have an Angular WebApp who retrives data from a backend Java server via http get. Example:
public getStateForUser(): Observable<UserRegistrationState> {
return this.http.get<any>(Environment.getServerAddress() + '/' +
UserRegistrationStateService.SERVICE_URL + '/getStateForUser', {
params: {
sessionIdentityStr: this.authGuard.getSession().sessionIdentityStr
}
});
}
export class UserRegistrationState {
registerDate: Date;
emailVerified: boolean;
unlocked: boolean;
}
This works fine for all fields. Except the Dates. The Dates are not parsed correctly, so I want to add a custom parser where I can tell him how he gets the date value from the json date string.
Of course now I can add a custom Parser for the whole UserRegistrationState class, but I have Dates on multiple classes and I do not want to create a Parser for every class, because the other properties(except the Dates) are parsed fine.
So my question: Is there a way to add a custom parser for all Date fields?
P.S. This is an example JSON date string, automatically parsed from a Java LocalDateTime:
"registerDate":{"dayOfMonth":17,"dayOfWeek":"WEDNESDAY","dayOfYear":290,"month":"OCTOBER","monthValue":10,"year":2018,"hour":21,"minute":21,"nano":370000000,"second":16,"chronology":{"id":"ISO","calendarType":"iso8601"}}