Implement toJSON on ServiceDiscoveryResult

This commit is contained in:
Stephen Paul Weber 2016-01-10 16:43:48 -05:00
parent 1e335d527b
commit 56f8fff935
1 changed files with 34 additions and 0 deletions

View File

@ -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;
}
}
}