Uploaded image for project: 'Spring Batch'
  1. Spring Batch
  2. BATCH-1431

StaxEventItemWriter throws IllegalStateException for JAXBElement<X>

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      In some cases JAXB2 does not create classes with an @XmlRootElement annotation.
      See http://weblogs.java.net/blog/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always

      Usually this is the case when you declare non-anonymous complex types and use those reusable types in xml-elements.

      Currently, the StaxEventItemWriter throws an IllegalStateException if you use this pattern:

      java.lang.IllegalStateException: Marshaller must support the class of the marshalled object
      at org.springframework.util.Assert.state(Assert.java:384)

      This is caused by the following statement:
      Assert.state(marshaller.supports(object.getClass()),
      "Marshaller must support the class of the marshalled object");
      (inside the method public void write(List<? extends T> items) throws XmlMappingException, IOException {}).

      The Jaxb2Marshaller.class has an additional method
      public boolean supports(Type type) {
      as opposed to public boolean supports(Class clazz) defined in the Marshaller interface.

      This Jaxb2 specific variant should be used for JAXB2.

        Attachments

          Activity

            People

            • Assignee:
              david_syer Dave Syer
              Reporter:
              fbascheper Erik-Berndt Scheper
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: