{"id":17323905,"url":"https://github.com/sanmai/json-serializer","last_synced_at":"2025-07-29T09:39:28.216Z","repository":{"id":46279819,"uuid":"299518641","full_name":"sanmai/json-serializer","owner":"sanmai","description":"Flexible JSON Serializer","archived":false,"fork":false,"pushed_at":"2025-06-24T12:16:56.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-30T06:42:50.438Z","etag":null,"topics":["json","php","serializer"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/sanmai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-09-29T05:58:43.000Z","updated_at":"2025-06-24T12:17:00.000Z","dependencies_parsed_at":"2024-02-17T11:48:38.147Z","dependency_job_id":null,"html_url":"https://github.com/sanmai/json-serializer","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"56e1c64db8b1f651c9da149445a0667376e7bfd7"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/sanmai/json-serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fjson-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fjson-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fjson-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fjson-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanmai","download_url":"https://codeload.github.com/sanmai/json-serializer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fjson-serializer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267665026,"owners_count":24124443,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","php","serializer"],"created_at":"2024-10-15T14:09:29.442Z","updated_at":"2025-07-29T09:39:28.209Z","avatar_url":"https://github.com/sanmai.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flexible JSON Serializer\n\n[![Latest Stable Version](https://poser.pugx.org/sanmai/json-serializer/v/stable)](https://packagist.org/packages/sanmai/json-serializer)\n[![Coverage Status](https://coveralls.io/repos/github/sanmai/json-serializer/badge.svg?branch=master)](https://coveralls.io/github/sanmai/json-serializer?branch=master)\n\nThis library is a thin wrapper around [jms/serializer](https://github.com/schmittjoh/serializer). \n\n```\ncomposer require sanmai/json-serializer\n```\n\nThe purpose of this library is to make simpler deserialization/serialization of objects and, specifically, of arrays of objects, and scalar values. All you need is to follow a simple protocol.\n\n### ItemList\n\nJMS Serializer supports deserializing arrays out of the box, but it is ever so slightly complicated since a user must specify a type in a full form, as in `array\u003cT\u003e`, all the while returned deserialized value will be a plain array. This library abstracts away this extra complexity by providing a two-method protocol instead.\n\nFor example, deserialising this object:\n\n```php\nuse JSONSerializer\\Contracts\\ItemList;\n\nclass ItemListExample implements ItemList\n{\n    /** @var ItemExample[] */\n    public $items = [];\n\n    public static function getListType(): string\n    {\n        return ItemExample::class;\n    }\n\n    public static function withList(array $list)\n    {\n        $itemList = new self();\n        $itemList-\u003eitems = $list;\n\n        return $itemList;\n    }\n}\n```\n\nFrom a JSON array:\n```json\n[\n    {\"name\": \"foo\"},\n    {\"name\": \"bar\"}\n]\n```\n\nWith an all-familiar method:\n\n```php\nuse JSONSerializer\\Serializer;\n\n$serializer = new Serializer();\n\n$result = $serializer-\u003edeserialize($json, ItemListExample::class);\n```\n\nWill leave an instance of `ItemListExample` in `$result` with `$result-\u003eitems` filled with two items as in the source array.\n\n### ScalarValue\n\nThere's a similar convenience interface called `ScalarValue` to aid with unserializing wrapped primitive scalar values.\n\n```php\nuse JSONSerializer\\Contracts\\ScalarValue;\n\nclass ScalarValueExample implements ScalarValue\n{\n    /** @var int */\n    public $value;\n\n    public static function withValue($value)\n    {\n        $item = new self();\n        $item-\u003evalue = $value;\n\n        return $item;\n    }\n\n    public static function getType(): string\n    {\n        return 'int';\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmai%2Fjson-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanmai%2Fjson-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmai%2Fjson-serializer/lists"}