Search in sources :

Example 16 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class DDLCompiler method convertToJSONObject.

private static String convertToJSONObject(AbstractExpression expr) throws JSONException {
    JSONStringer stringer = new JSONStringer();
    stringer.object();
    expr.toJSONString(stringer);
    stringer.endObject();
    return stringer.toString();
}
Also used : JSONStringer(org.json_voltpatches.JSONStringer)

Example 17 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class DDLCompiler method convertToJSONArray.

protected static String convertToJSONArray(List<AbstractExpression> exprs) throws JSONException {
    JSONStringer stringer = new JSONStringer();
    stringer.array();
    for (AbstractExpression abstractExpression : exprs) {
        stringer.object();
        abstractExpression.toJSONString(stringer);
        stringer.endObject();
    }
    stringer.endArray();
    return stringer.toString();
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) JSONStringer(org.json_voltpatches.JSONStringer)

Example 18 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class InstanceId method serializeToJSONObject.

public JSONObject serializeToJSONObject() throws JSONException {
    JSONStringer stringer = new JSONStringer();
    stringer.object();
    stringer.keySymbolValuePair("coord", m_coord);
    stringer.keySymbolValuePair("timestamp", m_timestamp);
    stringer.endObject();
    return new JSONObject(stringer.toString());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONStringer(org.json_voltpatches.JSONStringer)

Example 19 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class AbstractTopology method topologyToJSON.

/////////////////////////////////////
//
// SERIALIZATION API
//
/////////////////////////////////////
public JSONObject topologyToJSON() throws JSONException {
    JSONStringer stringer = new JSONStringer();
    stringer.object();
    stringer.keySymbolValuePair(TOPO_VERSION, version);
    stringer.key(TOPO_HAGROUPS).array();
    List<HAGroup> haGroups = hostsById.values().stream().map(h -> h.haGroup).distinct().collect(Collectors.toList());
    for (HAGroup haGroup : haGroups) {
        haGroup.toJSON(stringer);
    }
    stringer.endArray();
    stringer.key(TOPO_PARTITIONS).array();
    for (Partition partition : partitionsById.values()) {
        partition.toJSON(stringer);
    }
    stringer.endArray();
    stringer.key(TOPO_HOSTS).array();
    for (Host host : hostsById.values()) {
        host.toJSON(stringer);
    }
    stringer.endArray();
    stringer.endObject();
    return new JSONObject(stringer.toString());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONStringer(org.json_voltpatches.JSONStringer)

Example 20 with JSONStringer

use of org.json_voltpatches.JSONStringer in project voltdb by VoltDB.

the class SerializableException method toJSONString.

@Override
public String toJSONString() {
    try {
        JSONStringer js = new JSONStringer();
        js.object();
        js.keySymbolValuePair("type", getExceptionType().ordinal());
        js.keySymbolValuePair("message", m_message);
        js.endObject();
        return js.toString();
    } catch (Exception e) {
        return "{ error: \"Unable to serialize exception.\" }";
    }
}
Also used : JSONStringer(org.json_voltpatches.JSONStringer) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

JSONStringer (org.json_voltpatches.JSONStringer)28 JSONException (org.json_voltpatches.JSONException)18 JSONObject (org.json_voltpatches.JSONObject)7 ExecutionException (java.util.concurrent.ExecutionException)6 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)6 IOException (java.io.IOException)5 Map (java.util.Map)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SocketException (java.net.SocketException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 AbstractExpression (org.voltdb.expressions.AbstractExpression)2 SettingsException (org.voltdb.settings.SettingsException)2 ImmutableSortedMap (com.google_voltpatches.common.collect.ImmutableSortedMap)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1