KennyZgz
KennyZgz

Reputation: 33

Wrong annotation generated by XJC for extended base64Binary element

I have a web service to export image files. The entities of the web service are defined in a XSD schema and using xjc we generate the java classes used in the service response.

In the XSD the image is defined as a complexType that extends the base64Binary simple type.


<xsd:complexType name="image">
        <xsd:simpleContent>
            <xsd:extension base="xsd:base64Binary">
                <xsd:attribute name="nil" type="xsd:boolean" use="optional"/>
                <xsd:attribute name="overwrite" type="xsd:boolean"
                               use="optional"/>
                <xsd:attribute name="origin" type="xsd:string" use="optional"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

With xjc we generate the java classes and I get the following:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "image", propOrder = {
    "value"
})
public class Image {

    @XmlValue
    protected byte[] value;
    @XmlAttribute(name = "nil")
    protected Boolean nil;
    @XmlAttribute(name = "overwrite")
    protected Boolean overwrite;
    @XmlAttribute(name = "origin")
    protected String origin;

The value property has the annotation @XMlValue instead of @XmlSchemaType(name="base64Binary").

When testing the web service using SoapUI, instead of getting the base64 string with the image, I get the toString() result of the byte array image.

[B@11a0f47b

But if I manually change the @XmlValue annotation by the @XmlSchemaType(name="base64Binary"), the result is correct.

<ns1:value>LzlqLzRBQVFTa1pKUmdBQkFnQUFBUU....</ns1:value>

Upvotes: 0

Views: 178

Answers (1)

Qingfei Yuan
Qingfei Yuan

Reputation: 1212

Try to remove

<xsd:simpleContent>

in the type definition.

if doesn't work, replace with <xsd:complexContent>

Upvotes: 0

Related Questions