序列化为 XML 时出现异常(但不序列化为 JSON)
Exception when serializing to XML (but not to JSON)
我正在使用 Symfony 3.3
序列化器。此代码:
$serialized = $this->serializer->serialize($input, "json");
returns:
{
"title": "dsd",
"description": null,
"source": null,
"tags": null,
"objectId": null,
"attributes": {
"sdffds": "sdffsdfsd",
"fsfdsfd": "sdfsdfsdf"
},
"features": [],
"lifecycleStart": null,
"lifecycleEnd": null,
"attachments": {
"20170625194534-595012dee26c8": {
"original": "favicon (1).ico",
"filename": "favicon (1).ico",
"size": "318",
"title": null,
"description": null,
"reader": null
}
}
}
不幸的是,运行
$serialized = $this->serializer->serialize($input, "xml");
会抛出异常:
Uncaught PHP Exception DOMException: "Invalid Character Error" at /www/site/ui/vendor/symfony/symfony/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php line 454
我很确定我没有添加任何有趣的角色。你知道我是做错了什么还是 symfony 的错误?
可能是因为20170625194534-595012dee26c8
。 XML 元素名称不能以数字开头。请参阅:The Naming of Parts 关于 XML.com 的文章。
我正在使用 Symfony 3.3
序列化器。此代码:
$serialized = $this->serializer->serialize($input, "json");
returns:
{
"title": "dsd",
"description": null,
"source": null,
"tags": null,
"objectId": null,
"attributes": {
"sdffds": "sdffsdfsd",
"fsfdsfd": "sdfsdfsdf"
},
"features": [],
"lifecycleStart": null,
"lifecycleEnd": null,
"attachments": {
"20170625194534-595012dee26c8": {
"original": "favicon (1).ico",
"filename": "favicon (1).ico",
"size": "318",
"title": null,
"description": null,
"reader": null
}
}
}
不幸的是,运行
$serialized = $this->serializer->serialize($input, "xml");
会抛出异常:
Uncaught PHP Exception DOMException: "Invalid Character Error" at /www/site/ui/vendor/symfony/symfony/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php line 454
我很确定我没有添加任何有趣的角色。你知道我是做错了什么还是 symfony 的错误?
可能是因为20170625194534-595012dee26c8
。 XML 元素名称不能以数字开头。请参阅:The Naming of Parts 关于 XML.com 的文章。