SWS-220, now tokenizing the context path string, and using equals() rather than startsWith
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<FlightsType>",
|
||||
marshaller.supports(createFlight.getGenericReturnType()));
|
||||
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
|
||||
JAXBElement<Jaxb2MarshallerTest> testElement =
|
||||
new JAXBElement<Jaxb2MarshallerTest>(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()));
|
||||
|
||||
Reference in New Issue
Block a user