I am trying to add an API in my jersey server that will be able to handle POST requests. The API allows for null request body or a json input. However i am unable to set this up properly, since if i create a method like
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
interface Resource {
@POST
@Path("path")
Response create(InputObject object)
}
And hit this with curl without Content-Type and requestBody, it fails with an error like
javax.ws.rs.NotSupportedException: Cannot consume content type
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:380) ~[resteasy-jaxrs-3.0.10.Final.jar:?]
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:114) ~[resteasy-jaxrs-3.0.10.Final.jar:?]
It works if i am setting the content-type and passing a json. Any idea on how to make this work?
From my side i am going to see if i can use filters and interceptors to add an empty json and content-type header if they are missing. But it seems like too much work for a simple nullable input use-case. Hence wanted to check if the community has any answers for me.
Thanks