JSON output : not returning empty string but empty json array instead #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On QidoRS when there is no match for a request a empty body is returned which is a problem when client expect a JSON result.
An empty string is invalid JSON and breaks on most system, returning an empty array instead '[]' is correct JSON and is less error prone.
From json.org :
So a json message can't be just a string (empty or not) it can only be an object
{...}
or array[...]
( some system allows
null
as well).Example of system rejecting empty string as JSON :
JSON.parse()
consider an empty string as invalid JSON and throws errorExpected tokens are: [CURLYOPEN, SQUAREOPEN]
(Didn't test myself but qido-client is also most likely affected by this)
Now even if some implementation accept empty string as valid JSON it's safer to return an empty array.
About code change :
For XML output I kept the return of empty string by returning a
null
entity when no match are found (javax.ws.rs.core.Response.ResponseBuilder.entity(Object)
accepts null as argument).