数组子类无法反序列化,错误 #1034 [英] Array subclasses cannot be deserialized, Error #1034

查看:33
本文介绍了数组子类无法反序列化,错误 #1034的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在从 ByteArray 反序列化时发现了一个奇怪的错误,其中 Vector 不能包含扩展 Array 的类型:有反序列化时出现 TypeError.

I've just found a strange error when deserializing from a ByteArray, where Vectors cannot contain types that extend Array: there is a TypeError when they are deserialized.

TypeError: Error #1034: Type Coercion failed: cannot convert []@4b8c42e1 to com.myapp.ArraySubclass.
    at flash.utils::ByteArray/readObject()
    at com.myapp::MyApplication()[/Users/aaaidan/MyApp/com/myapp/MyApplication.as:99]

方法如下:

public class Application extends Sprite {
    public function Application() {
        // register the custom class
        registerClassAlias("MyArraySubclass", MyArraySubclass);        

        // write a vector containing an array subclass to a byte array
        var vec:Vector.<MyArraySubclass> = new Vector.<MyArraySubclass>();
        var arraySubclass:MyArraySubclass = new MyArraySubclass();
        arraySubclass.customProperty = "foo";
        vec.push(arraySubclass);

        var ba:ByteArray = new ByteArray();
        ba.writeObject(arraySubclass);
        ba.position = 0;

        // read it back
        var arraySubclass2:MyArraySubclass = ba.readObject() as MyArraySubclass; // throws TypeError
    }
}

public class MyArraySubclass extends Array {
    public var customProperty:String = "default";
}

这是一个非常具体的案例,但对我来说似乎很奇怪.任何人都知道是什么导致了它,或者如何修复它?

It's a pretty specific case, but it seems very odd to me. Anyone have any ideas what's causing it, or how it could be fixed?

推荐答案

好吧,看来数组序列化是硬编码的.您绝对应该发布错误报告.

well, it seems array serialization is hardcoded. you should definitely post a bug report.

实际上您发布的代码不会引发错误,因为 ba.readObject() as MyArraySubclass 只是 null.MyArraySubclass(ba.readObject()) 但是会.

actually the code you posted doesn't throw an error since ba.readObject() as MyArraySubclass is simply null. MyArraySubclass(ba.readObject()) however would.

您可以尝试修复它的方法是实施 IExternalizable,虽然我不确定它会不会更好.

what you could try to fix it, would be to implement IExternalizable, altough I'm not sure it'll work any better.

我想问题在于 Array 是 ActionScript 中一个非常非常特殊的类(从某种意义上说,它只不过是任何其他动态类,但在其他方面则不是all) 这会导致 VM 中出现大量 Array 特定的代码.另外,一个问题是,为什么需要对 Array 进行子类化?

I guess the problem is that Array is a very very special class in ActionScript (in the sense that in some way it is nothing more than any other dynamic class, but in other ways it's not at all) which leads to a lot of Array-specific code in the VM. Also, a question is, why do you need to subclass Array?

这篇关于数组子类无法反序列化,错误 #1034的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆