This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Web Services and the fly likes Empty request body in REST service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Web Services
Bookmark "Empty request body in REST service" Watch "Empty request body in REST service" New topic

Empty request body in REST service

Sam Mc Kee

Joined: Aug 20, 2010
Posts: 3
I have a REST service that accepts JSON in the request body. The method is defined as follows:

In the body of the request is a list of JSON objects representing ShoppingListItem objects, and this works fine. However, I would expect it also to work if the request body is empty--that the items variable would simply be null. However I get a 500 error before it even reaches my service when I post a request with an empty body.

Is this behavior normal/expected?


Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

I guess you are using Jersey, and in that case Jersey won't be able to find the matching method to call.
As far as I know, this is expected but I would wait for some experts to shed some more lights here.

Thanks and Regards,
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

My answer was wrong and I guess I didn't read your post well.
I was thinking about the uri and not the POST message being blank.

As per the REST architecture, you will call POST only if you want to UPDATE the resource.
And in your case you are calling POST without any payload.
This is an interesting thing. Let me try this.
I agree. Here's the link:
subject: Empty request body in REST service
It's not a secret anymore!