From 95d9d471ce9411af522f97efbc39dca0f3788795 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 18 Nov 2009 14:02:29 +0000 Subject: [PATCH] SPR-6371 - Jaxb2Marshaller should use AnnotationUtils git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2446 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../oxm/jaxb/Jaxb2Marshaller.java | 3 ++- .../oxm/jaxb/Jaxb2MarshallerTests.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/org.springframework.oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/org.springframework.oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index fb5669111c5..30ac57a3659 100644 --- a/org.springframework.oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/org.springframework.oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -63,6 +63,7 @@ import org.xml.sax.helpers.XMLReaderFactory; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.io.Resource; import org.springframework.oxm.MarshallingFailureException; import org.springframework.oxm.UncategorizedMappingException; @@ -369,7 +370,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl if (JAXBElement.class.isAssignableFrom(clazz)) { return true; } - else if (clazz.getAnnotation(XmlRootElement.class) != null) { + else if (AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) != null) { return true; } if (StringUtils.hasLength(this.contextPath)) { diff --git a/org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java b/org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java index 963de2d6cef..9fea0c4b56b 100644 --- a/org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java +++ b/org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java @@ -184,4 +184,20 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests { verify(mimeContainer); assertTrue("No XML written", writer.toString().length() > 0); } + + @Test + public void subclass() throws Exception { + assertTrue("Flights subclass is not supported", marshaller.supports(FlightsSubclass.class)); + FlightType flight = new FlightType(); + flight.setNumber(42L); + FlightsSubclass flights = new FlightsSubclass(); + flights.getFlight().add(flight); + StringWriter writer = new StringWriter(); + marshaller.marshal(flights, new StreamResult(writer)); + assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString()); + } + + private static class FlightsSubclass extends Flights { + + } }