JsonObjectclass
of Library json-lib-2.2.3(net.sf.json)
has two methods :
public void putAll( Map map )
AND
public void accumulateAll( Map map )
I have to put all map details in JSONObject.
Which method should i use and why(i.e What is the difference between the two) ?
From the javadoc on accumulate
:
Accumulate values under a key. It is similar to the element method except that if there is already an object stored under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already a JSONArray, then the new value is appended to it. In contrast, the replace method replaces the previous value.
From this, it seems that accumulateAll
would call accumulate
for all values in the map, i.e. values already in the object are not replaced, whereas putAll
might replace existing values.
Example:
You have an object like this: {"chars":"A"}
.
putAll
with a map containing "chars" -> "B"
would result in {"chars":"B"}
accumulateAll
with a map containing "chars" -> "B"
would result in {"chars":["A","B"]}