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

Add the ability to Scan Packages for JAXB Marshalling (java example provided)

    Details

    • Last commented by a User:
      false

      Description

      Hi,

      In our application we have a rapidly growing number of JAXB2 annotated classes. It is a right pain to add these classes manually to the "classesToBeBound" property in the Jaxb2Marshaller. Given that other components (I'm looking at you Hibernate : AnnotationSessionFactoryBean) have the ability to automatically add classes from packages that match annotations, why not then for the Jaxb2Marshaller (having to key in the classes manually is so old skool).

      I've extended Jaxb2Marshaller (file attached) that scans on the classpath for appropriately annotated classes. Please do review and I hope that this can be incorporated into the next release. I'm happy to make changes to the codebase if required to bring it up to Spring coding standards.

      It's a pity that afterPropertiesSet is marked as Final in Jaxb2Marshaller since I can't override that method to set up the setClassesToBeBound before then calling the super afterPropertiesSet. Currently as the code stands, I have to provide a dummy setClassesToBeBound and setLazyInit to be true. This dummy is then replaced by overriding the getJaxbContext. I think this needs rewriting.

      An example of use:

      <bean id="marshaller" class="foo.bar.AnnotationJaxb2Marshaller">
          <property name="lazyInit" value="true" />
          <property name="classesToBeBound">
             <list>
                 <value>foo.bar.Class</value>
             </list>
          </property>
          <property name="packagesToScan">
              <list>
                  <value>foo.bar.jaxb.model</value>
              </list>
          </property>
      </bean>
      

      =david=

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                arjen.poutsma Arjen Poutsma
                Reporter:
                dharrigan David Harrigan
                Last updater:
                Juergen Hoeller
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  6 years, 18 weeks, 2 days ago