Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9768

JibxMarshaller deletes comments when Result is an XMLEventWriter

    Details

    • Last commented by a User:
      true

      Description

      If a Result created from an XMLEventWriter is passed to a JibxMarshaller for marshalling, then the following happens:

      • AbstractMarshaller.marshal() delegates to AbstractMarshaller.marshalStaxResult()
      • AbstractMarshaller.marshalStaxResult() delegates to JibxMarshaller.marshalXmlEventWriter()
      • JibxMarshaller.marshalXmlEventWriter() creates a ContentHandler from the XMLEventWriter and then proceeds.

      The problem here is that the ContentHandler is a "logical view" API, not a "document view" API and (for example) does not support comments.

      So if you marshal a document containing comments, they are silently deleted.

      This is a bug: it is not appropriate to assume that comments are discardable.

        Issue Links

          Activity

          Hide
          arjen.poutsma Arjen Poutsma added a comment -

          Thanks for your help so far, Archie. I see that you're using the reference implementation of StAX. I generally recommend using Woodstox, though I am not sure if that would help in this case.

          Would it be possible for you to attach a sample project that triggers the problems? That would make it a lot easier for me to fix.

          Thanks!

          Show
          arjen.poutsma Arjen Poutsma added a comment - Thanks for your help so far, Archie. I see that you're using the reference implementation of StAX. I generally recommend using Woodstox, though I am not sure if that would help in this case. Would it be possible for you to attach a sample project that triggers the problems? That would make it a lot easier for me to fix. Thanks!
          Hide
          archie172 Archie Cobbs added a comment -

          Oops, I didn't realize it before but that last exception must be due to the AnnotatedXMLEventWriter that I'm using. So ignore that.

          In any case I'm attaching a test project that shows the three cases:

          1. Original problem
          2. My original workaround using a buffer
          3. Your new cleaner workaround

          Your workaround works fine, though for some reason it seems to delete some whitespace (probably allowed because there's no xml:space="preserve" set?).

          Show
          archie172 Archie Cobbs added a comment - Oops, I didn't realize it before but that last exception must be due to the AnnotatedXMLEventWriter that I'm using. So ignore that. In any case I'm attaching a test project that shows the three cases: Original problem My original workaround using a buffer Your new cleaner workaround Your workaround works fine, though for some reason it seems to delete some whitespace (probably allowed because there's no xml:space="preserve" set?).
          Hide
          arjen.poutsma Arjen Poutsma added a comment -

          Thanks for the test project. I will continue my investigation on Monday.

          Show
          arjen.poutsma Arjen Poutsma added a comment - Thanks for the test project. I will continue my investigation on Monday.
          Hide
          archie172 Archie Cobbs added a comment -

          Thanks. I confirmed that AnnotatedXMLEventWriter indeed was causing the earlier exception.

          However, the formatting thing is still an issue. The test case invokes JibxMarshaller.setIndent(4), but somehow all whitespace is removed from the output (except for the nested transforms).

          Show
          archie172 Archie Cobbs added a comment - Thanks. I confirmed that AnnotatedXMLEventWriter indeed was causing the earlier exception. However, the formatting thing is still an issue. The test case invokes JibxMarshaller.setIndent(4) , but somehow all whitespace is removed from the output (except for the nested transforms).
          Hide
          cbeams Chris Beams added a comment -

          Based on pull request at https://github.com/SpringSource/spring-framework/pull/147

          commit f191a55b8f570130f751c843d034451c6a277be3
          Author: Arjen Poutsma <[email protected]>
          Commit: Chris Beams <[email protected]>
           
              Preserve comments when using JibxMarshaller
              
              Prior to this commit, JibxMarshaller used a SAX ContentHandler to
              marshal to StAX XMLEventWriters, which inadvertently resulted in the
              deletion of XML comments.
              
              After this commit, JibxMarshaller adapts the XMLEventWriter into an
              XMLStreamWriter and comments are preserved.
              
              Issue: SPR-9768

          Show
          cbeams Chris Beams added a comment - Based on pull request at https://github.com/SpringSource/spring-framework/pull/147 commit f191a55b8f570130f751c843d034451c6a277be3 Author: Arjen Poutsma <[email protected]> Commit: Chris Beams <[email protected]>   Preserve comments when using JibxMarshaller Prior to this commit, JibxMarshaller used a SAX ContentHandler to marshal to StAX XMLEventWriters, which inadvertently resulted in the deletion of XML comments. After this commit, JibxMarshaller adapts the XMLEventWriter into an XMLStreamWriter and comments are preserved. Issue: SPR-9768

            People

            • Assignee:
              arjen.poutsma Arjen Poutsma
              Reporter:
              archie172 Archie Cobbs
              Last updater:
              Juergen Hoeller
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 10 weeks, 4 days ago