-
1. Re: Issue in JBoss with @XmlElementWrapper in combination with @ResponseWrapper
rafachies Jan 20, 2015 6:04 AM (in response to philipprusskneipcom)Hi Philipp,
This is because you are using an inner class, and also no getter and setter to the myDatas List. Also, you don't need the XmlElement annotation if you are already annotating the field with RequestWrapper. Please, try this:
@XmlAccessorType( XmlAccessType.FIELD )
@XmlType( name = "getMyDatasResult", propOrder = { "myDatas" } )
public static class GetMyDatasResult {
@XmlElementWrapper( name = "myDatas", required = true, nillable = false )
private List<MyData> myDatas;
public List<MyData> getMyDatas() {
return myDatas;
}
public void setMyDatas(List<MyData> myDatas) {
this.myDatas = myDatas;
}
}
-
2. Re: Issue in JBoss with @XmlElementWrapper in combination with @ResponseWrapper
philipprusskneipcom Feb 5, 2015 10:06 AM (in response to rafachies)Thanks for your reply !
I tried it out and it works in JBoss. What makes me confusing is that the below does work in JBoss although it uses the same pattern as I used above (which doesn't work), i.e. the pattern uses a nested class, it uses both @XmlElementWrapper and @XmlElement, and XmlAccessType.PUBLIC_MEMBER.
public class XmlElementWrapperTest {
@XmlRootElement
@XmlAccessorType( XmlAccessType.PUBLIC_MEMBER )
public static class Customer {
@XmlElementWrapper( name="email-addresses", required = true, nillable = false )
@XmlElement( name="email-address", required = false, nillable = false )
public List<String> emailAddresses;
public Customer() {
emailAddresses = new ArrayList<String>();
}
}
public static void test() throws Exception {
JAXBContext jc = JAXBContext.newInstance( Customer.class );
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
Customer customer1 = new Customer();
customer1.emailAddresses.add( "charliebrown@example.com" );
customer1.emailAddresses.add( "snoopy@example.org" );
marshaller.marshal( customer1, System.out );
Customer customer2 = new Customer();
marshaller.marshal( customer2, System.out );
}
}
Can you explain why this works in JBoss but my class GetMyDatasResult does not ?