将 java Byte[] 映射到 actionscript ByteArray 时出错
上下文 - GraniteDS + JPA DataNucleus + MySQL
该场景是在数据库中存储/检索图像。
问题在于从数据库检索。书籍封面已获取 来自数据库,但在 Flex 前面,它显示为空。
从 java“Byte[]”到 flex“ByteArray”的翻译返回 null。
下面是 2 个类文件。
AcrionScript 类
[RemoteClass(alias="com.app.model.Book")]
public class Book
{
public var id:uint;
public var cover:ByteArray;
}
Java 类
@Entity 公共类 Book 实现了 Serialized{
@Id
private Long id;
@Lob
@Basic(fetch=FetchType.EAGER)
private Byte[] cover = null;
}
谢谢
Context - GraniteDS + JPA DataNucleus + MySQL
The scenario is to store / retrieve an image in db.
The issue is with the retrieval FROM db. The book cover is fetched
from the db but at the flex front it shows as null.
The translation from java "Byte[]" to flex "ByteArray" is returning null.
Below are the 2 class files.
AcrionScript class
[RemoteClass(alias="com.app.model.Book")]
public class Book
{
public var id:uint;
public var cover:ByteArray;
}
Java class
@Entity
public class Book implements Serializable{
@Id
private Long id;
@Lob
@Basic(fetch=FetchType.EAGER)
private Byte[] cover = null;
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个序列化问题。
带有大写 B 的 Byte 是 a比
byte
原始对象更复杂的包装类。这是一个重要的事实,因为 AMF 串行器/解串器与内省一起工作。
所有非原始对象都必须有一个特定的类,其中包含通信通道两端的所有公共属性。
Byte
类不是原始类型,因此,默认情况下它不会被 AMF 序列化器/反序列化器识别,因此您从 java 发送到的每个Byte[]
对象也不会被识别。 Flex 会自动转换为 null。尝试将
Byte[]
更改为byte[]
并查看是否适合您。如果您确实需要使用 Byte[],请查看 上的花岗岩文档编写自定义序列化类以能够传输
字节
对象。请记住,这还需要您在 Flex 端编写一个解串器/串行器,并且在性能方面可能不是一个好的选择。
干杯
This seems to be a serialization issue.
Byte with a capital B is a wrapper class that is more elaborate than the
byte
primitive object.This is an important fact since an AMF serializer/deserializer works with introspection.
All non-primitive objects must have a specific class containing all public properties on both ends of your communication channel.
The
Byte
class is not a primitive type and therefore, it will not be recognized by default by the AMF serializer/deserializer and thus everyByte[]
object you send from java to Flex will be automatically converted to null.Try changing a
Byte[]
tobyte[]
and see if that works for you.If you truely need to use Byte[], check out the granite documentation on writing custom serialization classes to be able to transport
Byte
Objects.Keep in mind though that this will require you to write a deserializer/serializer on the Flex side as well and will probably not be a good choice when it comes to performance.
Cheers