Reputation: 7076
So I have this webservice that runs in a glassfish server and connects to a mysql database which contains several webmethods, among them:
@WebMethod(operationName = "getDrops")
public Dropslog[] getDrops(@WebParam(name = "User") Users user, @WebParam(name = "MonsterID") int monsterID){
return dbmg.getDrops(user, monsterID);
}
As you can see this method returns a variable of type Dropslog[] by calling this method from another class:
public Dropslog[] getDrops(Users user, int monsterID){
Dropslog drop;
Criteria criteria = session.createCriteria(Dropslog.class);
criteria.add(Restrictions.eq("monsterId", monsterID));
drop = (Dropslog) criteria.uniqueResult();
List<Dropslog> drops = (List<Dropslog>) criteria.list();
Dropslog[] dropsArray = new Dropslog[drops.size()];
dropsArray = drops.toArray(dropsArray);
return dropsArray;
}
This method previously returned drops
which is of type List<Dropslog>
but I changed it as I read here that SOAP webservices cannot return lists.
Now the application on the client side calls the webmethod getDrops using this code:
public static Dropslog[] getDrops(webservice.Users user, int monsterID){
webservice.PvmWs service = new webservice.PvmWs();
webservice.ClientHandler port = service.getClientHandlerPort();
return port.getDrops(user, monsterID);
}
So from what you've seen this should work perfectly, however it does not, instead I get an incompatible type error tip on NetBeans marked on the return line of that last method:
incompatible types
required: Dropslog[]
found: List<Dropslog>
Surprisingly when I change it as NetBeans suggests it does compile and work. I was wondering why this happens and if its some sort of bug or somehow netbeans is using an old file to compile the code or if java does some sort of autocasting?
Upvotes: 0
Views: 321
Reputation: 42040
The default ouput type for an array in JAXB is a list.
From what I know,
List<T>
andArray
doesn't make any difference in JAXB. Internally, even you declare your WS operation like this:
public Shape[] echoShapes(Shape[] input)
JAXB will create a
List<Shape>
instance to hold the Unmarshal results, then useList.toArray()
to convert it into array type.
OTN Discussion Forums : Webservices ...Array or List ...
Upvotes: 1