У меня возникают проблемы, когда методы afterUnmarshal()
на моих классах не вызывается, если класс является членом коллекции.JAXB/MOXy - afterUnmarshal(), как представляется, называется непоследовательно
Помимо объявления метода класса, созданного с помощью unmarshalling, существуют ли какие-либо другие шаги, которые я должен выполнить? (Я не могу увидеть что-нибудь еще в the docs)
Вот тест, который показывает проблема, у меня:
Учитывая эти классы домена два:
@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;
}
}
Этот тест терпит неудачу:
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;
}
}
Это ошибка, или я пропустил некоторые шаги, чтобы заставить это работать правильно?