{"id":14984091,"url":"https://github.com/goodwix/doctrine-json-odm","last_synced_at":"2025-07-10T08:36:39.882Z","repository":{"id":34034728,"uuid":"166171254","full_name":"goodwix/doctrine-json-odm","owner":"goodwix","description":"JSON Object-Document Mapping bundle for Symfony and Doctrine","archived":false,"fork":false,"pushed_at":"2022-11-30T04:54:33.000Z","size":87,"stargazers_count":22,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T17:21:27.317Z","etag":null,"topics":["database","doctrine","json","odm","orm","postgresql","symfony","symfony-bundle","symfony4"],"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/goodwix.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":"2019-01-17T06:17:13.000Z","updated_at":"2025-03-22T13:29:55.000Z","dependencies_parsed_at":"2023-01-15T04:06:21.696Z","dependency_job_id":null,"html_url":"https://github.com/goodwix/doctrine-json-odm","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodwix%2Fdoctrine-json-odm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodwix%2Fdoctrine-json-odm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodwix%2Fdoctrine-json-odm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodwix%2Fdoctrine-json-odm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goodwix","download_url":"https://codeload.github.com/goodwix/doctrine-json-odm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281424,"owners_count":21077423,"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":["database","doctrine","json","odm","orm","postgresql","symfony","symfony-bundle","symfony4"],"created_at":"2024-09-24T14:08:25.854Z","updated_at":"2025-04-10T19:43:34.195Z","avatar_url":"https://github.com/goodwix.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctrine JSON ODM library\n\n[![Latest Stable Version](https://poser.pugx.org/goodwix/doctrine-json-odm/v/stable)](https://packagist.org/packages/goodwix/doctrine-json-odm)\n[![Total Downloads](https://poser.pugx.org/goodwix/doctrine-json-odm/downloads)](https://packagist.org/packages/goodwix/doctrine-json-odm)\n[![License](https://poser.pugx.org/goodwix/doctrine-json-odm/license)](https://packagist.org/packages/goodwix/doctrine-json-odm)\n[![Build Status](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/badges/build.png?b=master)](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/build-status/master)\n[![Code Coverage](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/goodwix/doctrine-json-odm/?branch=master)\n\nInspired by \u003chttps://github.com/dunglas/doctrine-json-odm\u003e\n\nThis is beta version of library. Main differences from Dunglas library:\n\n* library does not store any metadata in json field;\n* doctrine ODM type uses main Symfony serializer service (so you can easily extend serialization process by adding normalizers/denormalizers globally in dependency injection config);\n* automatic registration of ODM types for Doctrine (using Symfony autowiring and autoconfigure features).\n\n## Features\n\n* Object-Document Mapping with database json types\n* Doctrine 2.5+ support\n* PostgreSQL 9.4+ support\n* Symfony 5+ support (not tested with previous versions)\n* MySQL support not tested\n\n## Additional features\n\n* Automatic registering normalizers for use with Java-like collections from [ramsey/collection](https://github.com/ramsey/collection) library\n\n## Install\n\n### Install with Symfony 4\n\nTo install the library, use [Composer](https://getcomposer.org/).\n\n```bash\ncomposer require goodwix/doctrine-json-odm\n```\n\nAdd lines to `config/bundles.php` (no automatic configuration is available for beta version).\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    Goodwix\\DoctrineJsonOdm\\Bridge\\Symfony\\DoctrineJsonOdmBundle::class =\u003e ['all' =\u003e true],\n];\n\n```\n\nCreate package config file `config/packages/doctrine-json-odm.yaml` with next content.\n\n```yaml\ndoctrine_json_odm:\n  mapping:\n    paths:\n      - '%kernel.project_dir%/src/ODM'\n```\n\nthere `src/ODM` is the root path for your ODM entities (like `src/Entity` for Doctrine).\n\n## Usage\n\n### Basic usage with automatic ODM types registration\n\nCreate entity class for ODM type in ODM-specific directory (like `src/ODM`) and mark it with `\\Goodwix\\DoctrineJsonOdm\\Annotation\\ODM` annotation.\n\n```php\nnamespace App\\ODM;\n\nuse Goodwix\\DoctrineJsonOdm\\Annotation\\ODM;\n\n/**\n * @ODM()\n */\nclass Document\n{\n    /** @var string */\n    public $title;\n\n    /** @var string */\n    public $description;\n}\n```\n\nCreate doctrine entity class with field type `App\\ODM\\Document`.\n\n```php\nnamespace App\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse App\\ODM\\Document;\n\n/**\n * @ORM\\Entity()\n */\nclass DocumentStorage\n{\n    /**\n     * @ORM\\Column(type=\"integer\")\n     * @ORM\\Id\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\n     *\n     * @var int\n     */\n    public $id;\n\n    /**\n     * @ORM\\Column(type=Document::class, nullable=true)\n     *\n     * @var Document\n     */\n    public $document;\n}\n```\n\nNow you can easily manage your ORM entity with ODM class field\n\n```php\n$documentStorage = $entityManager-\u003efind(DocumentStorage::class, $id);\n$documentStorage-\u003edocument-\u003etitle = 'ODM document title';\n$documentStorage-\u003edocument-\u003edescription = 'ODM document description';\n```\n\n### Manual usage with Doctrine and Symfony Serializer component\n\nTo manually register Doctrine ODM types use [`ODMType::registerODMType()`](https://github.com/goodwix/doctrine-json-odm/blob/36860ddaddc10e9ea33b2986b17009db979a0026/src/Type/ODMType.php#L100) method.\n\n```php\nrequire_once __DIR__.'/../vendor/autoload.php';\n\nuse Goodwix\\DoctrineJsonOdm\\Type\\ODMType;\nuse Symfony\\Component\\Serializer\\SerializerInterface;\n\nclass Document { }\n\nODMType::registerODMType(\n    Document::class,\n    new class implements SerializerInterface\n    {\n        public function serialize($data, $format, array $context = [])  { /* Implement serialize() method. */ }\n        public function deserialize($data, $type, $format, array $context = [])  { /* Implement deserialize() method. */ }\n    }\n);\n```\n\n### Examples with Symfony application\n\nYou can see example of Symfony 4 application with using ODM library in this [directory](https://github.com/goodwix/doctrine-json-odm/tree/master/tests/Resources/Symfony).\n\n## Deal with abstract\n\nAs an `abstract` class could not be created as an instance, each concrete children have to be mapped into the abstract class.\n\nIndeed, the `Symfony Serializer` must know the real type in this case through a discriminator field to determine the real object behind\nthe stored data. For that, it use `Symfony\\Component\\Serializer\\Annotation\\DiscriminatorMap`. More info is available [here](\nMaybe this way : [Symfony serializer : discriminator](https://symfony.com/doc/current/components/serializer.html#serializing-)\n\nFor example, if we have an abstract and 2 children\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Whatever;\n\nuse Symfony\\Component\\Serializer\\Annotation\\DiscriminatorMap;\n\n#### PHP8 Attribute ####\n#[DiscriminatorMap(\n    typeProperty: 'type',\n    mapping: [\n        'myChildTypeName' =\u003e 'App\\Whatever\\Child',\n        'myChild2TypeName' =\u003e 'App\\Whatever\\Child2',\n    ]\n)]\n####\u003e PHP8 Attribute ####\n\n\n#### PHP \u003c PHP8 ####\n/**\n * @DiscriminatorMap(typeProperty=\"type\", mapping={\n *    \"myChildTypeName\"=\"App\\Whatever\\Child\",\n *    \"myChild2TypeName\"=\"App\\Whatever\\Child2\"\n * })\n */\n####\u003e PHP \u003c PHP8 ####\n\n\nabstract class MyAbstract\n{\n}\n\nclass Child extends MyAbstract\n{}\n\n\nclass Child2 extends MyAbstract\n{}\n```\n\n\n## Contribution\n\nYou can run `composer lint` before pushing to repository to ensure that there are no code style errors.\n\nPlease remember to add some tests if you change library code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodwix%2Fdoctrine-json-odm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodwix%2Fdoctrine-json-odm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodwix%2Fdoctrine-json-odm/lists"}