(De)serialize complex object graphs to/from JSON
- SKIP :
symbol
- DATE_ONLY :
ModelSchema.<Date, string>
- DATE :
ModelSchema.<Date, string>
- PRIMITIVE :
ModelSchema.<TYPE, TYPE>
- alias(property, schema) ⇒
PropertySchema.<OBJECT, JSON>
- array(schema) ⇒
ModelSchema.<Array.<OBJECT>, Array.<JSON>>
- computed(compute) ⇒
PropertySchema.<OBJECT, JSON>
- object(schema) ⇒
ObjectModelSchema.<OBJECT>
- omitBy(predicate, schema) ⇒
ObjectModelSchema.<OBJECT>
Omit values after serialization.
While
skipBy
is useful to skip single values from an object, there are situations where you want to skip all properties if they are a certain value. In this case, it's easier to use thisomitBy
schema on theobject
schema.- omitNull(schema) ⇒
ObjectModelSchema.<OBJECT>
Omit
null
values after serialization.- optional(schema) ⇒
PropertySchema.<OBJECT, JSON>
- skipBy(predicate, schema) ⇒
PropertySchema.<OBJECT, JSON>
Skip the value after serialization if predicate returns true, in case the BE doesn't want to receive certain values.
Some REST API's rather have the key not being there than having a certain value they see as a nil value, like
null
,""
or{}
. In that case, this skip schema can be used with a predicate function to check.- skipNull(schema) ⇒
PropertySchema.<OBJECT, JSON>
Skip
null
value after serialization.Also checks undefined values, to avoid conflicts with required properties. The required check is done as last and turns values into
null
if needed.- withDefault(defaultValue, schema) ⇒
ModelSchema.<OBJECT, JSON>
|PropertySchema.<OBJECT, JSON>
Use a default value after deserialization, in cae the value turns up undefined.
- withJsonDefault(defaultValue, schema) ⇒
ModelSchema.<OBJECT, JSON>
|PropertySchema.<OBJECT, JSON>
Use a default json value before deserialization, in case the original value is undefined.
This can be very handy in case a sub-object is undefined, but you want the object to always be there, having it's properties initialized. For example, a patient object which has a person property to hold all it's name parts. In that case, you always want the person object to be there and have the name parts set to null instead, so you can use it in a form to fill out.
- ComputeObjectModel ⇒
OBJECT
- ObjectModelSchema :
ModelSchema.<OBJECT, Object>
- ObjectSchema :
Object.<string, PropertySchema>
- PropertySchema :
Object
- PropertyTransformer ⇒
TARGET
- ModelSchema :
Object
- ModelTransformer ⇒
TARGET
Kind: global constant
Template: TYPE
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
property | string |
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
schema | ModelSchema.<OBJECT, JSON> |
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
compute | ComputeObjectModel.<OBJECT, JSON> |
Kind: global function
Template: OBJECT
Param | Type |
---|---|
schema | ObjectSchema |
Omit values after serialization.
While skipBy
is useful to skip single values from an object, there are
situations where you want to skip all properties if they are a certain value.
In this case, it's easier to use this omitBy
schema on the object
schema.
Kind: global function
Template: OBJECT
See: skipBy
Param | Type |
---|---|
predicate | function |
schema | ObjectModelSchema.<OBJECT> |
Omit null
values after serialization.
Kind: global function
Template: OBJECT
See: omitBy
Param | Type |
---|---|
schema | ObjectModelSchema.<OBJECT> |
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Skip the value after serialization if predicate returns true, in case the BE doesn't want to receive certain values.
Some REST API's rather have the key not being there than having a certain
value they see as a nil value, like null
, ""
or {}
. In that case, this
skip schema can be used with a predicate function to check.
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
predicate | function |
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Skip null
value after serialization.
Also checks undefined values, to avoid conflicts with required properties.
The required check is done as last and turns values into null
if needed.
Kind: global function
Template: OBJECT, JSON
See: skipBy
Param | Type |
---|---|
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Use a default value after deserialization, in cae the value turns up undefined.
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
defaultValue | OBJECT |
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Use a default json value before deserialization, in case the original value is undefined.
This can be very handy in case a sub-object is undefined, but you want the object to always be there, having it's properties initialized. For example, a patient object which has a person property to hold all it's name parts. In that case, you always want the person object to be there and have the name parts set to null instead, so you can use it in a form to fill out.
Kind: global function
Template: OBJECT, JSON
Param | Type |
---|---|
defaultValue | JSON |
schema | ModelSchema.<OBJECT, JSON> | PropertySchema.<OBJECT, JSON> |
Kind: global typedef
Template: OBJECT, JSON
Param | Type | Description |
---|---|---|
json | Object |
|
property | string |
|
{JSON) | value |
Kind: global typedef
Template: OBJECT
Kind: global typedef
Template: OBJECT, JSON
Properties
Name | Type |
---|---|
[property] | string |
serialize | PropertyTransformer.<OBJECT, JSON> |
deserialize | PropertyTransformer.<JSON, OBJECT> |
Kind: global typedef
Template: SOURCE, TARGET
Param | Type |
---|---|
value | SOURCE |
source | Object |
property | string |
Kind: global typedef
Template: OBJECT, JSON
Properties
Name | Type |
---|---|
serialize | ModelTransformer.<OBJECT, JSON> |
deserialize | ModelTransformer.<JSON, OBJECT> |
Kind: global typedef
Template: SOURCE, TARGET
Param | Type |
---|---|
value | SOURCE |