aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2016-01-10 16:43:48 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2016-01-23 10:52:45 -0500
commit56f8fff935baa4cec804807cfed3728d11c086ed (patch)
treea0d38c9db9ddf5c42b533b0c1a617da41d8b7a3f /src/main/java/eu
parent1e335d527b888963aa953542cfae866ade0d5867 (diff)
Implement toJSON on ServiceDiscoveryResult
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
index 853e75aac..ac4e8c47e 100644
--- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
+++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
@@ -9,6 +9,9 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
@@ -70,6 +73,19 @@ public class ServiceDiscoveryResult {
return r;
}
+
+ public JSONObject toJSON() {
+ try {
+ JSONObject o = new JSONObject();
+ o.put("category", this.getCategory());
+ o.put("type", this.getType());
+ o.put("lang", this.getLang());
+ o.put("name", this.getName());
+ return o;
+ } catch(JSONException e) {
+ return null;
+ }
+ }
}
protected final List<Identity> identities;
@@ -157,4 +173,22 @@ public class ServiceDiscoveryResult {
}
}
+ public JSONObject toJSON() {
+ try {
+ JSONObject o = new JSONObject();
+
+ JSONArray ids = new JSONArray();
+ for(Identity id : this.getIdentities()) {
+ ids.put(id.toJSON());
+ }
+ o.put("identites", ids);
+
+ o.put("features", new JSONArray(this.getFeatures()));
+
+ return o;
+ } catch(JSONException e) {
+ return null;
+ }
+ }
+
}