我有一个具有某些属性的实体,我会将其中一些属性序列化为序列化的节点的属性。
我尝试添加@SerializedName(“ @ name”),但结果如下:
<Enitity>
<name>
Name
</name>
<Entity>
我需要这个
<Enitity name="name"/>
这是我的序列化器配置
public function serializeObjectToXml($object) {
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$normalizer = new ObjectNormalizer($classMetadataFactory);
$normalizer->setCircularReferenceLimit(1);
$normalizer->setCircularReferenceHandler(function ($object) {
return $object->getId();
});
$encoder = new XmlEncoder('ROOT');
$serializer = new Serializer(
[$normalizer],
[$encoder]
);
return $serializer->serialize($object, 'xml', ['use_attributes' => true, 'allow_extra_attributes' => false,]);
}