Skip to content

Jaxb2Marshaller::supports() ignores classes found by packages scanning [SPR-9152] #13790

@spring-projects-issues

Description

@spring-projects-issues

Mikhail Moussikhine opened SPR-9152 and commented

Use case:

Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller() {
jaxb2Marshaller.setPackagesToScan(new String[] { "com.blah" });
...
if (jaxb2Marshaller.supports(SomeJaxbAnnotatedClass.class)) {
  ...
}

org.springframework.oxm.jaxb.Jaxb2Marshaller::supports() will always return false in this case, since it does not take scanned classes into account. The culprit is:

private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement) {
  ...
}

It checks input clazz only against explicit contextPath and classesToBeBound. The simplest solution would be to allow createJaxbContextFromPackages() to set scanned classes as classesToBound, since contextPath, classesToBeBound and packagesToScan are mutually exclusive. The following code would do the trick:

private JAXBContext createJaxbContextFromPackages() throws JAXBException {
  ...
  Class<?>[] jaxb2Classes = scanner.getJaxb2Classes();
  classesToBeBound = jaxb2Classes;
  ...
}

The problem is aggravated by the fact that there does not seem to be a way to get the classes from JAXBContext either.


Affects: 3.1.1

Sub-tasks:

Issue Links:

Referenced from: commits 3f48c71, 43b4997

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions