-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Closed
Copy link
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: bugA general bugA general bug
Milestone
Description
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:
- Backport: "Jaxb2Marshaller::supports() ignores classes found by packages scanning" [SPR-9175] #13813 Backport: "Jaxb2Marshaller::supports() ignores classes found by packages scanning"
Issue Links:
- Jaxb2Marshaller + packagesToScan + SpringMVC fails to find supported class [SPR-10551] #15182 Jaxb2Marshaller + packagesToScan + SpringMVC fails to find supported class ("is duplicated by")
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: bugA general bugA general bug