[JSON_PROCESSING_SPEC-3] addArray methods in Builder Created: 21/May/12  Updated: 18/Jun/12  Resolved: 18/Jun/12

Status: Resolved
Project: json-processing-spec
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: jitu Assignee: jitu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Feedback on addArray methods: "API already has beginArray() for starting a new array, better to turn this into addAll(Iterable<JsonValue>) which would add all the elements of the iterable at the current point. That way addAll() can do double-duty both to bulk-add into the currently built array, or you can do .beginArray().addAll(iterable).endArray() to add a nested array."



 Comments   
Comment by jitu [ 21/May/12 ]

Proposed changes are:

Remove
JsonArrayBuilder#addArray(Iterable<JsonValue>)
JsonObjectBuilder#addArray(String, Iterable<JsonValue>)

and add
JsonArrayBuilder#addAll(Iterable<JsonValue>)

Comment by illsleydc [ 26/May/12 ]

I definitely agree with the need for an addAll to JsonArrayBuilder, but I think it's worth exploring further and adding a few... (I don't know where a developer would normally be getting the Iterable<JsonValue> from?)

addAll(Iterable<String>), addAll(Iterable<Integer>), addAll(Iterable<Double>)

The obvious inefficiency here is for people with int[] or double[]. For them, addAll(int...) etc would be better. That could get to be a lot of methods, but with consistent naming, it might not feel too overwhelming.

Comment by jitu [ 14/Jun/12 ]

> I definitely agree with the need for an addAll to JsonArrayBuilder, but I think it's worth exploring further and adding a few... (I don't know where a developer would normally be getting the Iterable<JsonValue> from?)

The developer may get Iterable<JsonValue> from an existing JsonArray, say JsonArray#getValues().

>addAll(Iterable<String>), addAll(Iterable<Integer>), addAll(Iterable<Double>)
>The obvious inefficiency here is for people with int[] or double[]. For them, addAll(int...) etc would be better. That could get to be a lot of methods, but with consistent naming, it might not feel too overwhelming.

We already have methods to add one JsonValue, int, String etc. Perhaps, we just remove the current addArray() methods and not add any new addAll methods. A developer can add them using the existing methods in a loop. If the addAll methods really needed, we can add them later.

Comment by jitu [ 18/Jun/12 ]

Removing the addArray methods on the builders.

Generated at Sun Apr 23 10:26:22 UTC 2017 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.