Flex:配置 AMF 序列化警告?
我一直在尝试测试我的应用程序,以确保所有重要的类都可以正确地序列化/重新加载自身(尤其是那些实现 IExternalizable 的类):
[Test]
public function testMyObjectSerialization():void {
var myobj:MyObject = new MyObject();
var ba:ByteArray = new ByteArray();
ba.writeObject(myobj);
ba.position = 0;
var loadedObj:MyObject = ba.readObject();
assertMyObjectEqual(myobj, loadedObj);
}
当我尝试序列化一个类时,我想收到警告没有设置 [RemoteClass]
的强类型对象(因为这几乎肯定代表我的代码中存在错误)。
那么,有没有办法配置AMF序列化器来发出警告呢?
另外,使用 services-config.xml
似乎可以实现这一点……但文档似乎暗示 services-config
是通道-级别,如果我的单元测试可以在不与服务器通信的情况下运行(而且我没有使用 LCDS,所以一堆 services-config
不适用于我),我真的很喜欢反正)。
I have been trying to test my application to make sure that all the important classes can serialize/reload themselves properly (especially those which implement IExternalizable
):
[Test]
public function testMyObjectSerialization():void {
var myobj:MyObject = new MyObject();
var ba:ByteArray = new ByteArray();
ba.writeObject(myobj);
ba.position = 0;
var loadedObj:MyObject = ba.readObject();
assertMyObjectEqual(myobj, loadedObj);
}
And I would like to be warned when I try to serialize a strongly-typed object which does not have a [RemoteClass]
set (because that almost certainly represents a bug in my code).
So, is there any way to configure the AMF serializer to give warnings?
Also, it seems like this might be possible using services-config.xml
… But the documentation seems to imply that services-config
is channel-level, and I'd really like it if my unit tests could run without talking to the server (and I'm not using LCDS, so a bunch of the services-config
wouldn't apply to me anyway).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果设置了 [RemoteClass] 或任何其他元数据,则无法从 Flash Player 配置本机 AMF 序列化/反序列化来向您发出警告。
但是,您可以编写自己的类来执行此操作 - 您可以注册列表中的所有对象并使用 flash.utils.describeType 检查 [Remote]。或者使用 writeObject 的包装来检查 [Remote] 元数据。
There is no way to configure the native AMF serialization/deserialization from the Flash Player to give you warnings if [RemoteClass] or any other metadata is set or not.
However you can write your own class to do that - you can register all the objects in a list and check for [Remote] using flash.utils.describeType. Or use a wrapper over writeObject which check for the [Remote] metadata.