-
- Notifications
You must be signed in to change notification settings - Fork 5.3k
Update serializer.rst #9939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update serializer.rst #9939
Conversation
minor doc fixes for the Message component
…(krizon) This PR was merged into the master branch. Discussion ---------- [Console] Change use statement for Process Helper Fixes the incorrect namespaces on this page. This issue was introduced in symfony#9396 Commits ------- 239f299 [Console] Change use statement for Process Helper
…r values (weaverryan) This PR was squashed before being merged into the master branch (closes symfony#9477). Discussion ---------- Removing warning about bind + controller + scalar values Docs for symfony/symfony#26658 :) Commits ------- af00dbc adding version note about scalar bind args 4312518 Removing warning about bind + controller + scalar values
…ereguiluz) This PR was squashed before being merged into the master branch (closes symfony#9490). Discussion ---------- Documented the trailing_slash_on_root option This fixes symfony#9484. @nicolas-grekas could you please verify if the config of the example is correct? I don't know if `trailing_slash_on_root` is defined for annotations. Thanks! Commits ------- b4b4954 Documented the trailing_slash_on_root option
…Form component (javiereguiluz) This PR was squashed before being merged into the master branch (closes symfony#9488). Discussion ---------- csrf_token now can be used without installing the Form component This fixes symfony#9488. @xabbuh in your original code (https://github.com/symfony/symfony/pull/25197/files) the function was added to Twig Bridge so ... could you please verify if installing just `security-csrf` is enough to use this function or if we need to install some other package? Thanks! Commits ------- 3c48a0a csrf_token now can be used without installing the Form component
* 4.0: (24 commits) added Sam in the core team minor symfony#9494 [Console] Change use statement for Process Helper (krizon) Specify how provide a high availability fixing format + language Documenting make:controller and make:crud Use FQCN as service ID Describe reliability in Lock Propose identical comparison [symfony#9195] fix a minor typo Fixed some variable names fix some security config examples Made explicit testing dependencies ...
Please enter the commit message for your changes. Lines starting
…es (javiereguiluz) This PR was merged into the master branch. Discussion ---------- Use the new TransitionException in Workflow examples This fixes symfony#9478. I couldn't find any other usage of the old `LogicException` class. Commits ------- d1f4384 Use the new TransitionException in Workflow examples
…javiereguiluz) This PR was merged into the master branch. Discussion ---------- Documented the service locator autoconfiguration This fixes symfony#9374. Commits ------- c7ea0cf Documented the service locator autoconfiguration
* 4.0: Fixed the name of the decorating service argument Fix linebreak in Code line Fix link to Tobias' Github profile
* 3.4: Use matching closing tag
The introduction states 4 big section will on the page, but the page list 1-3. (Not on 3.x)
This PR was submitted for the 4.1 branch but it was merged into the 4.0 branch instead (closes symfony#9928). Discussion ---------- Update messenger.rst <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 270b306 Update messenger.rst
…ions page (Calinou) This PR was merged into the 4.0 branch. Discussion ---------- Fix a configuration block in the Doctrine Associations page This also fixes a small typo. This issue first appeared in the `4.0` branch. Commits ------- 9a10276 Fix a configuration block in the Doctrine Associations page
This PR was merged into the 4.0 branch. Discussion ---------- Security - Fix numbering on 4.* The introduction states 4 big sections will on the page, but the page list 1-3. (not an issue on 3.x branch) Commits ------- 331a2a8 Fix numbering
…(javiereguiluz) This PR was merged into the 4.0 branch. Discussion ---------- Update Best Practices about service config format This fixes symfony#9915. @mickaelandrieu is this more clear now? Thanks! Commits ------- b08a9ca Update Best Practices about service config format
This PR was merged into the 4.0 branch. Discussion ---------- add legacy labels to keep external references for the old headlines before symfony#9921 working Commits ------- bcb2591 add legacy labels
The page is still a mess, but a tried to (at least) improve it a little. The main problem (to me) is that there a two pages for (basically) the same: * https://symfony.com/doc/4.0/serializer.html * https://symfony.com/doc/4.0/components/serializer.html ...which sometimes contradict each other, sometimes repeat each other and sometimes enhance each other. What's the advantage of having two pages at all? Why not merge them? Some additional ideas for future improvements: * Show a copy-pastable example of serializing an entity from the database, since this is (probably) the most common use-case. * Show `->select('a.name, a.price, a.desc')` together with `->getArrayResult()` as an alternative to the `@Groups` annotation * When is dependency injection possible (or superior) over `new Serializer(...)`? I edited the 4.0 version, since the page differs notably between versions, and I wasn't sure which one to take.
Sadly sometimes this results in some duplications. Overall, these would be the differences:
@ThomasLandauer is it more clear now? |
Yeah, somewhat - thanks! :-) Can I ask you some questions for me (or somebody else) to be able to make more improvements?
|
@ThomasLandauer those are great questions ... but the Serializer component is not my strong suit so I can't answer to them. Let's ask to our doc maintainers @wouterj and @xabbuh ... and also to Serializer and Symfony experts @dunglas and @Simperfit. Thanks! |
For the record I'm 👍 to merge both pages, and add examples explaining how to use features using the full stack framework, then example on how to initialize the required class in component mode. If we don't merge it:
|
Using the Serializer Service | ||
---------------------------- | ||
The serializer's constructor takes two arguments: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't merge both pages, it should be in the component page, not here.
public function index() | ||
{ | ||
// keep reading for usage examples | ||
$serializer = new Serializer(array(new DateTimeNormalizer('Y-m-d')), array(new CsvEncoder())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎, when using the full stack framework, the service registered by FrameworkBundle should alway be used. Here you don't benefit from the cache layer, groups, max depth...
Initializing the component manually belongs to the component docs.
getters (``getXxx()``), issers (``isXxx()``) or hassers (``hasXxx()``) to read | ||
properties and setters (``setXxx()``) to change properties | ||
| ||
And these encoders: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not true, they are automatically registered (to usr the YAML encoder, the Yaml component must be installed): https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml#L112-L118
| ||
These normalizers need to be loaded manually: | ||
| ||
* :class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not mention this normalizer here. We'll maybe deprecate it at some point.
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`. It's also | ||
possible to set the priority of the tag in order to decide the matching order. | ||
| ||
Here is an example on how to load the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to drop this block, but I'll not mention it in this documentation (why not in the component one, but it's confusion for frameworkbundle users)
So should we wait for additional opinions or go ahead and start merging?
I'm ignoring your other comments for now - till the big question (merge?) is answered :-) |
To configure it globally, you have to override the service definition: # config/services.yaml serializer.normalizer.datetime: class: Symfony\Component\Serializer\Normalizer\DateTimeNormalizer arguments: ['Y-m-d'] tags: [{name: serializer.normalizer, priority: -910}] Alternatively, you can change the format using the |
If you are thinking about deleting one of the two pages, that's not possible. We must maintain the component page for sure ... and the main article too (if it's still relevant). For some components we don't have a main page: e.g. DomCrawler ... we only mention it briefly in the main |
Hi guys! Thanks for the PR - let's fix this! First, I think we do need both articles. Typically, we put most of the documentation into the framework document and then only put the details about how to instantiate & setup the objects in the component documentation. To say it differently, the framework is the first class citizen. If you're using a component, we need to give you the details on how to set things up, but for usage, you will need to go look at the framework docs (which, besides how you get/instantiate the object, the usage is the same). Translation is a pretty good example:
For the serializer, I think we should do this in 3 steps (could be 3 PRs or 1 PR):
For step (2) [rewrite the framework documentation], we should probably steal a lot from the component documentation, which is much more complete (it has a diagram, shows an example class, shows serializing/deserializing objects). For the first "draft", we should probably just include the following topics:
Does anyone disagree or have any thoughts? @ThomasLandauer As we're all quite busy, we would LOVE to have your help with this. It's very important - we just need more good people to help! |
@ThomasLandauer I'd love to see this pull request move forward. However, in my experience, pull requests that try to do too many things always fail: too many merge conflicts, endless discussions, etc. So, if you have some time for this, could you send a small pull request to fix the most urgent problems of this article ... and later, if needed, submit other PRs to fix further things? Thanks! |
It's sad but I'm going to close this PR without merging because it has too many conflicts, unrelated changes, targerts an unmaintained branch, etc. @ThomasLandauer I'm really sorry. I hope you can recover some of your commits and apply them to 4.1 branch so we can review and merge. If you do so, please try to do not many changes in order to ease reviewing it. Thanks a lot! |
The page is still a mess, but a tried to (at least) improve it a little.
The main problem (to me) is that there a two pages for (basically) the same:
...which sometimes contradict each other, sometimes repeat each other and sometimes enhance each other. What's the advantage of having two pages at all? Why not merge them?
Some additional ideas for future improvements:
->select('a.name, a.price, a.desc')
together with->getArrayResult()
as an alternative to the@Groups
annotationnew Serializer(...)
?I edited the 4.0 version, since the page differs notably between versions, and I wasn't sure which one to take.