diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-12 20:56:25 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-12 20:56:25 +1200 |
commit | 401eb799f3294f219c2a806655d27a1c496bde0a (patch) | |
tree | 953476a4095d1bab9c2b30173851ccd0379ca8eb /src/org | |
parent | 807eb5398e5e9a6ab827a576cb94e904f509bda5 (diff) | |
download | trackermap-server-401eb799f3294f219c2a806655d27a1c496bde0a.tar.gz trackermap-server-401eb799f3294f219c2a806655d27a1c496bde0a.tar.bz2 trackermap-server-401eb799f3294f219c2a806655d27a1c496bde0a.zip |
Add JSON formatting method
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/model/ExtendedInfoFormatter.java | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/org/traccar/model/ExtendedInfoFormatter.java b/src/org/traccar/model/ExtendedInfoFormatter.java index 31aac7672..e7e0dead0 100644 --- a/src/org/traccar/model/ExtendedInfoFormatter.java +++ b/src/org/traccar/model/ExtendedInfoFormatter.java @@ -15,6 +15,7 @@ */ package org.traccar.model; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; @@ -42,9 +43,8 @@ public class ExtendedInfoFormatter { data.put(key, value); } } - - @Override - public String toString() { + + private String toXmlString() { StringBuilder result = new StringBuilder(); result.append("<").append(rootNode).append(">"); @@ -60,5 +60,34 @@ public class ExtendedInfoFormatter { return result.toString(); } + + private String toJsonString() { + StringBuilder result = new StringBuilder(); + + result.append("{"); + + Iterator<Map.Entry<String, Object> > i = data.entrySet().iterator(); + + while (i.hasNext()) { + Map.Entry<String, Object> entry = i.next(); + + result.append('"').append(entry.getKey()).append('"'); + result.append(':'); + result.append('"').append(entry.getValue()).append('"'); + + if (i.hasNext()) { + result.append(','); + } + } + + result.append("}"); + + return result.toString(); + } + + @Override + public String toString() { + return toXmlString(); + } } |