JohnWeisz/TypedJSON

Support for implicit type conversion

s888 opened this issue · 3 comments

s888 commented

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 commented

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

s888 commented

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?

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.