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

Introduce multiple context feature to @Json #124

Closed
etsuo opened this issue Jan 28, 2018 · 0 comments
Closed

Introduce multiple context feature to @Json #124

etsuo opened this issue Jan 28, 2018 · 0 comments
Milestone

Comments

@etsuo
Copy link
Member

etsuo commented Jan 28, 2018

Models may have multiple sources and they may need to be marshalled to multiple destinations, of which each may have different field names for the same property.

@Model()
export class SomeClass extends SapiModelMixin() {

    @Db('fn')
    @Json('fName')
    @Json({field: 'first_name', context: 'sisense'})
    @Json('f', 'source2')
    firstName: string;
}

const someClass1 = SomeClass.fromJson({'firstName': 'John'}); // depending on #121
const someClass2 = SomeClass.fromJson({'fName': 'John'});
const someClass3 = SomeClass.fromJson({'first_name': 'John'}, 'sisense');
const someClass4 = SomeClass.fromJson({'f': 'John'}, 'source2');

someClass1.toJson();
// { "fName": "John" }

someClass2.toJson('sisense');
// { "first_name" : "John" }

someClass3.toJson('source2');
// { "f" : "John" }

@etsuo etsuo added the proposal label Jan 28, 2018
@etsuo etsuo added this to the 0.9.0 milestone Jan 28, 2018
@etsuo etsuo changed the title Introduce multiple context feature to @Json Introduce multiple context feature to @Json Jan 28, 2018
@etsuo etsuo removed the proposal label Jan 30, 2018
@etsuo etsuo closed this as completed in 2fcd586 Jan 30, 2018
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

1 participant