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

ClassPathJaxb2TypeScanner which scans packagesToScan for Jaxb2Marshaller does not scan for @XmlRegistry annotation

    Details

    • Last commented by a User:
      true

      Description

      The ClassPathJaxb2TypeScanner class is a helper class for Jaxb2Marshaller that scans given packages for classes marked with JAXB2 annotations. However, it does not scan for the @XmlRegistry annotation, which is used on ObjectFactory classes.

      In some cases, the ObjectFactory classes contain crucial annotations for JAXB such as the following:

          @XmlElementDecl(namespace = "http://www.example.com/schemas/mymodule", 
              name = "myElement", substitutionHeadNamespace = "http://www.example.com/schemas/core", 
              substitutionHeadName = "myBaseElement")
      

      Without have scanned these annotations, JAXB will not recognize "myElement" as a valid substitution for "myBaseElement" and unmarshalling will fail.

      I have attached a very simple maven project with two test cases which illustrates the issue (pure JAXB).

      The resolution of the issue is simple (I have also tested this in the project where we ran into the problem). All that is necessary is to add XmlRegistry to the list of scanned annotations in ClassPathJaxb2TypeScanner, i.e.:

      	private final TypeFilter[] jaxb2TypeFilters =
      			new TypeFilter[]{new AnnotationTypeFilter(XmlRootElement.class, false),
      					new AnnotationTypeFilter(XmlType.class, false), new AnnotationTypeFilter(XmlSeeAlso.class, false),
      					new AnnotationTypeFilter(XmlEnum.class, false), new AnnotationTypeFilter(XmlRegistry.class, false)};
      

        Attachments

          Activity

            People

            • Assignee:
              pwebb Phil Webb
              Reporter:
              sebster Sebastiaan van Erk
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                40 weeks, 1 day ago