SpringBatch Jaxb2Marshaller: different name of class and xml attribute

Posted by user588961 on Stack Overflow See other posts from Stack Overflow or by user588961
Published on 2014-08-21T15:47:25Z Indexed on 2014/08/21 16:20 UTC
Read the original article Hit count: 232

Filed under:
|
|
|
|

I try to read an xml file as input for spring batch:

Java Class:

package de.example.schema.processes.standardprocess;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Process", namespace = "http://schema.example.de/processes/process", propOrder = {
    "input"
})
public class Process implements Serializable
{

    @XmlElement(namespace = "http://schema.example.de/processes/process")
    protected ProcessInput input;

    public ProcessInput getInput() {
        return input;
    }

    public void setInput(ProcessInput value) {
        this.input = value;
    }

}

SpringBatch dev-job.xml:

<bean id="exampleReader" class="org.springframework.batch.item.xml.StaxEventItemReader" scope="step">
    <property name="fragmentRootElementName" value="input" />
    <property name="resource"
        value="file:#{jobParameters['dateiname']}" />
    <property name="unmarshaller" ref="jaxb2Marshaller" />
</bean>

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>de.example.schema.processes.standardprocess.Process</value>
            <value>de.example.schema.processes.standardprocess.ProcessInput</value>
            ...
        </list>
    </property>
</bean>

Input file:

<?xml version="1.0" encoding="UTF-8"?>
<process:process xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:process="http://schema.example.de/processes/process">
    <process:input>
        ...
    </process:input>
</process:process>

It fires the following exception: [javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schema.example.de/processes/process", local:"input"). Expected elements are <<{http://schema.example.de/processes/process}processInput>] at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:92) at org.springframework.oxm.jaxb.AbstractJaxbMarshaller.convertJaxbException(AbstractJaxbMarshaller.java:143) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:428)

If I change to in xml it work's fine. Unfortunately I can change neither the xml nor the java class.

Is there a possibility to make Jaxb2Marshaller map the element 'input' to the class 'ProcessInput'?

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml