MOXy - afterUnmarshal() not called in children of lists [message #816609] |
Thu, 08 March 2012 22:27  |
Eclipse User |
|
|
|
Note - this question has been cross-posted to Stack Overflow - so, if you're a rep junkie, go grab the points!
( I can't post the link, but it's question 9628477)
I'm having trouble where the `afterUnmarshal()` methods on my classes are not called if the class is a member of a collection.
Beyond declaring the method on a class which is created via unmarshalling, is there any other steps I'm required to perform? (I can't see anything else in [the docs][1])
Here's a test which shows the problem I'm having:
Given these two domain classes:
@XmlRootElement(name="Parent")
public class Parent {
public boolean unmarshalCalled = false;
@XmlPath("Children/Child")
List<Child> children;
void afterUnmarshal(Unmarshaller u, Object parent)
{
unmarshalCalled = true;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Child {
public boolean unmarshalCalled = false;
@Getter @Setter
@XmlPath("@name")
private String name;
void afterUnmarshal(Unmarshaller u, Object parent)
{
unmarshalCalled = true;
}
}
This test fails:
public class UnmarshalTest {
@Test
@SneakyThrows
public void testUnmarshal()
{
String xml = "<Parent><Children><Child name='Jack' /><Child name='Jill' /></Children></Parent>";
JAXBContext context = getContext();
Parent parent = (Parent) context.createUnmarshaller().unmarshal(new StringReader(xml));
assertTrue(parent.unmarshalCalled);
for (Child child : parent.children)
{
assertThat(child.getName(),notNullValue());
assertTrue(child.unmarshalCalled); // This assertion fails
}
}
@SneakyThrows
public static JAXBContext getContext()
{
JAXBContext context;
context = org.eclipse.persistence.jaxb.JAXBContext.newInstance(Parent.class);
return context;
}
}
Is this a bug, or have I missed some steps to get this to work correctly?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03479 seconds