Byte array is not working in JAXB classes
I am trying to use byte array like this (JAXB class). However, I am getting all 0s in the msg field even though I pass valid characters. The "id" and "myid" fields are parsed successfully and it is failing for the byte array field.
@XmlRootElement(name = "testMessage")
@XmlAccessorType(XmlAccessType.FIELD)
public class TestMessage
{
@XmlAttribute
private Integer id;
@XmlElement(name = "myid")
private Long myid;
@XmlElement(name = "msg")
private byte[] msg;
}
Using JAXB of Java 1.6.0_23 i get the following xml file for a TestMessage instance:
TestMessage testMessage = new TestMessage();
testMessage.id = 1;
testMessage.myid = 2l;
testMessage.msg = "Test12345678".getBytes();
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testMessage id="1">
<myid>2</myid>
<msg>VGVzdDEyMzQ1Njc4</msg>
</testMessage>
If you unmarshall this xml content you should get back the TestMessage instance including the msg byte array (which is base64 encoded in the xml file).
链接地址: http://www.djcxy.com/p/62966.html上一篇: 如何在使用JAXB映射到对象时忽略XML中的元素/属性?
下一篇: 字节数组在JAXB类中不起作用
