Use of the SYMFONY2 Framework Serialization tool (II)

Source: Internet
Author: User
Tags normalizer
The SYMFONY2 framework uses Objectnormalizer by default, which is already mentioned in the previous article. But in fact, in addition to the default way, you can also have more options, such as the use of getsetmethodnormalizer, you need to do is to register a service:

Services:    App.serializer.method_normalizer:        class:symfony\component\serializer\normalizer\ Getsetmethodnormalizer        Tags:            -{Name:serializer.normalizer}

Defining a service as the key to Normalizer is actually the last sentence of the definition of tags. Just define a service for Serializer.normalizer he became a normalizer in the serializer service.

The Getsetmethodnormalizer constructor allows you to allow no arguments, but you cannot use Annotation to define the serialization Group as described in the previous article, and when you register a new normalizer , the Name_converter in CONFIG.YML does not work (this setting only works with the normalizer of the frame itself), so when registering this normalizer service, it is best to mimic the normalizer that the framework comes with, read Annotation configuration of the @serializer. Mapping.class_metadata_factory services and @serializer. Name_converter.camel_case_to_snake_ Case injected into the service:

Services:    App.serializer.method_normalizer:        class:symfony\component\serializer\normalizer\ Getsetmethodnormalizer        arguments:            -' @serializer. Mapping.class_metadata_factory '            -' @serializer. Name _converter.camel_case_to_snake_case '        Tags:            -{Name:serializer.normalizer}

Circular Reference Handler

Symfony2 's documentation mentions that serialization is a very complex topic, indeed, such as careful handling of circular references, such as a user with 1 group, but the group has n user, and if the user object is serialized, it will automatically serialize the use R's Group object, and when serializing the group object, it automatically serializes all the User objects in the group ... Fortunately, the Symfony2 serialization tool can be set

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.