Skip to content

Commit 22771c0

Browse files
committed
Resolve matomo-org#9
1 parent 5fea54d commit 22771c0

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/main/java/org/piwik/java/tracking/PiwikJsonObject.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
package org.piwik.java.tracking;
88

9-
import java.util.HashMap;
9+
import java.util.LinkedHashMap;
1010
import java.util.Map;
1111
import java.util.Map.Entry;
1212
import javax.json.Json;
@@ -22,7 +22,7 @@
2222
* @author brettcsorba
2323
*/
2424
public class PiwikJsonObject{
25-
Map<String, String> map = new HashMap<>();
25+
Map<String, String> map = new LinkedHashMap<>();
2626

2727
/**
2828
* Gets the custom value stored at this custom key.
@@ -77,11 +77,20 @@ public int size(){
7777
* <br>
7878
* {@code {"1": ["key1", "value1"], "2": ["key2": "value2"]} }<br>
7979
* <br>
80-
* could be produced. Note that there is no guarantee about the ordering of
81-
* the produced JSON based. The following JSON is also valid and could also
82-
* be produced:<br>
80+
* would be produced. The produced JSON will be ordered according to the
81+
* order the values were put in. Removing an object will cause the values
82+
* to backfill accordingly.<br>
83+
* <br>
84+
* For example, if the following values were put into the object<br>
85+
* <br>
86+
* {@code ("key1", "value1")}, {@code ("key2", "value2")}, and {@code ("key3", "value3")}<br>
87+
* <br>
88+
* and {@code ("key2", "value2") } was then removed, then<br>
89+
* <br>
90+
* {@code {"1": ["key1", "value1"], "2": ["key3": "value3"]} }<br>
91+
* <br>
92+
* would be produced.
8393
* <br>
84-
* {@code {"1": ["key2", "value2"], "2": ["key1": "value1"]} }.
8594
* @return the JSON string representation of this object
8695
*/
8796
@Override

src/test/java/org/piwik/java/tracking/PiwikJsonObjectTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ public void testMethods(){
6767
public void testToString(){
6868
obj.put("key", "value");
6969
obj.put("key2", "value2");
70+
obj.put("key3", "value3");
71+
obj.remove("key2");
7072

71-
assertEquals("{\"1\":[\"key2\",\"value2\"],\"2\":[\"key\",\"value\"]}", obj.toString());
73+
assertEquals("{\"1\":[\"key\",\"value\"],\"2\":[\"key3\",\"value3\"]}", obj.toString());
7274
}
7375

7476
}

0 commit comments

Comments
 (0)