diff --git a/oxm-tiger/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/oxm-tiger/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index 254365aa..5c4bcfad 100644 --- a/oxm-tiger/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/oxm-tiger/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -209,7 +209,13 @@ public class Jaxb2Marshaller extends AbstractJaxbMarshaller return false; } String packageName = className.substring(0, lastDotIndex); - return getContextPath().startsWith(packageName); + String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":"); + for (int i = 0; i < contextPaths.length; i++) { + if (contextPaths[i].equals(packageName)) { + return true; + } + } + return false; } else if (!ObjectUtils.isEmpty(classesToBeBound)) { return Arrays.asList(classesToBeBound).contains(clazz); diff --git a/oxm-tiger/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTest.java b/oxm-tiger/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTest.java index 136b554e..5560c86e 100644 --- a/oxm-tiger/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTest.java +++ b/oxm-tiger/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTest.java @@ -194,7 +194,23 @@ public class Jaxb2MarshallerTest extends XMLTestCase { verify(handlerMock); } - public void testSupports() throws Exception { + public void testSupportsContextPath() throws Exception { + Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights"); + assertTrue("Jaxb2Marshaller does not support Flights", + marshaller.supports(createFlights.getGenericReturnType())); + Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class); + assertTrue("Jaxb2Marshaller does not support JAXBElement", + marshaller.supports(createFlight.getGenericReturnType())); + assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class)); + JAXBElement testElement = + new JAXBElement(new QName("something"), Jaxb2MarshallerTest.class, null, this); + assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass())); + } + + public void testSupportsClassesToBeBound() throws Exception { + marshaller = new Jaxb2Marshaller(); + marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class}); + marshaller.afterPropertiesSet(); Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights"); assertTrue("Jaxb2Marshaller does not support Flights", marshaller.supports(createFlights.getGenericReturnType()));