Java Castor Unmarshal byte array

739 views Asked by At

Good Day Community,

I have a question regarding castor unmarshaling in java. As mentioned I am using castor to unmarshal a webservice response that contains a byte array (byte[]) .. please refer to below:

public class ViewReportResponse {

private String reportId;
private byte[] report;

//getters and setters here ...

I have used castor before to unmarhsal webservice responses, but admittedly, the responses previously where always strings. The problem lyes with the byte array returned as I believe castor chokes on unmarshaling it.

My castor-mapping file is provided below:

<class name="com.domain.reporting.client.service.ViewReportResponse">

    <map-to xml="viewReportResponse" 
            xsi:schemaLocation="http://domain.com/schemas/reportingService/generateReport" 
            ns-uri="http://domain.com/schemas/reportingService/generateReport"
            ns-prefix="ns2" />

    <field name="reportId">
        <bind-xml name="reportId" 
                  node="element" 
                  type="string"/>
    </field>

    <field name="report">
        <bind-xml name="report" 
                  node="element" 
                  type="bytes" />
    </field>

I'm not sure what I am missing, but the message is received but fails at the point of unmarshaling.

I've attached a clip of the error below.

org.springframework.oxm.UnmarshallingFailureException: Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: unable to find FieldDescriptor for 'report' in ClassDescriptor of viewReportResponse.

Please any assistance is much appreciated. Thank-you kindly

1

There are 1 answers

0
Sergio On

Solved:

The general problem is not the maping to and from the byte[]. The problem is related to the use of namespace in this case.

<field name="reportId"> 
<bind-xml name="ns:reportId" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
    node="element"
    type="string"/> 

<field name="report"> 
<bind-xml name="ns:report" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
    node="element"
    type="bytes"/> 

This post is now effectively solved and closed.