I know what this exception reports for me. Its a null return. But I want to pass a null object, and want to receive a null object. I dont want to check for null and create a empty object, its a waste of cpu resource, since null conveys what it has to, no data found. How can I allow JSON to send a null.
OR
Am I without options here, I need to create a dummy object and send it over the wire ?
SubscriberListRequest request = new
SubscriberListRequest((SubscriberListConcrete)element.getValue()) ;
SubscriberListResponse response ;
clientSession = sessionManager.getClientSession(identityHash) ;
clientSession.getSendQueue().sendRequest(request) ;
try {
response = (SubscriberListResponse)clientSession.waitAndGetResponse(request) ;
} catch (WaitedLongEnoughException e) {
return Response.serverError().build() ;
} catch (UnableToResolveResponseException e) {
return Response.serverError().build() ;
}
//
// Should I check for response.getSubscriberList() == null, create a new SubscriberList() and send it over the wire ?
//
return Response.ok(response.getSubscriberList()).build();
You can’t really pass
nullover the wire, so I suggest you use the Null Object pattern (http://en.wikipedia.org/wiki/Null_Object_pattern) and create a static empty array/list inSubscriberListResponsewhich will be returned fromSubscriberListResponse.getSubscriberList()in case of no results. Then you don’t have to check for null in your service, but ingetSubscriberListto make sure you always return a valid object.