Announcement Announcement Module
Collapse
No announcement yet.
How do you configure xmlStaxJob.xml when using Complex Types? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you configure xmlStaxJob.xml when using Complex Types?

    I have three domnain classes which look like this:

    public class Location {
    private String productName;
    private String commOrPers;
    private String crimeCommOrPers;
    private ReportParam reportParam;
    private HomeAddress homeAddress;
    ...
    }

    public class HomeAddress {
    private boolean isScrubAddr;
    private String trilliumScore;
    private String failLevel;
    private String origAddrLine;
    ...
    }

    public class ReportParam {
    private String name;
    private String vaule;
    ...
    }

    How do I configure my locationXmlStaxJob.xml to properly parse these objects if my XML looks like this:
    <root>
    <LOCATION>
    <ProductName>PPCXD</ProductName>
    <CommOrPers>B</CommOrPers>
    <CrimeCommOrPers>P</CrimeCommOrPers>
    <ADDRESS>
    <HomeAddress>
    <HomeIsScrubAddr>Y</HomeIsScrubAddr>
    <HomeTrilliumScore>100</HomeTrilliumScore>
    <HomeFailLevel>0</HomeFailLevel>
    <HomeOrigAddrLine>508 HURLEY DR;</HomeOrigAddrLine>
    <HomeOrigCity>DEFUNIAK SPRINGS</HomeOrigCity>
    <HomeOrigState>FL</HomeOrigState>
    <HomeOrigZip>32433</HomeOrigZip>
    ...
    </HomeAddress>
    </ADDRESS>
    </LOCATION>
    <LOCATION>
    <ProductName>PPCXD</ProductName>
    <CommOrPers>B</CommOrPers>
    <CrimeCommOrPers>C</CrimeCommOrPers>
    <ADDRESS>
    <HomeAddress>
    <HomeIsScrubAddr>Y</HomeIsScrubAddr>
    <HomeTrilliumScore>100</HomeTrilliumScore>
    <HomeFailLevel>0</HomeFailLevel>
    <HomeOrigAddrLine>5133 Otis Avenue</HomeOrigAddrLine>
    <HomeOrigCity>Tarzana</HomeOrigCity>
    <HomeOrigState>CA</HomeOrigState>
    <HomeOrigZip>91356</HomeOrigZip>
    <HomeOrigZipPlus></HomeOrigZipPlus>
    <HomeZip>91356</HomeZip>
    ...
    </HomeAddress>
    </ADDRESS>
    </LOCATION>
    </root>

    I'm not able to find any documentation on this - any help would be approciated.

    Thanks.

    p.s. Here's the last version of my job config:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

    <bean parent="stepScope" />
    <bean parent="jobConfigurationRegistryBeanPostProcessor" />

    <bean id="locationXmlStaxJob" parent="simpleJob">
    <property name="steps">
    <bean id="step1" parent="simpleStep">
    <property name="tasklet">
    <bean
    class="org.springframework.batch.execution.tasklet .ItemOrientedTasklet">
    <property name="itemReader">
    <bean
    class="org.springframework.batch.io.xml.StaxEventI temReader"
    scope="step">
    <aop:scoped-proxy />
    <property name="fragmentRootElementName"
    value="LOCATION" />
    <property name="resource"
    value="data/staxJob/input/LocationBatchInput.xml" />
    <property name="fragmentDeserializer">
    <bean
    class="org.springframework.batch.io.xml.oxm.Unmars hallingEventReaderDeserializer">
    <constructor-arg>
    <bean
    class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases"
    ref="aliases" />
    </bean>
    </constructor-arg>
    </bean>
    </property>
    </bean>
    </property>
    <property name="itemWriter"
    ref="locationStaxWriter" />
    </bean>
    </property>
    </bean>
    </property>
    </bean>

    <bean class="org.springframework.batch.io.xml.StaxEventI temWriter"
    id="locationStaxWriter">
    <property name="resource"
    value="file:target/test-outputs/LocationBatch.output.xml" />
    <property name="serializer" ref="locatoinMarshallingSerializer" />
    <property name="rootTagName" value="root" />
    <property name="overwriteOutput" value="true" />
    </bean>

    <bean
    class="org.springframework.batch.io.xml.oxm.Marsha llingEventWriterSerializer"
    id="locatoinMarshallingSerializer">
    <constructor-arg>
    <bean
    class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases" ref="aliases" />
    </bean>
    </constructor-arg>
    </bean>

    <util:map id="aliases">
    <entry key="LOCATION" value="com.iso.la.batch.domain.Location" />
    <entry key="ProductName" value="java.lang.String" />
    <entry key="CommOrPers" value="java.lang.String" />
    <entry key="CrimeCommOrPers" value="java.lang.String" />
    <entry key="ADDRESS" value="com.iso.la.batch.domain.Address" />
    <entry key="HomeAddress"
    value="com.iso.la.batch.domain.HomeAddress" />
    <entry key="HomeIsScrubAddr" value="java.lang.String" />
    <entry key="HomeTrilliumScore" value="java.lang.String" />
    <entry key="HomeFailLevel" value="java.lang.String" />
    <entry key="HomeOrigAddrLine" value="java.lang.String" />
    <entry key="HomeOrigCity" value="java.lang.String" />
    <entry key="HomeOrigState" value="java.lang.String" />
    <entry key="HomeOrigZip" value="java.lang.String" />
    <entry key="HomeOrigZipPlus" value="java.lang.String" />
    <entry key="HomeZip" value="java.lang.String" />
    <entry key="HomeZipPlus" value="java.lang.String" />
    <entry key="HomeStreetNum" value="java.lang.String" />
    <entry key="HomeStreetPreDir" value="java.lang.String" />
    <entry key="HomeStreetName" value="java.lang.String" />
    <entry key="HomePostDir" value="java.lang.String" />
    <entry key="HomeStreetType" value="java.lang.String" />
    <entry key="HomeCity" value="java.lang.String" />
    <entry key="HomeState" value="java.lang.String" />
    <entry key="HomeCountry" value="java.lang.String" />
    </util:map>



    <!-- register the step scope with the application context -->
    <bean class="org.springframework.batch.execution.scope.S tepScope" />

    </beans>

  • #2
    Your configuration seems reasonable, but I don't know what problems you encountered. You are using XStream, so XStream gurus should be able to give better advice.

    Comment


    • #3
      Runs fine, but domain objects are null

      The code runs without any exceptions, and a Location instance gets created, but all of it attributes are null:

      private String productName;
      private String commOrPers;
      private String crimeCommOrPers;
      private ReportParam reportParam;
      private HomeAddress homeAddress;


      Nigel

      Comment

      Working...
      X