{"id":14155556,"url":"https://github.com/paddls/ts-serializer","last_synced_at":"2025-06-26T01:03:13.628Z","repository":{"id":38198775,"uuid":"266527141","full_name":"paddls/ts-serializer","owner":"paddls","description":"Serialize your models into strongly typed Typescript classes","archived":false,"fork":false,"pushed_at":"2024-08-02T07:47:56.000Z","size":453,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T03:03:48.517Z","etag":null,"topics":["json","serialization","serializer","strongly-typed","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@paddls/ts-serializer","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paddls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-24T11:31:23.000Z","updated_at":"2024-08-02T07:47:08.000Z","dependencies_parsed_at":"2024-05-31T15:42:41.301Z","dependency_job_id":"4b7bb51c-32c1-4a26-ba21-e55f4ef1332c","html_url":"https://github.com/paddls/ts-serializer","commit_stats":{"total_commits":80,"total_committers":6,"mean_commits":"13.333333333333334","dds":"0.32499999999999996","last_synced_commit":"d4482c73e54e34ddcff3de8012a52ef0b1e77321"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/paddls/ts-serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fts-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fts-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fts-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fts-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paddls","download_url":"https://codeload.github.com/paddls/ts-serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fts-serializer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260275176,"owners_count":22984650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","serialization","serializer","strongly-typed","typescript"],"created_at":"2024-08-17T08:03:55.825Z","updated_at":"2025-06-26T01:03:13.599Z","avatar_url":"https://github.com/paddls.png","language":"TypeScript","readme":"# TS-Serializer\n\n![ts-serializer-ci](https://github.com/paddls/ts-serializer/workflows/build/badge.svg?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/paddls/ts-serializer/badge.svg?branch=master)](https://coveralls.io/github/paddls/ts-serializer?branch=master)\n[![npm version](https://badge.fury.io/js/%40paddls%2Fts-serializer.svg)](https://badge.fury.io/js/%40paddls%2Fts-serializer)\n![GitHub](https://img.shields.io/github/license/paddls/ts-serializer)\n![GitHub repo size](https://img.shields.io/github/repo-size/paddls/ts-serializer)\n![GitHub last commit](https://img.shields.io/github/last-commit/paddls/ts-serializer)\n![GitHub issues](https://img.shields.io/github/issues/paddls/ts-serializer)\n![GitHub top language](https://img.shields.io/github/languages/top/paddls/ts-serializer)\n\nSerialize and deserialize JSON into strongly typed typescript objects using decorators.\n\n## Informations\n\n\u003e :warning: Since version 1.0.10, ```ts-serializer``` has been published under ```@paddls``` namespace. We continue to maintain ```@witty-services``` namespace.\n\n## Summary\n\n* [How to install](#how-to-install)\n* [How to use](#how-to-use)\n    * [Configure your models](#configure-your-models)\n    * [Serialization](#serialization)\n    * [Deserialization](#deserialization)\n    * [Serialization configuration](#serializer-configuration)\n* [API](#api)\n  * [JsonPropertyDecorator](#jsonproperty)\n  * [JsonPropertyContext](#jsonpropertycontext)\n    * [JsonTypeSupports](#jsontypesupports)\n    * [NormalizerConfiguration](#normalizerconfiguration)\n    * [CustomConverter](#customconverter)\n* [How to run Unit Tests](#how-to-run-unit-tests)\n\n## How to install\n\nTo install the library, run :\n\n```\nnpm i @paddls/ts-serializer\n```\nor\n```\nnpm i @witty-services/ts-serializer\n```\n\n## How to use\n\n### Configure your models\n\n````typescript\nexport class User {\n\n  @JsonProperty({readOnly: true})\n  public id: string;\n\n  @JsonProperty()\n  public firstName: string\n\n  @JsonProperty('lastname')\n  public lastName: string;\n\n  @JsonProperty(Address)\n  public address: Address;\n\n  @JsonProperty(() =\u003e [Car, Truck])\n  public vehicles: Vehicle[];\n\n  @JsonProperty({groups: ['WithAge', 'OtherGroup']})\n  public age: number;\n\n  @JsonProperty({groups: 'WithSize'})\n  public size: number;\n}\n\nabstract class Vehicle {\n\n  @JsonProperty()\n  public name: string;\n}\n\n@JsonTypeSupports((data: { type: 'CAR' | 'TRUCK' }) =\u003e data.type === 'CAR')\nclass Car extends Vehicle {\n\n  @JsonProperty()\n  public seatingCapacity: number;\n}\n\n@JsonTypeSupports((data: { type: 'CAR' | 'TRUCK' }) =\u003e data.type === 'TRUCK')\nclass Truck extends Vehicle {\n\n  @JsonProperty()\n  public payloadCapacity: number;\n}\n````\n\nYou can find the full ``@JsonProperty()`` decorator configuration in [API](#API) section.\n\n### Serialization\n\n```typescript\nconst object: MyClass = new MyClass();\n\nconst serializer: Serializer = new Serialize(new Normalizer(), new Denormalizer());\nconst data: any = serializer.serialize(object);\n```\n\n### Deserialization\n\n```typescript\nclass MyClass {\n  // ...\n}\n\nconst data: any = {};\n\n\nconst serializer: Serializer = new Serializer(new Normalizer(), new Denormalizer());\nconst myObject: MyClass = serializer.deserialize(MyClass, data);\n```\n\n### Serializer configuration\n\nYou can configure serializer using ``NormalizerConfiguration`` class :\n\n````typescript\nconst configuration: NormalizerConfiguration = {\n  denormalizeNull: false,\n  denormalizeUndefined: false,\n  normalizeNull: false,\n  normalizeUndefined: false\n};\n````\n\n### Groups\n\nYou can use groups to restrict the serialization/deserialization process. Without any options provided to serializer,\ngroups configuration aren't used. But if you want to use groups defined in JsonProperty decorator, you can use them like\nthis :\n\n```typescript\nclass MyClass {\n\n  @JsonProperty()\n  public attribute1: string;\n\n  @JsonProperty({groups: 'Group1'})\n  public attribute2: string;\n\n  @JsonProperty({groups: ['Group1', 'Group2']})\n  public attribute3: string;\n\n  @JsonProperty({groups: 'Group3'})\n  public attribute4: string;\n}\n\nconst data: any = {\n  //...\n};\n\n\nconst serializer: Serializer = new Serializer(new Normalizer(), new Denormalizer());\nconst myObject: MyClass = serializer.deserialize(MyClass, data, {groups: ['Group1', 'Group2']});\n\n// here, myObject has only attribute2 and attribute3 valued\n```\n\n## API\n\n### JsonProperty\n\n| Argument            | Type                                                                  | Required   | Description                                                                                                                                                                                                                                                                                                                                                                                                     |\n|----------           | ------                                                                | ---------- | ------------                                                                                                                                                                                                                                                                                                                                                                                                    |\n| jsonPropertyContext | [JsonPropertyContext](#jsonpropertycontext) \u0026#124; string \u0026#124; Type | No         | If no argument is provided, the attribute will be mapped with a field in json object with the same name.\u003cbr/\u003e If the argument is a string, the attribute will be mapped with a field in json object named with the provided string.\u003cbr/\u003e If the argument is a type, the attribute will be mapped with a field in json object with the same name, but the type provided will be used to make the transformation. |\n\n### JsonPropertyContext\n\n| Attribute       | Type                   | Required   | Description                                                                                                                         |\n|-----------      | ------                 | ---------- | ------------                                                                                                                        |\n| field           | string                 | No         | You can change the name of mapped field. The attribute accept a path ``` 'path.to.myField' ```                                      |\n| type            | Function\u003cType\u003e         | No         | You can provide a type to convert json data to an object of Type or convert an object of Type to json data using Type configuration |\n| readOnly        | boolean                | No         | You can want to use the attribute configuration only in the deserialization process                                                 |\n| writeOnly       | boolean                | No         | You can want to use the attribute configuration only in the serialization process                                                   |\n| customConverter | Converter              | No         | You can add a custom converter object of type [Converter](#customconverter) to convert your object                                        |\n| groups          | string \u0026#124; string[] | No         | You can restrict serialization/deserialization process with groups                                                                  |\n\n### JsonTypeSupports\n\n| Argument  | Type              | Required   | Description                                                                                                     |\n|---------- | ------            | ---------- | ------------                                                                                                    |\n| context   | Function\u003cboolean\u003e | Yes        | This argument sets up the function to call when the serializer searches a type which matches with received data |\n\n### NormalizerConfiguration\n\n| Attribute            | Type    | Required   | Default value   | Description                                                    |\n|-----------           | ------  | ---------- | --------------- | ------------                                                   |\n| denormalizerNull     | boolean | No         | false           | Denormalizer configuration to not denormalize null values      |\n| denormalizeUndefined | boolean | No         | false           | Denormalizer configuration to not denormalize undefined values |\n| normalizeNull        | boolean | No         | false           | Normalizer configuration to not normalize null values          |\n| normalizeUndefined   | boolean | No         | false           | Normalizer configuration to not normalize undefined values     |\n\n### CustomConverter\n\n``CustomConverter`` is an interface to make some converter. TS-Serializer provides a ``DateConverter`` to convert a date\nto an ISOString and an ISOString to a date.\n\n### SerializerOptions\n\n``SerializerOptions`` is an interface which represents optional options to provide to serialization/deserialization\nprocess.\n\n| Attribute  | Type                   | Required   | Default value   | Description                                            |\n|----------- | ------                 | ---------- | --------------- | ------------                                           |\n| groups     | string \u0026#124; string[] | No         | undefined       | Groups to use in serialization/deserialization process |\n\n## How to run Unit Tests\n\nTo run unit tests and generate coverage, run :\n\n```\nnpm run test\n```\n","funding_links":[],"categories":["typescript","Underlying Technologies"],"sub_categories":["TypeScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddls%2Fts-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaddls%2Fts-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddls%2Fts-serializer/lists"}