Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String date to Object Date #27

Open
basvandenheuvel opened this issue Jun 7, 2017 · 1 comment
Open

String date to Object Date #27

basvandenheuvel opened this issue Jun 7, 2017 · 1 comment

Comments

@basvandenheuvel
Copy link

basvandenheuvel commented Jun 7, 2017

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
Copy link

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;

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

No branches or pull requests

2 participants