Skip to content

Commit 211e36c

Browse files
committed
SPR-6371 - Jaxb2Marshaller should use AnnotationUtils
1 parent 7ac0e2b commit 211e36c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
import org.springframework.beans.factory.BeanClassLoaderAware;
6565
import org.springframework.beans.factory.InitializingBean;
66+
import org.springframework.core.annotation.AnnotationUtils;
6667
import org.springframework.core.io.Resource;
6768
import org.springframework.oxm.MarshallingFailureException;
6869
import org.springframework.oxm.UncategorizedMappingException;
@@ -369,7 +370,7 @@ public boolean supports(Class<?> clazz) {
369370
if (JAXBElement.class.isAssignableFrom(clazz)) {
370371
return true;
371372
}
372-
else if (clazz.getAnnotation(XmlRootElement.class) != null) {
373+
else if (AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) != null) {
373374
return true;
374375
}
375376
if (StringUtils.hasLength(this.contextPath)) {

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

+16
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,20 @@ public void marshalAttachments() throws Exception {
184184
verify(mimeContainer);
185185
assertTrue("No XML written", writer.toString().length() > 0);
186186
}
187+
188+
@Test
189+
public void subclass() throws Exception {
190+
assertTrue("Flights subclass is not supported", marshaller.supports(FlightsSubclass.class));
191+
FlightType flight = new FlightType();
192+
flight.setNumber(42L);
193+
FlightsSubclass flights = new FlightsSubclass();
194+
flights.getFlight().add(flight);
195+
StringWriter writer = new StringWriter();
196+
marshaller.marshal(flights, new StreamResult(writer));
197+
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
198+
}
199+
200+
private static class FlightsSubclass extends Flights {
201+
202+
}
187203
}

0 commit comments

Comments
 (0)