symfony icon indicating copy to clipboard operation
symfony copied to clipboard

[Serializer][XMLEncoder] add a way to Annotate/Attribute the ROOT_NODE_NAME on a Class

Open Hanmac opened this issue 2 years ago • 3 comments

Description

add a new Annotation/Attribute to mark the XMLEncoder::ROOT_NODE_NAME on a class

Annotation\Context can't be used for this because that can't be tagged in classes (yet)

Example

/*
 * @RootNodeName("product")
 */
class Product
{
   public $name;
   public $price;
}

results in:

<product>
  <name></name>
  <price></price>
</product>

Hanmac avatar Sep 14 '23 08:09 Hanmac

probably fixed by this #51476

Hanmac avatar Sep 15 '23 07:09 Hanmac

@xabbuh some more tests to this problem:

While #[Context] can be used on Class now, that Context ist just not passed to the Encoder, only to the (de)normalizers etc., as far as I have debugged initially

and i don't know how to feed the Encoder with the Class Context yet

Hanmac avatar Jan 31 '24 12:01 Hanmac

Just ran into the same issue while trying to transform some JMS Serializer-based code into Symfony Serializer-based code. This is indeed very cumbersome. I suppose the fact that the encoder does not use the classMetadataFactory while the object normalizers do has something to do with it. Maybe the context could refreshed by a specific XmlNormalizer whose job would be (possibly among others things) to set the XmlEncoder related context properties into the "live" context. But then the context would probably have to be passed by reference to all normalizers.

rrajkomar avatar Apr 21 '24 17:04 rrajkomar