Skip to content

Commit

Permalink
Resolve #9
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsorba committed Dec 28, 2015
1 parent 5fea54d commit 22771c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/main/java/org/piwik/java/tracking/PiwikJsonObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package org.piwik.java.tracking;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.json.Json;
Expand All @@ -22,7 +22,7 @@
* @author brettcsorba
*/
public class PiwikJsonObject{
Map<String, String> map = new HashMap<>();
Map<String, String> map = new LinkedHashMap<>();

/**
* Gets the custom value stored at this custom key.
Expand Down Expand Up @@ -77,11 +77,20 @@ public int size(){
* <br>
* {@code {"1": ["key1", "value1"], "2": ["key2": "value2"]} }<br>
* <br>
* could be produced. Note that there is no guarantee about the ordering of
* the produced JSON based. The following JSON is also valid and could also
* be produced:<br>
* would be produced. The produced JSON will be ordered according to the
* order the values were put in. Removing an object will cause the values
* to backfill accordingly.<br>
* <br>
* For example, if the following values were put into the object<br>
* <br>
* {@code ("key1", "value1")}, {@code ("key2", "value2")}, and {@code ("key3", "value3")}<br>
* <br>
* and {@code ("key2", "value2") } was then removed, then<br>
* <br>
* {@code {"1": ["key1", "value1"], "2": ["key3": "value3"]} }<br>
* <br>
* would be produced.
* <br>
* {@code {"1": ["key2", "value2"], "2": ["key1": "value1"]} }.
* @return the JSON string representation of this object
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public void testMethods(){
public void testToString(){
obj.put("key", "value");
obj.put("key2", "value2");
obj.put("key3", "value3");
obj.remove("key2");

assertEquals("{\"1\":[\"key2\",\"value2\"],\"2\":[\"key\",\"value\"]}", obj.toString());
assertEquals("{\"1\":[\"key\",\"value\"],\"2\":[\"key3\",\"value3\"]}", obj.toString());
}

}

0 comments on commit 22771c0

Please sign in to comment.