JsonParser reset nextToken() to beginning in ExceptionMapper of type JsonProcessingException

Viewed 24

Summary

How do I reset JsonParser's nextToken() back to the start and get the tokens anew? I can't find any promising methods for this.

Details

I am creating a custom ExceptionMapper of kind JsonProcessingException to handle a situation where some un-mappable JSON is POSTed to a Jersey endpoint. The nextToken() is already "finished" and I can't re-inspect the payload.

I need to do this because it is a health check payload that doesn't conform to the expected JSON structure of the usual API. The contents of the health check payload is not under our control. More context over here but, basically, we expect this:

{  
  "eventKey":"repo:refs_changed",
  "date":"2017-09-19T09:45:32+1000",
  ... other details but eventKey is necessary
}

but get this:

{"test": true}

If I can, in the ExceptionMapper of kind JsonProcessingException, just check for literally { "test": true } and return 200 OK otherwise the usual 400 error it would be handy.

0 Answers
Related