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

Support for implicit type conversion #121

Open
s888 opened this issue Feb 1, 2020 · 3 comments
Open

Support for implicit type conversion #121

s888 opened this issue Feb 1, 2020 · 3 comments

Comments

@s888
Copy link

s888 commented Feb 1, 2020

I am evaluating to choose between https://www.npmjs.com/package/class-transformer and Typedjson. But since class-transformer is barely maintained so I am trying out TypedJson. But one major thing that is lacking for me is implicit type conversion. https://github.com/typestack/class-transformer#implicit-type-conversion
Is there a way I could implement this?
Thanks in advance.

@marcj
Copy link

marcj commented Feb 3, 2020

Give Marshal.ts a try, it covers what you need, is maintained and is the fastest serializer.

@s888
Copy link
Author

s888 commented Feb 3, 2020

Give Marshal.ts a try, it covers what you need, is maintained and is the fastest serializer.

Is there any parameter to enable/disable Soft type castings?

@Neos3452
Copy link
Collaborator

Neos3452 commented Feb 3, 2020

Hey @s888, if you are still interested, with TypedJSON you could use a custom serialiser to achieve what you need. For example, something like this below if you always want a string. Take care, because with custom serialisers and deserialiser you also need to handle null, and undefined if they are expected in the input.

@jsonObject
class Foo {
    @jsonMember({ deserializer: ((value: any) => '' + value) })
    alwaysString: string;
}

@marcj, you should learn some manners and not intrude like this and advertise your own project. We are all giving to the community and if you think the project could be improved I invite you to contribute and help this long running library.

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

3 participants