Hi all,
I have a class that contains a list, the contents of which I'd like to
customize the marshalling of using an XmlAdapter. Basically I have
the following:
class Accessories
{
List<Accessory> accessories;
}
but I'd like to change the way Accessory is marshalled. So I've tried this:
@XmlJavaTypeAdapter(AccessoriesXmlAdapter.class)
class Accessory
{
}
but that seems to be ignored (I'm assuming that the XmlJavaTypeAdapter
annotation is only valid on fields, but the jaxb-ri-20050407 doco
doesn't seem to give any indication).
So I'm assuming I need to write an adapter to do this:
public class AccessoriesXmlAdapter extends XmlAdapter<List,List>
but when I do that, I find that instead of the expected output I get this:
<Accessories>
</Accessories>
when I step out of my custom marshall method which returns the correct
list of 7 items that are annotated as I'd like them to be saved I find
that in ArrayElementProperty.serializeBody(BeanT o, XMLSerializer w)
there appears to be no TagAndType available for my mapped class and so
the following code is executed:
if(tt==null) {
// item is not of the expected type.
TODO.prototype(); // TODO: error report
continue;
}
and hence I get no output.
I've tried a couple of other things but without success. At this
stage I'm going to step up a level and put a java adapter on the
Accessories field to make it work that way until I can figure this
out.
Does the above make sense? Am I missing something? I also found that
I got a ClassCastException when my adapter was mapping List<Accessory>
to List<XmlAccessory> which I would have thought was correct. Sorry
to not be more verbose on that but I did have a nice email written and
I lost it when windows decided it had better uses for my gmail window
(o:
thanks again (in advance)
cheers
dim