提交 211e36c2 编写于 作者: A Arjen Poutsma

SPR-6371 - Jaxb2Marshaller should use AnnotationUtils

上级 7ac0e2ba
......@@ -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)) {
......
......@@ -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 {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册