Announcement Announcement Module
Collapse
No announcement yet.
Unable to get Jaxb2Marhshaller to create indented xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to get Jaxb2Marhshaller to create indented xml

    Hi,

    I'm writing a batch process to transform an xml file into another xml format, and trying to set up the Jaxb2Marshaller to output the xml in indented format, to make it easier to read and verify.

    Now the problem is JAXB_FORMATTED_OUTPUT doesn't seem to get set in the context, even though I'm passing in the value of "true" using "marshallerProperties" property.

    I've tried using the latest version of Jaxb2Marshaller in spring-oxm-tiger-1.5.6.jar but it still doesn't work.

    I've included a snippet of the context file that I'm using. I've tried to make it complete as possible because I don't know if there are any interactions between the different beans that I'm not aware of.

    <bean id="tm" class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager"/>

    <bean id="jobRepository" class="org.springframework.batch.core.repository.s upport.MapJobRepositoryFactoryBean">
    <property name="transactionManager" ref="tm"/>
    </bean>

    <bean id="helloStep" class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean">
    <property name="transactionManager" ref="tm"/>
    <property name="jobRepository" ref="jobRepository"/>
    <property name="itemReader" ref="reader"/>
    <property name="itemWriter" ref="transformingWriter"/>
    <!--need to register the xmlWriter directly because we are using ItemTransformerItemWriter-->
    <!--see: forum.springframework.org/showthread.php?t=63297-->
    <property name="streams">
    <list>
    <ref bean="xmlWriter" />
    </list>
    </property>
    </bean>

    <bean id="transformingWriter" class="org.springframework.batch.item.transform.It emTransformerItemWriter">
    <property name="itemTransformer" ref="mapper" />
    <property name="delegate" ref="xmlWriter"/>
    </bean>

    <bean id="xmlWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter">
    <property name="rootTagName" value="JOBS"/>
    <property name="serializer" ref="xmlSerializer"/>
    <property name="overwriteOutput" value="true"/>
    <property name="resource" ref="xmlOutputFile"/>
    </bean>

    <bean id="xmlSerializer" class="org.springframework.batch.item.xml.oxm.Mars hallingEventWriterSerializer">
    <constructor-arg index="0" ref="jaxbMarshaller" />
    </bean>

    <!--TODO - can we config this so that it outputs in indented format-->
    <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="contextPath" value="our.package"/>
    <property name="marshallerProperties">
    <map>
    <!--TODO - why is this not working?? -->
    <entry>
    <key>
    <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OU TPUT" />
    </key>
    <value type="boolean">true</value>
    </entry>
    </map>
    </property>
    </bean>


    Does anyone have an idea of what is the correct config that works? I've Googled around for examples on doing this, and it seems that I'm using the right settings, but it doesnt seem to affect the formatting of the xml. The xml gets marshalled, and the output file is created, but it's just not indented.

    thanks,

    Ellecer

  • #2
    Did you resolve this as i'm trying to do the same thing?

    Comment


    • #3
      I never got a solution to this. I think we just modified our requirements. =) Is it still failing with the latest version of the code? Maybe a bug should be posted.

      Comment


      • #4
        Thanks for getting back to me.

        Yeah i'm using the latest code but it still doesn't format the xml output file.

        Going to open a new thread and hopefully if it is a bug it will be identified through that.

        Thanks again for replying to my post.

        Cheers
        Dave

        Comment


        • #5
          Hi guys! Any news about this issue? I'm stuck on this and can't get well intended XML using org.springframework.batch.item.xml.StaxEventItemWr iter together with org.springframework.oxm.jaxb.Jaxb2Marshaller

          Comment


          • #6
            Hi,

            Unfortunately I never got this to work either and implemented the project with the xml unformated.

            Here is the link to the other thread i started.

            If you do resolve this I would be interested to know how you achieved it.

            Good Luck
            Dave

            Comment


            • #7
              are you sure the key/value is correct?

              according to Java Doc : Marshaller

              jaxb.formatted.output - value must be a java.lang.Boolean
              This property controls whether or not the Marshaller will format the resulting XML data with line breaks and indentation. A true value for this property indicates human readable indented xml data, while a false value indicates unformatted xml data. The Marshaller will default to false (unformatted) if this property is not specified.

              Comment


              • #8
                Originally posted by michael.lange View Post
                are you sure the key/value is correct?
                yes, absolute.
                I have following in my spring config:
                Code:
                      <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                        <property name="contextPath" value="..." />
                        <property name="marshallerProperties">
                          <map>
                            <entry>
                              <key>
                                <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT" />
                              </key>
                              <value type="java.lang.Boolean">true</value>
                            </entry>
                          </map>
                        </property>
                      </bean>
                And I debugged, the correct key and value are coming to org.springframework.oxm.jaxb.Jaxb2Marshaller.initJ axbMarshaller(Marshaller).

                Cheers,
                Alexey

                Comment


                • #9
                  Did someone find a solution to this?
                  It is really annoying not to be able to get an indented xml file.

                  Cheers

                  Comment


                  • #10
                    Unfortunately it's still open I found the bug issue here: https://jira.springsource.org/browse/BATCH-1835

                    Comment

                    Working...
                    X