1

I use Jersey for WS. I have the following method:

@Path("...")
@POST
public Response updateConfigs(@Context HttpServletRequest request, ....
        ConfigurationItemList itemList) {
    ...
}

Where itemList is POST param. When I try to call this method with empty POST params, I get an exception:

[#|2012-10-12T14:08:52.623+0200|SEVERE|glassfish3.1.1|com.sun.jersey.spi.container.ContainerResponse|_ThreadID=25;_ThreadName=Thread-2;|The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.io.EOFException: No content to map to Object due to end of input
       at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
       at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
       at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
       ...
|#]

[#|2012-10-12T14:08:52.624+0200|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=25;_ThreadName=Thread-2;|StandardWrapperValve[...ApplicationConfig]: PWC1406: Servlet.service() for servlet ....ApplicationConfig threw exception
java.io.EOFException: No content to map to Object due to end of input
       at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
       at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
       at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
       at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
       ....
|#]
Anton Tsivarev
  • 851
  • 3
  • 12
  • 25

2 Answers2

1

The error you get

java.io.EOFException: No content to map to Object due to end of input

is what I would expect for an empty input. Since there is no JSON to consume, what do you expect JAX-RS to do?

Edit: In JAX-RS 2.0, validation will be included.

1

I suspect that the only possible workaround is to use your own JAX-RS data provider, which will properly handle incoming NULLs. See also: JAX-RS / Jersey how to customize error handling?

Community
  • 1
  • 1
yegor256
  • 93,933
  • 106
  • 409
  • 558