mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
Implement toJSON on ServiceDiscoveryResult
This commit is contained in:
parent
1e335d527b
commit
56f8fff935
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user