Unmarshalling collections in JaxB
Posted
by Stas
on Stack Overflow
See other posts from Stack Overflow
or by Stas
Published on 2009-06-23T12:06:57Z
Indexed on
2010/04/12
21:13 UTC
Read the original article
Hit count: 380
Hi,
suppose I have this class:
public class A {
private HashMap<String, B> map;
@XmlElement
private void setB(ArrayList<B> col) {
...
}
private ArrayList<B> getB() {
...
}
}
When trying to unmarshall an xml document to this class using JaxB I notice that instead of calling the setB() method and sending me the list of B instances JaxB actually calls the getB() and adds the B instances to the returned list. Why?
The reason I want the setter to be called is that the list is actually just a temporary storage from which I want to build the map field, so I thought to do it in the setter.
Thanks.
© Stack Overflow or respective owner