0.4.2 • Published 7 months ago
class-json v0.4.2
Comprehensive JSON library for a class.
with TypeScript support
Decorators 1.1 Converting
* `@Json.type(Ctor: Function, options?)` * `@Json.array(Ctor: Function, options?)` * `@Json.name(jsonName: string)` * `@Json.ignore()` * `@Json.converter(converter: IJsonConverter)`
1.2 Validation
* `@Rule.required(message?)` * `@Rule.minLength(count: number, message?)` * `@Rule.maxLength(count: number, message?)` * `@Rule.minimum(val: number, message?)` * `@Rule.maximum(val: number, message?)` * `@Rule.pattern(rgx: RegExp, message?)` * `@Rule.validate(validator: IValueValidator)` Message Type: * string * string templates: `Interpolations: ~[value] ~[property] ~[model.foo]` * Custom Function: `(value, model) => string`
import { Json, Rule } from 'class-json'
class Transaction {
@Json.type(BigInt)
@Rule.minimum(100n)
value: bigint
@Json.type(Date)
@Ruke.required()
executeAt: Date
}
Classes
Serializable<T>
interface Serializable<T> {
constructor (partial: Partial<T>)
/** Create an instance from json, all Types from decorators will be restored. */
static fromJSON (json): T
/** Use Rules from decorators to validate the instance */
static validate (instance: T): IRuleError[]
/** Serialize instance to JSON object. All Types from decorators will be properly converted to JSON supported types */
toJSON(): object
}
Constructor: accepts partial object, example:
// instead of:
let foo = new Foo();
foo.lorem = 'lorem';
foo.ipsum = 'ipsum';
// more convinient way would be:
let foo = new Foo({
lorem: 'lorem',
ipsum: 'ipsum'
});
Namespaces
JsonConvert
toJSON(model, settings)
fromJSON<T>(model, settings): T
© 2021 Atmajs
0.4.2
7 months ago
0.4.1
11 months ago
0.3.8
2 years ago
0.3.7
4 years ago
0.3.6
4 years ago
0.3.5
4 years ago
0.3.4
4 years ago
0.3.3
5 years ago
0.3.2
5 years ago
0.2.99
5 years ago
0.2.98
5 years ago
0.2.97
5 years ago
0.3.0
5 years ago
0.3.1
5 years ago
0.2.95
5 years ago
0.2.94
5 years ago
0.2.93
5 years ago
0.2.92
5 years ago
0.2.90
5 years ago
0.2.89
5 years ago
0.2.88
5 years ago
0.2.85
5 years ago
0.2.87
5 years ago
0.2.84
5 years ago
0.2.83
5 years ago
0.2.82
5 years ago
0.2.81
5 years ago
0.2.80
5 years ago
0.2.79
5 years ago
0.2.78
5 years ago
0.2.76
5 years ago
0.2.75
5 years ago
0.2.74
5 years ago
0.2.73
5 years ago
0.2.72
5 years ago
0.2.71
5 years ago
0.2.69
5 years ago
0.2.68
5 years ago
0.2.67
5 years ago
0.2.66
5 years ago
0.2.65
6 years ago
0.2.63
6 years ago
0.2.64
6 years ago
0.2.61
6 years ago
0.2.60
6 years ago
0.2.59
6 years ago
0.2.58
6 years ago
0.2.55
6 years ago