• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Axis2 support for collections

 
Ram Charan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does axis2 support collections as return types and input arguments in webservices? My deployment env is Axis2 + JBoss4.2 + EJB3.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not use Java collections in a web service. They're not part of XML Schema, and thus can't be used by WSDL. They're also not cross-platform compatible, which is a major point of WS. Use arrays instead of collections.
 
Suryavas.k Kazipeta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Implementing java.util.Collections is possible in WebServices using @XmlJavaTypeAdapter of JAXB 2.0.
have a look on below link and example
https://jaxb.dev.java.net/guide/XML_layout_and_in_memory_data_layout.html

@XmlRootElement
class ComplexStruct {
@XmlJavaTypeAdapter(value=ArrayListDataAdapter.class)
@XmlElement
ArrayList<Data> dataList;
}

class ArrayListDataAdapter extends XmlAdapter<Data[], ArrayList<Data>> {

@Override
public ArrayList<Data> unmarshal(Data[] objectArray2ArrayList) {
if ( objectArray2ArrayList == null )
return null;

return new ArrayList<Data>(Arrays.asList(objectArray2ArrayList));
}
@Override
public Data[] marshal(ArrayList<Data> arrayList2ObjectArray) {
if ( arrayList2ObjectArray == null )
return null;

Data[] dataArray = new Data[ arrayList2ObjectArray.size() ];
int i=0;
for (Data data : arrayList2ObjectArray) {
dataArray [ i++ ] = data;
}
return dataArray;
}
}
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suryavas.k Kazipeta:





Consider using instead:



In general:


See also Implementing Collections In WebServices
[ November 25, 2008: Message edited by: Peer Reynders ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic