{"id":23219102,"url":"https://github.com/b2pweb/bdf-serializer","last_synced_at":"2025-10-03T14:59:35.095Z","repository":{"id":36159728,"uuid":"221949940","full_name":"b2pweb/bdf-serializer","owner":"b2pweb","description":"A basic but powerful PHP serializer","archived":false,"fork":false,"pushed_at":"2025-07-01T08:04:45.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-23T19:39:23.018Z","etag":null,"topics":[],"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/b2pweb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-11-15T15:21:29.000Z","updated_at":"2025-07-01T07:47:43.000Z","dependencies_parsed_at":"2023-11-10T14:40:18.764Z","dependency_job_id":"ec4cd9a3-df30-43d9-87ee-670f1bd2d277","html_url":"https://github.com/b2pweb/bdf-serializer","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":"0.32432432432432434","last_synced_commit":"24d2d70ab1d7e1bd618ca72b04254f5b04a1988d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/b2pweb/bdf-serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b2pweb","download_url":"https://codeload.github.com/b2pweb/bdf-serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fbdf-serializer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277171030,"owners_count":25773130,"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-09-27T02:00:08.978Z","response_time":73,"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":[],"created_at":"2024-12-18T21:19:17.903Z","updated_at":"2025-10-03T14:59:35.038Z","avatar_url":"https://github.com/b2pweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Serializer\n\nThe Bdf Serializer can normalize, hydrate / extract and encode data or object.\nIt use doctrine/instantiator for instancing class and phpdocumentor for reading annotations.\n\n[![build](https://github.com/b2pweb/bdf-serializer/actions/workflows/php.yml/badge.svg)](https://github.com/b2pweb/bdf-serializer/actions/workflows/php.yml)\n[![codecov](https://codecov.io/github/b2pweb/bdf-serializer/branch/master/graph/badge.svg?token=VOFSPEWYKX)](https://codecov.io/github/b2pweb/bdf-serializer)\n[![Packagist Version](https://img.shields.io/packagist/v/b2pweb/bdf-serializer.svg)](https://packagist.org/packages/b2pweb/bdf-serializer)\n[![Total Downloads](https://img.shields.io/packagist/dt/b2pweb/bdf-serializer.svg)](https://packagist.org/packages/b2pweb/bdf-serializer)\n[![Type Coverage](https://shepherd.dev/github/b2pweb/bdf-serializer/coverage.svg)](https://shepherd.dev/github/b2pweb/bdf-serializer)\n\n### Installation with Composer\n\n```bash\ncomposer require b2p/bdf-serializer\n```\n\n### Basic usage\n\n```PHP\n\u003c?php\n\nuse Bdf\\Serializer\\SerializerBuilder;\n\n$serializer = SerializerBuilder::create()-\u003ebuild();\n$json = $serializer-\u003etoJson($object);\n//...\n```\n\n### Declare metadata\n\n2 drivers are available. The static method called and the annotations driver.\n\n#### Static method driver\n\nDeclare your static method to build metadata\n\n\n```PHP\n\u003c?php\n\nuse Bdf\\Serializer\\Metadata\\Builder\\ClassMetadataBuilder;\nuse DateTime;\n\nclass User\n{\n    /**\n     * @var integer\n     */\n    private $id;\n    \n    /**\n     * @var string\n     */\n    private $name;\n    \n    /**\n     * @var DateTime\n     */\n    private $date;\n    \n    /**\n     * @param ClassMetadataBuilder $builder\n     */\n    public static function loadSerializerMetadata($builder)\n    {\n        $builder-\u003einteger('id');\n        $builder-\u003estring('name');\n        \n        // You can also add group, alias, ...\n        $builder-\u003estring('name')\n            -\u003eaddGroup('all')\n            -\u003ealias('user_name')\n            -\u003esince('1.0.0');\n            \n        // DateTime options are available\n        $builder-\u003edateTime('date')\n            -\u003edateFormat('Y/m/d H:i')\n            -\u003etimezone('+01:00')      // Use this timezone in internal\n            -\u003etoTimezone('+00:00');   // Export date with this timezone\n    }\n}\n```\n\n#### Annotations driver\n\nThe annotations driver use phpdocumentor/reflection-docblock. The tag `@var` will be read.\nIf no tag is found, the default type is `string`.\n\nSupported tags\n* `var`: This annotation specify the type of the property. This tag is mandatory for deserialization.\n* `since`: Enable object versionning. The value specify starting from which version this property is available.\n* `until`: Enable object versionning. The value specify until which version this property was available.\n* `SerializeIgnore`: Don't serialize this property.\n\nNOTE: If type has not been detected in the phpdoc we try to add the typed property value added in PHP 7.4\n\n\n#### JMS/serializer driver\n\nThe driver `Bdf\\Serializer\\Metadata\\Driver\\JMSAnnotationDriver` allows you to use JMS drivers. \nThe JMS metadata will be used to create Bdf metadata. Only few options of the serializer is used:\n* `serializedName`\n* `readOnly`\n* `inline`\n* `sinceVersion`\n* `untilVersion`\n* `getter`\n* `setter`\n* `groups`\n* `type`\n\nNOTE: The driver works with jms/serializer \u003e v3.0 and php \u003e v7.2\n\n```PHP\n\u003c?php\n\nuse Bdf\\Serializer\\Metadata\\Driver\\JMSAnnotationDriver;\nuse JMS\\Serializer\\Metadata\\Driver\\AnnotationDriver as BaseJMSAnnotationDriver;\n\n$driver = new JMSAnnotationDriver(new BaseJMSAnnotationDriver(...));\n```\n\n\n#### Serialization options\n\nThe `NormalizationContext` contains options for normalization.\n* `exclude`: Properties to exclude from normalization .\n* `include`: Properties to include from normalization.\n* `groups`: Groups of properties to include.\n* `null`: Null value will be added if true.\n* `meta_type`: Include the metadata \"@type\" in the payload.\n* `version`: Set the version for object that support versionning serialization.The string version should be compatible with PHP function `version_compare`.\n* `circular_reference_limit`: Number of circular reference. Default 1.\n* `remove_default_value`: Don't inject the value of a property if it is set to its default value.\n\nDate time options\n\n* `dateFormat`: Normalization option to specify the format.\n* `dateTimezone`: Use the given timezone to format date.\n* `timezoneHint`: Denormalization option to help to detect the timezone from input string.\n\nAvailable option for `NormalizationContext` and `DenormalizationContext`.\n\n* `throws_on_accessor_error`: By default a value is skipped if an `Error` is thrown when writting or reading on a property. This option will throw error from accessor (debug purpose).\n\nExemple:\n```PHP\n\u003c?php\n\nuse \\Bdf\\Serializer\\Context\\NormalizationContext;\n\n$object = (object)[\n    \"name\" =\u003e \"John\",\n    \"age\"  =\u003e null,\n];\n\n$builder = new \\Bdf\\Serializer\\SerializerBuilder();\n$builder-\u003esetNormalizers([new \\Bdf\\Serializer\\Normalizer\\ObjectNormalizer()]);\n\n$serializer = $builder-\u003ebuild();\necho $serializer-\u003etoJson($object);\n// {\"name\":\"John\"}\n\necho $serializer-\u003etoJson($object, [NormalizationContext::NULL =\u003e true]);\n// {\"name\":\"John\",\"age\":null}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fbdf-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb2pweb%2Fbdf-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fbdf-serializer/lists"}