{"id":15782544,"url":"https://github.com/mtarld/encoder-examples","last_synced_at":"2025-03-31T16:44:59.596Z","repository":{"id":211886169,"uuid":"730169462","full_name":"mtarld/encoder-examples","owner":"mtarld","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-12T02:00:47.000Z","size":47,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-05T19:08:14.207Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtarld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-12-11T10:56:27.000Z","updated_at":"2024-05-05T23:32:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"9733eb21-f453-4f32-80b1-b8ded4bedd61","html_url":"https://github.com/mtarld/encoder-examples","commit_stats":null,"previous_names":["mtarld/encoder-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtarld%2Fencoder-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtarld%2Fencoder-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtarld%2Fencoder-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtarld%2Fencoder-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtarld","download_url":"https://codeload.github.com/mtarld/encoder-examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246500082,"owners_count":20787633,"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-10-04T19:08:18.403Z","updated_at":"2025-03-31T16:44:59.571Z","avatar_url":"https://github.com/mtarld.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonEncoder examples\n\nA demo project showing the main differences between the usage of the\nSerializer component and the JsonEncoder component.\n\nRelevant examples can be found in: `src/Command`.\n\n## Sum up of differences\n\nWhile the Serializer component is focused on flexibility, and covers a huge\namount of use cases, the JsonEncoder component is more focused on efficiency.\n\nIndeed, by design, the Serializer serializes data using two steps:\nnormalization/denormalization and encoding/decoding. This implies\nthat the whole normalized/decoded data is at some point in memory.\n\nOn the other hand, the JsonEncoder normalizes/denormalizes and\nencodes/decodes data at the same time, which allows to leverage streams,\nperformance and laziness.\n\nFor the sake of performance, the JsonEncoder differs from the Serializer in\nsome other points:\n- during cache warmup, the data shape is precompiled, and some PHP code is\n  generated. Therefore there is no way to adapt the data shape depending on\n  the data itself.\n- because there is no normalization step, there is no point in using\n  normalizers/denormalizers. Static formatters must be used instead.\n- the JsonEncoder only deals with public properties (but this can be\n  challenged, and there is no blocker to leverage the property accessor\n  instead).\n\n## When to use the Serializer component or the JsonEncoder component? \n\nMost of the time, developers will use the Serializer component, because most of\nthe time, the performance provided by that component will fit their needs. So\nthey will seamlessly benefit from the flexibility.\n\nBut, when it comes to big amounts of data, or a need for high speed, developers\nwill be able to leverage the JsonEncoder component directly.\n\nWhen can see the difference between the Serializer component and the JsonEncoder\ncomponent like the difference between Doctrine ORM and Doctrine DBAL.\n\nIndeed, the DBAL can be considered as a sub-layer of ORM, and when precise and\nperformance-related stuff is needed, developers will skip the ORM layer to deal\nwith the DBAL one directly.\n\nAnd it's the very same difference between the Serializer and the JsonEncoder,\nwhen precise and performance-related stuff is needed, developers will skip the\nnormalization layer, by fine-tuning the data mapping in their userland and deal\nwith the encoding layer directly.\n\nAnother way to consider the JsonEncoder is as the `json_encode`/`json_decode`\nfunctions, but on steroids.\n\nTherefore, the JsonEncoder can and must at some point replace the existing JSON\nencoder of the Serializer, so that only one JSON encoder exists in the Symfony\necosystem.\n\nPlus, the availability to handle streams is making the JsonEncoder a perfect\ncandidate to deal with uses cases with huge amout of data, such as ETL or\ndatalakes. Indeed, in theses cases, it is almost impossible to escape the OOM\nissues without streaming.\n\nIn addition to developers facing the challenges mentioned above in final\napplications, Symfony itself already builds on JSON streaming through e.g. the\nrecently introduced `StreamedJsonResponse` and will do more and more in the\ncoming years notably through API Platform. As such, I think Symfony would better\nbe the one providing the foundations for this and should rather gain adoption\ninstead of having its users forced to look at other, external alternatives such\nas https://github.com/halaxa/json-machine or https://github.com/cerbero90/json-parser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtarld%2Fencoder-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtarld%2Fencoder-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtarld%2Fencoder-examples/lists"}