TS SerVal (TypeScript Serialization and Validation) is a TypeScript library for runtime serialization and validation of JSON objects to/from JavaScript classes. It is using TypeScript decorators (e.g. @serialize()) to mark classes and properties for serialization and validation. It heavily uses reflection and TypeScript decorators.
The documentation for this package is currently under construction.
If you require to set any JSON content to a Serializable property, you can use JSONWrapper or JSONWrapperAsync. They enable the (de-)serialization with serialize(), toJSON(), from() or deserialize() in a generic way.
The wrappers store all content into a generic value property as JSON. This property is transparent, meaning that value won't appear in the serialized output. However, accessing the value is required while using the wrappers programmatically.
The wrappers are automatically used if ts-serval encounters a property of type Serializable (=> JSONWrapper) or SerializableAsync (=> JSONWrapperAsync).
If you would like to allow any type (be it any object, boolean, string, number), set {any:true} within the @serialize() descriptor. This will disable most of the parsing and (de-)serialization logic.
@validate()
@serialize({any:true})
public content:anyIf you would also like to allow null values, use {nullable:true} within the @validate() descriptor.
@validate({nullable:true})
@serialize({any:true})
public content:anyCurrently contribution to this project is not possible. This will change soon.