JAXB generic @XmlValue

前端 未结 4 944
暖寄归人
暖寄归人 2021-02-06 06:00

The goal is to produce the following XML with JAXB


   string data
   binary data

         


        
4条回答
  •  面向向阳花
    2021-02-06 06:56

    The trick I'm usually using is to create schema with types you want and then use xjc to generate Java classes and see how annotations are used. :) I believe in XML schema proper type mapping for byte[] is 'base64Binary', so creating schema like this:

    
    
        
    
    

    and running xjc we would get following code generated:

    @XmlElementDecl(namespace = "http://www.example.org/NewXMLSchema", name = "aTest")
    public JAXBElement createATest(byte[] value) {
        return new JAXBElement(_ATest_QNAME, byte[].class, null, ((byte[]) value));
    }
    

提交回复
热议问题