Announcement Announcement Module
Collapse
No announcement yet.
StaxEventItemWriter with jaxb2 marshaller how to suppress namespace Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StaxEventItemWriter with jaxb2 marshaller how to suppress namespace

    Hi,

    I use Spring Batch 2.1.8 and spring oxm 1.5.9. the config is as follows.


    <bean id="rsXMLWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter">
    <property name="marshaller" ref="rsMarshaller" />
    <property name="rootTagName" value="Price" />
    <property name="rootElementAttributes">
    <util:map>
    <entry key="xsi:schemaLocation" value="fsrv Price.xsd" />
    <!--
    <entry key="xmlns" value="fsrv" />
    -->
    <entry key="xmlns:xsi" value="http://www.w3.org/2001/XMLSchema-instance" />
    <entry key="Version" value="22" />

    </util:map>
    </property>

    <property name="headerCallback" ref="rsHeaderCallback" />

    </bean>


    <bean id="rsMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="classesToBeBound">
    <util:list>
    <value>com.xxx.esg.ffs.translator.jaxb2.price.Reco rdTypeTyp</value>
    <value>com.xxx.esg.ffs.translator.jaxb2.price.Stat usIndTyp</value>
    </util:list>
    </property>
    <property name="schema" value="classpath:com/xxx/esg/ffs/translator/schema/Price.xsd"/>
    </bean>

    the XML generated is as follows.

    <?xml version="1.0" encoding="UTF-8"?><Price xsi:schemaLocation="fsrv Price.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="22">
    <CreateDate>20111104</CreateDate><PerStartDate>20111104</PerStartDate><PerEndDate>20111104</PerEndDate>
    <PriceRec xmlns="fsrv"><MgmtCode>PIC</MgmtCode><FundID>801</FundID><RecordType>PRI</RecordType><StatusInd>O</StatusInd><RecordDate>20111104</RecordDate><PriceRateAccrl>+01209960000</PriceRateAccrl></PriceRec></Price>


    <Price xsi:schemaLocation="fsrv Price.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="22">
    generated by roottag and properties

    <CreateDate>20111104</CreateDate><PerStartDate>20111104</PerStartDate><PerEndDate>20111104</PerEndDate>
    generated by callback.

    <PriceRec xmlns="fsrv"><MgmtCode>PIC</MgmtCode><FundID>801</FundID><RecordType>PRI</RecordType><StatusInd>O</StatusInd><RecordDate>20111104</RecordDate><PriceRateAccrl>+01209960000</PriceRateAccrl></PriceRec>

    generated by jaxb2 marshaller.


    what I expect to see is as follows.

    <?xml version="1.0" encoding="UTF-8"?><Price xsi:schemaLocation="fsrv Price.xsd" xmlns="fsrv" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="22">
    <CreateDate>20111104</CreateDate><PerStartDate>20111104</PerStartDate><PerEndDate>20111104</PerEndDate>
    <PriceRec ><MgmtCode>PIC</MgmtCode><FundID>801</FundID><RecordType>PRI</RecordType><StatusInd>O</StatusInd><RecordDate>20111104</RecordDate><PriceRateAccrl>+01209960000</PriceRateAccrl></PriceRec></Price>


    When I try to enable <entry key="xmlns" value="fsrv" /> in StaxEventItemWriter, the spring batch report the following problem

    org.springframework.dao.DataAccessResourceFailureE xception: Unable to write to file resource: [file [/tmp/RSP0002400111011AGF901]]; nested exception is
    javax.xml.stream.XMLStreamException: xmlns has been already bound to . Rebinding it to fsrv is an error
    at org.springframework.batch.item.xml.StaxEventItemWr iter.open(StaxEventItemWriter.java:410) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
    at org.springframework.batch.item.xml.StaxEventItemWr iter.open(StaxEventItemWriter.java:339) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
    at org.springframework.batch.item.file.MultiResourceI temWriter.write(MultiResourceItemWriter.java:79) ~[spring-batch-infrastructure-2.1.8.RELEAS
    E.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) ~[na:1.6.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) ~[na:1.6.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) ~[na:1.6.0_21]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_21]

    I appreciate if someone could advise me how to fix it. I think, if I use xstream instead of jaxb2, it probably can be done, but jaxb2 can do validation, it will be my 1st choice.

    Thanks in advance!

    XZ
Working...
X