(TypeScript) Json-Object-Mapper
This a simple package to mapping a json object.
Getting Started
Install
npm install typescript-json-object-mapper
yarn add typescript-json-object-mapper
Configure
To work with decorators, you need first enable emitDecoratorMetadata
y experimentalDecorators
on you tsconfig.json
.
Example:
Create you own Views
This example tries to show all possible cases in which you might need to use this utility.
Define you data object
;
Serilize(without topic's)
;
results:
Serilize(with topic)
;
results:
Serilize(with topic)
;
results:
Features
- No-Initiation(Using only reference to class)
- Renaming properties
- Change data types
- to Date
- from String using
Date.parse
- from Integer using
Date
- from String using
- to Integer
- from String using
Number
- from String using
- to Float
- from String using
Number
- from String using
- to Boolean
- to String
- to Object
- to Date
- Sub-Views(Recursivity)
- Array sub-views
- Single sub-view
- Date values(String, Number, Date)
- Serialize from
Object Array
- Serialize from
Object
- Serialize from
String
- Property Topic's
- Smart
Object
,Constructor
,Function
,Date
,ObjectId
toString
- Using
toString
method when it exists- If
toString
return[object object]
, JsonObjectMapper will try iterate object to create a plain object with defualts values.
- If
- Using
API:
JsonObjectMapper.serialize
This function always return Serialization
object.
And can using it with data as Array
or Object
.
Example
// from ArrayJsonObjectMapper.serialize, UserView; // from ObjectJsonObjectMapper.serialize, UserView;
Serialization
spaces:number = 4
): string
Serialization.toString(This method return a string representation of object.
Serialization.toJson()
This method return a json object representation.