How to handle if JSON POST body is empty?

So, i have flow service and exposing it using Rest Resource with http POST method.
How to handle if the request have empty body , not a single string?
currently the webmethods return error like this


{
    "$errorDump": "com.wm.util.coder.InvalidDatatypeException: [ISC.0076.9012] Invalid state. JSON input stream does not start with the  \"{\" character.\r\n\tat com.wm.util.coder.IDataJSONCoder.decode(IDataJSONCoder.java:378)\r\n\tat com.wm.app.b2b.server.ContentHandler_JSON.getInputValues(ContentHandler_JSON.java:59)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler.getPostParams(HTTPInvokeHandler.java:623)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler.getContentForPostAndPut(HTTPInvokeHandler.java:611)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler._process(HTTPInvokeHandler.java:155)\r\n\tat com.wm.app.b2b.server.RESTHandlerV2.process(RESTHandlerV2.java:85)\r\n\tat com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:190)\r\n\tat com.wm.app.b2b.server.Dispatch.run(Dispatch.java:401)\r\n\tat com.wm.util.pool.PooledThread.run(PooledThread.java:134)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\n",
    "$errorInfo": {
        "$errorDump": "com.wm.util.coder.InvalidDatatypeException: [ISC.0076.9012] Invalid state. JSON input stream does not start with the  \"{\" character.\r\n\tat com.wm.util.coder.IDataJSONCoder.decode(IDataJSONCoder.java:378)\r\n\tat com.wm.app.b2b.server.ContentHandler_JSON.getInputValues(ContentHandler_JSON.java:59)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler.getPostParams(HTTPInvokeHandler.java:623)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler.getContentForPostAndPut(HTTPInvokeHandler.java:611)\r\n\tat com.wm.app.b2b.server.HTTPInvokeHandler._process(HTTPInvokeHandler.java:155)\r\n\tat com.wm.app.b2b.server.RESTHandlerV2.process(RESTHandlerV2.java:85)\r\n\tat com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:190)\r\n\tat com.wm.app.b2b.server.Dispatch.run(Dispatch.java:401)\r\n\tat com.wm.util.pool.PooledThread.run(PooledThread.java:134)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\n",
        "$error": "[ISC.0076.9012] Invalid state. JSON input stream does not start with the  \"{\" character.",
        "$localizedError": "[ISC.0076.9012] Invalid state. JSON input stream does not start with the  \"{\" character.",
        "$errorType": "com.wm.util.coder.InvalidDatatypeException",
        "$service": "apiSprintIS.services:new_flowservice",
        "$user": "52125",
        "$time": "Mon Mar 02 15:09:05 ICT 2020"
    },
    "$error": "[ISC.0076.9012] Invalid state. JSON input stream does not start with the  \"{\" character.",
    "$errorType": "com.wm.util.coder.InvalidDatatypeException"
}

Thankyou

Hello Alexander,

It is more usual for the GET method to be used when all the data is passed on the URL, however if the POST method is required by the client (as in this case), then there are 2 options:

  1. Tell the client to send an empty JSON string, i.e. {} in the HTTP body when using Content-Type=application/json)
  2. Tell the client to put ?jsonFormat=stream onto the URL. This will not parse the body but will put a null jsonStream object onto the pipeline - as it is null it can be ignored.

Please try it out.

Cheers!
RMG

It works ! the 2nd one is the best option for me.
Thankyou

Glad to hear it worked out for you!!

Cheers!
RMG