{"id":18963783,"url":"https://github.com/opensoft/simple-serializer","last_synced_at":"2025-04-19T12:36:45.487Z","repository":{"id":4390033,"uuid":"5527013","full_name":"opensoft/simple-serializer","owner":"opensoft","description":"Simple serializer","archived":false,"fork":false,"pushed_at":"2020-09-03T18:06:14.000Z","size":451,"stargazers_count":19,"open_issues_count":2,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T20:09:23.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/opensoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2012-08-23T13:46:51.000Z","updated_at":"2025-01-30T11:37:17.000Z","dependencies_parsed_at":"2022-08-24T05:40:54.399Z","dependency_job_id":null,"html_url":"https://github.com/opensoft/simple-serializer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensoft%2Fsimple-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensoft%2Fsimple-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensoft%2Fsimple-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensoft%2Fsimple-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opensoft","download_url":"https://codeload.github.com/opensoft/simple-serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249201117,"owners_count":21229004,"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":[],"created_at":"2024-11-08T14:21:40.057Z","updated_at":"2025-04-16T05:31:25.863Z","avatar_url":"https://github.com/opensoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Simple-Serializer\n================\n\n\n[![Build Status](https://secure.travis-ci.org/opensoft/simple-serializer.png?branch=master)](http://travis-ci.org/opensoft/simple-serializer)\n[![Total Downloads](https://poser.pugx.org/opensoft/simple-serializer/downloads.png)](https://packagist.org/packages/opensoft/simple-serializer)\n[![Latest Stable Version](https://poser.pugx.org/opensoft/simple-serializer/v/stable.png)](https://packagist.org/packages/opensoft/simple-serializer)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/opensoft/simple-serializer/badges/quality-score.png?s=ce7bb8be75525d519d466114856681b0dbd95848)](https://scrutinizer-ci.com/g/opensoft/simple-serializer/)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/950193f2-a3a7-4117-a267-e4b1c95fe5b3/mini.png)](https://insight.sensiolabs.com/projects/950193f2-a3a7-4117-a267-e4b1c95fe5b3)\n\nIntroduction\n------------\n\nSimple-Serializer allows you to serialize your objects into a requested output format such as JSON.\nThe library is written to work with DTO objects in the REST services.\n\nBuilt-in features include:\n\n- (de-)serialize object graphs\n- supports boolean, integer, double, DateTime\\\u003cformat\\\u003e, array, T, array\\\u003cT\\\u003e, null types, where \"T\" - is some PHP object.\n- configurable via YAML\n- three unserialize mode (non-strict, medium strict, strict)\n\nUnserialize mode:\nNon-Strict mode - serializer does not check incoming parameters\nMedium Strict - serializer extra check incoming parameters and if they exist throw InvalidArgumentException\nStrict - serializer extra check incoming parameters completely as expected if there are extra arguments or missing some, it throws an exception.\n\n\nSome Restrictions:\n\n- object must have configuration for serialize/unserialize\n\nPossible TODO list:\n\n- (de-)serialize object graphs of any complexity including circular references\n- configurable via PHP, XML, or annotations\n- custom integrates with Doctrine ORM, et. al.\n\nIt should be noted that Simple-Serializer is realy simple library with minimum configuration,\nbut it provides wide opportunity for create REST API.\n\n[![Build Status](https://secure.travis-ci.org/opensoft/simple-serializer.png?branch=master)](http://travis-ci.org/opensoft/simple-serializer)\n\n\nInstallation\n------------\n\nTo install Simple-Serializer with Composer just add the following to your `composer.json` file:\n\n```javascript\n    // composer.json\n    {\n        // ...\n        require: {\n            // ...\n            \"opensoft/simple-serializer\": \"dev-master\"\n        }\n    }\n```\n\nThen, you can install the new dependencies by running Composer's ``update``\ncommand from the directory where your ``composer.json`` file is located:\n\n    $ php composer.phar update\n\nConfiguration\n-------------\n\n```yml\nMyBundle\\Resources\\config\\serializer\\ClassName.yml\n    Fully\\Qualified\\ClassName:\n        properties:\n            some-property:\n                expose: true\n                type: string\n                serialized_name: foo\n                since_version: 1.0\n                until_version: 2.0\n                groups: ['get','patch']\n```\n\n* expose\n * true\n * false (default)\n* type\n * integer\n * boolean\n * double\n * string\n * array\n * T - fully qualified class name\n * array\\\u003cT\\\u003e\n * DateTime\n * DateTime\\\u003cformat\\\u003e\n  * format could be name of DateTime constant (COOKIE, ISO8601), string or empty (default format is ISO8601)\n* serialized_name\n * default value is equal name property\n* since_version\n * string\n* until_version\n * string\n* groups\n * array\n* null_skipped\n * true\n * false (default)\n\nSerializing Objects\n-------------------\nMost common usage is probably to serialize objects. This can be achieved\nvery easily:\n\n```php\n    \u003c?php\n    //get Serializer\n    $serializer = $this-\u003egetSerializer();\n    $string = $serializer-\u003eserialize($object);\n    //Serialize array of the objects\n    $string = $serializer-\u003eserialize(array($object));\n    //Serialize specific groups\n    $serializer-\u003esetGroups(array('get'));\n    $string = $serializer-\u003eserialize($object);\n    //Serialize specific version\n    $serializer-\u003esetVersion('1.0');\n    $string = $serializer-\u003eserialize($object);\n```\n\nDeserializing Objects\n---------------------\nYou can also unserialize objects from JSON representation. For\nexample, when accepting data via an API.\n\n```php\n    \u003c?php\n    //get Fully\\Qualified\\ClassName\n    $object = $this-\u003egetClassName();\n    //get Serializer\n    $serializer = $this-\u003egetSerializer();\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n    //Unserialize array of the objects\n    $objects = $serializer-\u003eunserialize($jsonData, array($object));\n    //Unserialize specific groups\n    $serializer-\u003esetGroups(array('get'));\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n    //Unserialize specific version\n    $serializer-\u003esetVersion('1.0');\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n    //Strict unserialize mode\n    $serializer-\u003esetStrictUnserializeMode(2);\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n    //Medium Strict unserialize mode\n    $serializer-\u003esetStrictUnserializeMode(1);\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n    //Non-Strict unserialize mode\n    $serializer-\u003esetStrictUnserializeMode(0);\n    $object = $serializer-\u003eunserialize($jsonData, $object);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensoft%2Fsimple-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensoft%2Fsimple-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensoft%2Fsimple-serializer/lists"}