除字节[]从XMLEn codeR系列化 [英] excluding byte[] from serialization of XMLEncoder

查看:140
本文介绍了除字节[]从XMLEn codeR系列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是如何以除外的字节[] 从XMLEn codeR系列化,但我需要这个字段保存到数据库。我有一个对象

The problem is how to except an byte[] from serialization of XMLEncoder, but i need to save this field to DB. I have a Object

public class MyClass1 implements Serializable {
 some properties ...
 private  byte[] a01_14_01_content;
 getters and setters ...
}

和恩codeR:

import java.beans.XMLEncoder;
public class MyEncoder{ 
...
public byte[] getBytes() {
    XMLEncoder e = new XMLEncoder(baos);
    e.writeObject(answer);
    e.close();
    return baos.toByteArray();
}
}

我需要序列化,除了数组字段的所有字段。
瞬态修饰符属性不起作用;
@Transient 标注上get方法不起作用;
@XmlTransient 物业标注不起作用。
它是如此简单,但我需要社会的帮助!

I need to serialize all fields except array fields. transient modifier for property doesn't work; @Transient annotation on on get method doesn't work; @XMLTransient annotation on property doesn't work. It's so simple, but I need help of community!

推荐答案

答案是使用 @ java.beans.Transient annotaion上获取方法@Transient。
在我的情况进口javax.persistence。* 引起错误))

Answer is to use @java.beans.Transient annotaion on get method instead @Transient. In my case import javax.persistence.* caused a "bug" ))

public class MyClass1 implements Serializable {
 some properties ...
 private  byte[] a01_14_01_content;

 @javax.beans.Transient //not @Transient
 public byte[] getA01_14_01_content() {
 return a01_14_01_content;
 } 
//getters and setters ...
}

这篇关于除字节[]从XMLEn codeR系列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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