{"id":19240463,"url":"https://github.com/lookyman/json-mapper","last_synced_at":"2025-04-21T08:32:26.342Z","repository":{"id":62518975,"uuid":"442730553","full_name":"lookyman/json-mapper","owner":"lookyman","description":"Strict JSON to object hydrator based on PHPStan.","archived":true,"fork":false,"pushed_at":"2022-01-03T10:14:15.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T14:30:36.208Z","etag":null,"topics":["json","mapper","phpstan"],"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/lookyman.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}},"created_at":"2021-12-29T09:59:26.000Z","updated_at":"2024-05-04T16:00:52.000Z","dependencies_parsed_at":"2022-11-02T14:45:59.907Z","dependency_job_id":null,"html_url":"https://github.com/lookyman/json-mapper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookyman%2Fjson-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookyman%2Fjson-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookyman%2Fjson-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookyman%2Fjson-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lookyman","download_url":"https://codeload.github.com/lookyman/json-mapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250023577,"owners_count":21362428,"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","mapper","phpstan"],"created_at":"2024-11-09T17:07:35.964Z","updated_at":"2025-04-21T08:32:26.074Z","avatar_url":"https://github.com/lookyman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Mapper\n\nStrict JSON to object hydrator based on [PHPStan](https://phpstan.org/).\n\n## Usage\n\n```php\nuse Lookyman\\JsonMapper\\MapperBuilder\nuse PHPUnit\\Framework\\Assert;\n\nclass Foo\n{\n    public function __construct(public string $foo)\n    {\n    }\n}\n\nclass Bar\n{\n    public function __construct(public Foo $first)\n    {\n    }\n}\n\n$result = (new MapperBuilder())\n    -\u003ebuild()\n    -\u003emap(Bar::class, '{\"first\":{\"foo\":\"wtf\"}}');\n\nAssert::assertEquals(\n    new Bar(new Foo('wtf')),\n    $result,\n);\n```\n\nIf the parameter is not present in source, and has a scalar default value, it will be assigned that value.\nIf the parameter is not present in source, but is nullable, it will be assigned a `NULL` value.\nIf the source contains keys not present in parameter names, those will be ignored.\nOtherwise, we do not do any guessing or type casting.\n\nIn case of any error, `Lookyman\\JsonMapper\\Exception\\MapperException` is thrown.\n\n## Supported types\n\n* Scalars (including literals and integer ranges),\n* arrays (including associative and shapes),\n* iterables,\n* `class-string` (including generic),\n* `object`,\n* normal class objects (including generic),\n* unions (including nullable parameters),\n* backed enums.\n\nSee [PHPStan documentation](https://phpstan.org/writing-php-code/phpdoc-types) and `tests` directory for examples.\n\n## Caveats\n\nAll classes must be instantiable with a public constructor.\nIf your types contain interfaces or abstract classes, use `MapperBuilder::withClassMapping` to provide a map to concrete classes.\n\n## Questions?\n\nThis is a pet project I played with over the 2021 end of year holidays, because I saw [@Ocramius](https://twitter.com/Ocramius) looking for a similar library a few weeks earlier.\nAt the moment, I have no ambitions with it, I just wanted to see if this approach is feasible.\n\nIt probably contains a lot of bugs.\n\nIf you have any questions, the answer is probably \"I don't know\".\nIf you have any requests, I will probably not respond.\n\nBut I reserve the right to change my mind at any point.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookyman%2Fjson-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flookyman%2Fjson-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookyman%2Fjson-mapper/lists"}