I'm trying to construct a mapping file for this class (lots of hopefully irrelevant details have been snipped and modified in an attempt to show just the basic problem):

class Foo {
List bars;
public Foo () {
bars = new ArrayList();
}

public void addBar (Bar b) {
bars.add(b);
}

public List getBars () {
return Collections.unmodifiableList(bars);
}
}

Important: Note that the getBars method returns an *unmodifiable* list.

My mapping file:

<class name="Foo">
<field name="bars" type="Bar" collection="arraylist">
<bind-xml name="bars" node="element"/>
</field>
</class>

A Foo appropariately marshals and creates the XML that I expect. However, trying to unmarshal the resultant XML ends up throwing an UnsupportedOperationException when the Bar is added to the list. My best guess from the stack trace is that the code is doing something like:

Bar b = new Bar();
List bars = foo.getBars();
bars.add(b);

This *will* cause the exception. What I'd like the code to do is more like:

Bar b = new Bar();
foo.addBar(b);

How can I do this with the mapping?
--
PC

Paul Christmann
Prior Artisans, LLC
mailto:[EMAIL PROTECTED]
504-587-9072

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev

Reply via email to