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

JsonMember's reviver and replacer #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afshin-hoseini
Copy link

First of all thank you for this awesome library.

I have added following feature and would be glad if you accept:

  1. Implemented reviver and replacer functions for JsonMemberOptions:

Sometimes it's needed to let a member to revive or replace its own value on serialization and/or deserialization process. As like as currency or metric values which should convert their value.

Definition

/** Will be invoked, with the deserialized value in order to let the member, revive it. */
reviver? : (deserializedValue : any)=>any
/** Will be invoked, with the serialized value in order to let the member, replace it. */
replacer? : (serializedValue : any)=>any

Usage

@JsonMember({
      type : Number, 
      reviver : value=> value + 5, 
      replacer : value=> value * 10 
})
level : number

 - Implemented reviver and replacer functions for JsonMemberOptions
@Jimmy-Hernandez
Copy link

OMG this would be awesome

@Neos3452
Copy link
Collaborator

Neos3452 commented Mar 5, 2019

You can use serializer and deserializer options in the latest version. Or, is it maybe something different?

@afshin-hoseini
Copy link
Author

@Neos3452
Actually it is an old PR, when serializer and deserializer weren't available. 🙂

@Jimmy-Hernandez 🥺You're the only one who told me something like this in my whole life... I'll appreciate it 😀

@Neos3452
Copy link
Collaborator

Neos3452 commented Mar 6, 2019

@afshin-hoseini I know, but if it is different and serves a purpose to someone I would consider rebasing your change. :)

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

Successfully merging this pull request may close these issues.

3 participants