开发者

have a java web service return a Null Web Result

I have a Java web service that when no item is found I want a null object to be returned. Instead, I'm getting back an instance with all properties set to null. I can check for the item having a null property, but would prefer the item returned itself to be N开发者_如何学Pythonull.

@WebMethod
@WebResult(name="item")
public item findItem(
            @WebParam(name="Id") int Id){
  //...
  if(ItemNotFound(Id)){
    return null;
  }
}

On the client side, the wsItem is NOT null

item wsItem=ws.findItem(1);
if(wsItem==null){
  // this will not be hit
}

Checking the item property will work on the client side

item wsItem=ws.findItem(1);
    if(wsItem.Property1==null){
      // this will
    }


Based on the information you've given, I don't understand why you can't simply do

if(item.getProperties() == null)
    return null;

EDIT:
Okay, now that you've updated with more code, I have a better idea of what's going on. Can you set some breakpoints? Are you sure that ItemNotFound is returning true, and that you're actually reaching the return null line in your service code? Something extra-kooky would have to be going on for the client code to be responsible, since I don't see the new keyword anywhere in there.

EDIT 2:
I initially approached this as a pure Java problem, but based on your latest comment, that's not true. It was pointed out in the chat that this is probably has to do with your annotations, or some other kind of broader settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜