Byte array not working in JAXB classes

I am trying to use a byte array like this (JAXB class). However, I get all 0s in the msg field, although I pass in valid characters. The "id" and "myid" fields were successfully parsed and they do not work 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;
 }
+4
source share
1 answer

Using JAXB Java 1.6.0_23, I get the following XML file for the 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 unmount this xml content, you must return an instance of TestMessage, including the msg byte array (which is encoded base64 in the XML file).

+4
source

Source: https://habr.com/ru/post/1333967/


All Articles