简体   繁体   English

从XMLEncoder的序列化中排除byte []

[英]excluding byte[] from serialization of XMLEncoder

The problem is how to except an byte[] from serialization of XMLEncoder, but i need to save this field to DB. 问题是如何从XMLEncoder的序列化中除去byte[] ,但是我需要将此字段保存到DB。 I have a Object 我有一个对象

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

and Encoder: 和编码器:

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

I need to serialize all fields except array fields. 我需要序列化除数组字段之外的所有字段。 transient modifier for property doesn't work; 属性的transient修改器不起作用; @Transient annotation on on get method doesn't work; get方法上的@Transient注释不起作用; @XMLTransient annotation on property doesn't work. 属性上的@XMLTransient注释不起作用。 It's so simple, but I need help of community! 很简单,但是我需要社区的帮助!

Answer is to use @java.beans.Transient annotaion on get method instead @Transient. 答案是在get方法上使用@java.beans.Transient注释,而不是@Transient。 In my case import javax.persistence.* caused a "bug" )) 在我的情况下, import javax.persistence.*导致了“错误”))

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 ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM