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