deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

Custom converter and validators for a type

Open leandro-manifesto opened this issue 5 years ago • 1 comments

This is like a continuation from my question in https://github.com/super-hornet/super-hornet.ts/issues/12#issuecomment-663155896.

Looking at the source code I figured out a way to to add custom converter compilers to specifics types:

https://gist.github.com/leandro-manifesto/cac78114030756383462b6c7b641aaf2#file-register-ts

It works by overring the default plain -> class and class -> plain converter compilers and the default class checker compiler, but I get the feeling that it can break at any moment if internals change.

Would be nice if a feature like this was provided by Marshal itself.

leandro-manifesto avatar Aug 07 '20 23:08 leandro-manifesto

I see, yes indeed the internals might change and we could add instead a simpler API for adding checkers/serializers for simple class types.

marcj avatar Aug 09 '20 17:08 marcj

Here is an example that shows how a custom class type can be de/serialised: https://github.com/deepkit/deepkit-framework/blob/master/packages/type/tests/serializer-api.spec.ts#L48-L64

I'll close this issue since I don't see anything we can do.

marcj avatar Dec 03 '22 14:12 marcj