java - Using a JAXB XmlAdapter to adapt an entire list without a wrapper element -


i'm trying use xmladapter unmarshal xml custom collection type (that intentionally not implement collection interface due conflicting restriction imposed use of class, unfortunately fails if class contains collections). difficulty xml nodes placed collection not wrapped in wrapper element.

here's xml looks like:

<xml>   <foo></foo>   <bar>1</bar>   <bar>2</bar> </xml> 

i can make jaxb unmarshall following pojo:

class naive {   foo foo;   list<bar> bar; } 

however, want following:

class bars {   // there fixed number of these, known in advance   bar bar1;   bar bar2;  }  class barsadapter extends xmladapter<arraylist<bar>, bars> {   ... }  class custom {   foo foo;   @xmljavatypeadapter(barsadapter.class)  // won't work   bars bar; } 

as can see, wrote xmladapter wants adapt entire list, not individual elements, never gets invoked unmarshalling. (it invoked marshalling.)

if xml contained wrapper around <bar> elements, know how solve this:

<xml>   <foo></foo>   <wrapper>     <bar>1</bar>     <bar>2</bar>   </wrapper> </xml> 

because annotate bars field @xmlelement(id="wrapper") , adapter correctly called. however, xml schema comes rfc , entirely unchangeable, stuck how proceed. ideas appreciated!


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -