Skip to content

Commit 43b4997

Browse files
committed
Support scanned classes in Jaxb2Marshaller
Jaxb2Marshaller#supports now supports classes found via package scanning. Issue: SPR-9152
1 parent 83f3750 commit 43b4997

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ private JAXBContext createJaxbContextFromPackages() throws JAXBException {
457457
if (logger.isDebugEnabled()) {
458458
logger.debug("Found JAXB2 classes: [" + StringUtils.arrayToCommaDelimitedString(jaxb2Classes) + "]");
459459
}
460+
this.classesToBeBound = jaxb2Classes;
460461
if (this.jaxbContextProperties != null) {
461462
return JAXBContext.newInstance(jaxb2Classes, this.jaxbContextProperties);
462463
}

spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ public void supportsClassesToBeBound() throws Exception {
163163
marshaller.afterPropertiesSet();
164164
testSupports();
165165
}
166+
167+
@Test
168+
public void supportsPackagesToScan() throws Exception {
169+
marshaller = new Jaxb2Marshaller();
170+
marshaller.setPackagesToScan(new String[] {CONTEXT_PATH});
171+
marshaller.afterPropertiesSet();
172+
testSupports();
173+
}
166174

167175
private void testSupports() throws Exception {
168176
assertTrue("Jaxb2Marshaller does not support Flights class", marshaller.supports(Flights.class));
@@ -279,13 +287,6 @@ public void marshalAttachments() throws Exception {
279287
assertTrue("No XML written", writer.toString().length() > 0);
280288
}
281289

282-
@Test
283-
public void supportsPackagesToScan() throws Exception {
284-
marshaller = new Jaxb2Marshaller();
285-
marshaller.setPackagesToScan(new String[] {CONTEXT_PATH});
286-
marshaller.afterPropertiesSet();
287-
}
288-
289290
@XmlRootElement
290291
public static class DummyRootElement {
291292

0 commit comments

Comments
 (0)