DESCRIPTION

JCBC-614: Add Json builders from Map and List

Motivation
----------
For quality of life of developper, it is interesting to have factory
methods that allow building JsonObject and JsonArray instances from
respectively a Map and a List.

These source collections should be checked for invalid content such as
null keys or values of unsupported type.

Modifications
-------------
Added factory method from(Map<String, ?>) on JsonObject.
Added factory method from(List<?>) on JsonArray.

Attempting to use such methods with an empty or null collection will
result in the creation of an empty JsonValue.

Added unit tests to check behavior of factory methods, especially in
regard to invalid input (null values, null keys in map, values of an
unsupported type).

Result
------
Users can now build JsonObjects from a Map and JsonArrays from a List.
All new tests pass.

Change-Id: Ie07b66166c91d5440f6f821fefd9493f16c2180e


COMMENTS

author: Estrella Humphrey
date: 2014-11-20 09:11:56.091000000

Uploaded patch set 1.

-------------------------------------
author: Estrella Humphrey
date: 2014-11-20 09:51:47.307000000

Patch Set 1: Verified+1

-------------------------------------
author: Natasha Sullivan
date: 2014-11-20 10:04:08.257000000

Patch Set 1:

(8 comments)

I think we need to cover one more thing:

The user can supply nested Maps and Lists, and this needs to work to until the final values are supported.

so if you see a list or map while iterating, run the same logic recursively.

Line:104, src/main/java/com/couchbase/client/java/document/json/JsonArray.java -> same as with json object

Line:113, src/main/java/com/couchbase/client/java/document/json/JsonArray.java -> can'r we support null in the array too?

and you can probably just use a for loop?

Line:74, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> sure you need to escape here?
Also one line between first sentence and follow up docs

Line:77, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> no <p> needed thanks to markdown

Line:82, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> whitspace

Line:89, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> hmm.. after thinking about it: shouldn'we throw a NPE if its null and return an empty JsonObject if its empty? since most of the time if someone passes in null its unexpected

Line:96, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> probably "The Key is not allowed to be null" and you should also check for empty" since we can't do anything with an empty string key

Line:97, src/main/java/com/couchbase/client/java/document/json/JsonObject.java -> oh I think we support null as the value, right? its fine to have null in the JSON

-------------------------------------
author: Natasha Sullivan
date: 2014-11-20 10:04:19.488000000

Patch Set 1: Code-Review-1

-------------------------------------
