vert-x/vert.x — pull request #679 by pmlopes (2013-07-05 09:53:01+00:00)
Title: Simplify the JSON api to check for "undefined" values in Java

Once a JSON document is parsed into a JsonObject instance and there is a need to verify if a field is present, one with the current API needs to do:

boolean exists = jsonObject.getFieldNames().contains(someFieldName);

while it could be easier with the updated code:

boolean exists = jsonObject.contains(someFieldName);

It is not a deal breaker the longer API however since verifying if a field is present is a common task in JSON (because there is no fixed schema to force the structure of the document) it just makes the readability of the code easier.

Also the idea of the extra method is to avoid wrong checks like:

jsonObject.getField(someFieldName) != null

which is wrong since null is a valid json value and can be present. e.g.:

{key: 'a', value: null}

using the last check is not valid to say that the "value" field is not present.

I've signed the Eclipse CLA.