Java 类org.json.JSONStringer 实例源码

项目:sstore-soft    文件:MarkovVertex.java   
/**
 * Implementation of the toJSONString method for an AbstractVertex
 */
public void toJSONStringImpl(JSONStringer stringer) throws JSONException {
    super.toJSONStringImpl(stringer);

    Set<Members> members_set = CollectionUtil.getAllExcluding(Members.values(), Members.PROBABILITIES);
    Members members[] = new Members[members_set.size()];
    members_set.toArray(members);
    super.fieldsToJSONString(stringer, MarkovVertex.class, members);

    // Probabilities Map
    stringer.key(Members.PROBABILITIES.name()).object();
    for (Probability type : Probability.values()) {
        stringer.key(type.name()).array();
        int i = type.ordinal();
        for (int j = 0, cnt = this.probabilities[i].length; j < cnt; j++) {
            stringer.value(this.probabilities[i][j]);
        } // FOR
        stringer.endArray();
    } // FOR
    stringer.endObject();
}
项目:s-store    文件:AbstractPlanNode.java   
@Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try
        {
            stringer.object();
            toJSONString(stringer);
            stringer.endObject();
        }
        catch (JSONException e)
        {
            throw new RuntimeException("Failed to serialize " + this, e);
//            System.exit(-1);
        }
        return stringer.toString();
    }
项目:sstore-soft    文件:JSONUtil.java   
/**
 * @param <T>
 * @param object
 * @return
 */
public static String toJSONString(Object object) {
    JSONStringer stringer = new JSONStringer();
    try {
        if (object instanceof JSONSerializable) {
            stringer.object();
            ((JSONSerializable) object).toJSON(stringer);
            stringer.endObject();
        } else if (object != null) {
            Class<?> clazz = object.getClass();
            // stringer.key(clazz.getSimpleName());
            JSONUtil.writeFieldValue(stringer, clazz, object);
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return (stringer.toString());
}
项目:s-store    文件:DesignerHints.java   
/**
 * Load with the ability to override values
 */
public void load(File input_path, Database catalog_db, Map<String, String> override) throws IOException {
    // First call the regular load() method to bring all of our options
    this.load(input_path, catalog_db);

    // Then construct a JSONObject from the map to override the parameters
    if (override.isEmpty() == false) {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            for (Entry<String, String> e : override.entrySet()) {
                stringer.key(e.getKey().toUpperCase()).value(e.getValue());
            } // FOR
            stringer.endObject();
            this.fromJSON(new JSONObject(stringer.toString()), catalog_db);
        } catch (JSONException ex) {
            throw new IOException("Failed to load override parameters: " + override, ex);
        }
    }
}
项目:nucleus-test    文件:UserConverte.java   
public String toJSON(List<User> users) throws JSONException {
    try{
        JSONStringer jsonStringer = new JSONStringer();
        jsonStringer.object().key("lista").array().object().key("user").array();
        for (User user:users){
            jsonStringer.object();
            jsonStringer.key("cpf").value(user.getCpf());
            jsonStringer.key("name").value(user.getName());
            jsonStringer.key("phone").value(user.getPhone());
            jsonStringer.key("email").value(user.getEmail());
            jsonStringer.key("company").value(user.getCompany());
            jsonStringer.key("birthdate").value(user.getBirthdate());
            jsonStringer.key("url").value(user.getUrl());
            jsonStringer.key("location").value(user.getLocation());
            jsonStringer.key("photo").value(user.getPhoto());
            jsonStringer.endObject();
        }
        jsonStringer.endArray().endObject().endArray().endObject();
        return jsonStringer.toString();
    } catch (JSONException e){
        return null;
    }
}
项目:sstore-soft    文件:DesignerHints.java   
/**
 * Load with the ability to override values
 */
public void load(File input_path, Database catalog_db, Map<String, String> override) throws IOException {
    // First call the regular load() method to bring all of our options
    this.load(input_path, catalog_db);

    // Then construct a JSONObject from the map to override the parameters
    if (override.isEmpty() == false) {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            for (Entry<String, String> e : override.entrySet()) {
                stringer.key(e.getKey().toUpperCase()).value(e.getValue());
            } // FOR
            stringer.endObject();
            this.fromJSON(new JSONObject(stringer.toString()), catalog_db);
        } catch (JSONException ex) {
            throw new IOException("Failed to load override parameters: " + override, ex);
        }
    }
}
项目:nucleus-test    文件:UserConverte.java   
public String toJSON(List<User> users) throws JSONException {
    try{
        JSONStringer jsonStringer = new JSONStringer();
        jsonStringer.object().key("lista").array().object().key("user").array();
        for (User user:users){
            jsonStringer.object();
            jsonStringer.key("cpf").value(user.getCpf());
            jsonStringer.key("name").value(user.getName());
            jsonStringer.key("phone").value(user.getPhone());
            jsonStringer.key("email").value(user.getEmail());
            jsonStringer.key("company").value(user.getCompany());
            jsonStringer.key("birthdate").value(user.getBirthdate());
            jsonStringer.key("url").value(user.getUrl());
            jsonStringer.key("location").value(user.getLocation());
            jsonStringer.key("photo").value(user.getPhoto());
            jsonStringer.endObject();
        }
        jsonStringer.endArray().endObject().endArray().endObject();
        return jsonStringer.toString();
    } catch (JSONException e){
        return null;
    }
}
项目:s-store    文件:IndexScanPlanNode.java   
@Override
public void toJSONString(JSONStringer stringer) throws JSONException {
    super.toJSONString(stringer);
    stringer.key(Members.KEY_ITERATE.name()).value(m_keyIterate);
    stringer.key(Members.LOOKUP_TYPE.name()).value(m_lookupType.toString());
    stringer.key(Members.SORT_DIRECTION.name()).value(m_sortDirection.toString());
    stringer.key(Members.TARGET_INDEX_NAME.name()).value(m_targetIndexName);
    stringer.key(Members.END_EXPRESSION.name());
    stringer.value(m_endExpression);

    stringer.key(Members.SEARCHKEY_EXPRESSIONS.name()).array();
    for (AbstractExpression ae : m_searchkeyExpressions) {
        assert (ae instanceof JSONString);
        stringer.value(ae);
    }
    stringer.endArray();
}
项目:s-store    文件:FastIntHistogram.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {

    // Go through once and find the greatest position where
    // there are no more non-null values
    int maxSize = 0;
    for (int i = 0; i < this.histogram.length; i++) {
        if (this.histogram[i] != NULL_COUNT) {
            maxSize = i;
        }
    } // FOR
    stringer.key(Members.HISTOGRAM.name()).array();
    for (int i = 0; i <= maxSize; i++) {
        stringer.value(this.histogram[i]);
    } // FOR
    stringer.endArray();

    if (this.debug_names != null && this.debug_names.isEmpty() == false) {
        stringer.key(Members.DEBUG.name()).object();
        for (Entry<Object, String> e : this.debug_names.entrySet()) {
            stringer.key(e.getKey().toString())
                    .value(e.getValue().toString());
        } // FOR
        stringer.endObject();
    }
}
项目:boohee_v5.6    文件:AddCardToWXCardPackage.java   
public void toBundle(Bundle bundle) {
    super.toBundle(bundle);
    JSONStringer jSONStringer = new JSONStringer();
    try {
        jSONStringer.object();
        jSONStringer.key("card_list");
        jSONStringer.array();
        for (WXCardItem wXCardItem : this.cardArrary) {
            jSONStringer.object();
            jSONStringer.key("card_id");
            jSONStringer.value(wXCardItem.cardId);
            jSONStringer.key("card_ext");
            jSONStringer.value(wXCardItem.cardExtMsg == null ? "" : wXCardItem.cardExtMsg);
            jSONStringer.endObject();
        }
        jSONStringer.endArray();
        jSONStringer.endObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    bundle.putString("_wxapi_add_card_to_wx_card_list", jSONStringer.toString());
}
项目:sstore-soft    文件:IndexScanPlanNode.java   
@Override
public void toJSONString(JSONStringer stringer) throws JSONException {
    super.toJSONString(stringer);
    stringer.key(Members.KEY_ITERATE.name()).value(m_keyIterate);
    stringer.key(Members.LOOKUP_TYPE.name()).value(m_lookupType.toString());
    stringer.key(Members.SORT_DIRECTION.name()).value(m_sortDirection.toString());
    stringer.key(Members.TARGET_INDEX_NAME.name()).value(m_targetIndexName);
    stringer.key(Members.END_EXPRESSION.name());
    stringer.value(m_endExpression);

    stringer.key(Members.SEARCHKEY_EXPRESSIONS.name()).array();
    for (AbstractExpression ae : m_searchkeyExpressions) {
        assert (ae instanceof JSONString);
        stringer.value(ae);
    }
    stringer.endArray();
}
项目:sstore-soft    文件:PlanNodeList.java   
@Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            super.toJSONString(stringer);

            stringer.key(Members.EXECUTE_LIST.name()).array();
            for (AbstractPlanNode node : m_list) {
                stringer.value(node.getPlanNodeId().intValue());
            }
            stringer.endArray(); //end execution list

            stringer.endObject(); //end PlanNodeList
        } catch (JSONException e) {
            // HACK ugly ugly to make the JSON handling
            // in QueryPlanner generate a JSONException for a plan we know
            // here that we can't serialize.  Making this method throw
            // JSONException pushes that exception deep into the bowels of
            // Volt with no good place to catch it and handle the error.
            // Consider this the coward's way out.
            throw new RuntimeException("Failed to serialize PlanNodeList", e);
//            return "This JSON error message is a lie";
        }
        return stringer.toString();
    }
项目:s-store    文件:PlanNodeList.java   
@Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            super.toJSONString(stringer);

            stringer.key(Members.EXECUTE_LIST.name()).array();
            for (AbstractPlanNode node : m_list) {
                stringer.value(node.getPlanNodeId().intValue());
            }
            stringer.endArray(); //end execution list

            stringer.endObject(); //end PlanNodeList
        } catch (JSONException e) {
            // HACK ugly ugly to make the JSON handling
            // in QueryPlanner generate a JSONException for a plan we know
            // here that we can't serialize.  Making this method throw
            // JSONException pushes that exception deep into the bowels of
            // Volt with no good place to catch it and handle the error.
            // Consider this the coward's way out.
            throw new RuntimeException("Failed to serialize PlanNodeList", e);
//            return "This JSON error message is a lie";
        }
        return stringer.toString();
    }
项目:boohee_v5.6    文件:AddCardToWXCardPackage.java   
public void toBundle(Bundle bundle) {
    super.toBundle(bundle);
    JSONStringer jSONStringer = new JSONStringer();
    try {
        jSONStringer.object();
        jSONStringer.key("card_list");
        jSONStringer.array();
        for (WXCardItem wXCardItem : this.cardArrary) {
            jSONStringer.object();
            jSONStringer.key("card_id");
            jSONStringer.value(wXCardItem.cardId);
            jSONStringer.key("card_ext");
            jSONStringer.value(wXCardItem.cardExtMsg == null ? "" : wXCardItem.cardExtMsg);
            jSONStringer.key("is_succ");
            jSONStringer.value((long) wXCardItem.cardState);
            jSONStringer.endObject();
        }
        jSONStringer.endArray();
        jSONStringer.endObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    bundle.putString("_wxapi_add_card_to_wx_card_list", jSONStringer.toString());
}
项目:sstore-soft    文件:BenchmarkComponentResults.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {
    String exclude[] = {
        (this.enableBasePartitions == false ? "basePartitions" : ""),
        (this.enableResponseStatuses == false ? "responseStatuses" : ""),
    };

    // HACK
    this.specexecs.setDebugLabels(null);
    this.dtxns.setDebugLabels(null);

    Field fields[] = JSONUtil.getSerializableFields(this.getClass(), exclude);
    JSONUtil.fieldsToJSON(stringer, this, BenchmarkComponentResults.class, fields);

    this.specexecs.setDebugLabels(this.transactions.getDebugLabels());
    this.dtxns.setDebugLabels(this.transactions.getDebugLabels());
}
项目:s-store    文件:MarkovVertex.java   
/**
 * Implementation of the toJSONString method for an AbstractVertex
 */
public void toJSONStringImpl(JSONStringer stringer) throws JSONException {
    super.toJSONStringImpl(stringer);

    Set<Members> members_set = CollectionUtil.getAllExcluding(Members.values(), Members.PROBABILITIES);
    Members members[] = new Members[members_set.size()];
    members_set.toArray(members);
    super.fieldsToJSONString(stringer, MarkovVertex.class, members);

    // Probabilities Map
    stringer.key(Members.PROBABILITIES.name()).object();
    for (Probability type : Probability.values()) {
        stringer.key(type.name()).array();
        int i = type.ordinal();
        for (int j = 0, cnt = this.probabilities[i].length; j < cnt; j++) {
            stringer.value(this.probabilities[i][j]);
        } // FOR
        stringer.endArray();
    } // FOR
    stringer.endObject();
}
项目:s-store    文件:CatalogKey.java   
/**
 * Returns a String key representation of the column as "Parent.Child"
 * 
 * @param catalog_col
 * @return
 */
public static <T extends CatalogType> String createKey(T catalog_item) {
    // There is a 7x speed-up when we use the cache versus always
    // constructing a new key
    String ret = CACHE_CREATEKEY.get(catalog_item);
    if (ret != null)
        return (ret);
    if (catalog_item == null)
        return (null);

    JSONStringer stringer = new JSONStringer();
    try {
        createKey(catalog_item, stringer);
        // IMPORTANT: We have to convert all double quotes to single-quotes
        // so that
        // the keys don't get escaped when stored in other JSON objects
        ret = stringer.toString().replace("\"", "'");
        CACHE_CREATEKEY.put(catalog_item, ret);
    } catch (JSONException ex) {
        throw new RuntimeException("Failed to create catalog key for " + catalog_item, ex);
    }
    return (ret);
}
项目:Blockly    文件:BlocklyEvent.java   
public String toJsonString() throws JSONException {
    JSONStringer out = new JSONStringer();
    out.object();
    out.key(JSON_TYPE);
    out.value(getTypeName());
    if (!TextUtils.isEmpty(mBlockId)) {
        out.key(JSON_BLOCK_ID);
        out.value(mBlockId);
    }
    if (!TextUtils.isEmpty(mGroupId)) {
        out.key(JSON_GROUP_ID);
        out.value(mGroupId);
    }
    writeJsonAttributes(out);
    // Workspace id is not included to reduce size over network.
    out.endObject();
    return out.toString();
}
项目:s-store    文件:JSONUtil.java   
/**
 * @param <T>
 * @param object
 * @return
 */
public static String toJSONString(Object object) {
    JSONStringer stringer = new JSONStringer();
    try {
        if (object instanceof JSONSerializable) {
            stringer.object();
            ((JSONSerializable) object).toJSON(stringer);
            stringer.endObject();
        } else if (object != null) {
            Class<?> clazz = object.getClass();
            // stringer.key(clazz.getSimpleName());
            JSONUtil.writeFieldValue(stringer, clazz, object);
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return (stringer.toString());
}
项目:Logistics-guard    文件:TestActivity3.java   
@Override
protected void onPostExecute(JSONStringer strCardInfo) {
    if (strCardInfo != null) {
        displayIdInfo(strCardInfo);
    }
    super.onPostExecute(strCardInfo);
}
项目:LaunchEnr    文件:InstallShortcutReceiver.java   
String encodeToString() {
    try {
        if (activityInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                .object()
                .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                .key(APP_SHORTCUT_TYPE_KEY).value(true)
                .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                        .getSerialNumberForUser(user))
                .endObject().toString();
        } else if (shortcutInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                    .object()
                    .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                    .key(DEEPSHORTCUT_TYPE_KEY).value(true)
                    .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                            .getSerialNumberForUser(user))
                    .endObject().toString();
        } else if (providerInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                    .object()
                    .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                    .key(APP_WIDGET_TYPE_KEY).value(true)
                    .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                            .getSerialNumberForUser(user))
                    .endObject().toString();
        }

        if (launchIntent.getAction() == null) {
            launchIntent.setAction(Intent.ACTION_VIEW);
        } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) &&
                launchIntent.getCategories() != null &&
                launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
            launchIntent.addFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        }

        // This name is only used for comparisons and notifications, so fall back to activity
        // name if not supplied
        String name = ensureValidName(mContext, launchIntent, label).toString();
        Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
        Intent.ShortcutIconResource iconResource =
            data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

        // Only encode the parameters which are supported by the API.
        JSONStringer json = new JSONStringer()
            .object()
            .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
            .key(NAME_KEY).value(name);
        if (icon != null) {
            byte[] iconByteArray = Utilities.flattenBitmap(icon);
            json = json.key(ICON_KEY).value(
                    Base64.encodeToString(
                            iconByteArray, 0, iconByteArray.length, Base64.DEFAULT));
        }
        if (iconResource != null) {
            json = json.key(ICON_RESOURCE_NAME_KEY).value(iconResource.resourceName);
            json = json.key(ICON_RESOURCE_PACKAGE_NAME_KEY)
                    .value(iconResource.packageName);
        }
        return json.endObject().toString();
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
项目:sstore-soft    文件:MarkovGraphsContainer.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {
    // CLASSNAME
    stringer.key(Members.CLASSNAME.name()).value(this.getClass().getCanonicalName());

    // MARKOV GRAPHS
    stringer.key(Members.MARKOVS.name()).object();
    for (Integer id : this.markovs.keySet()) {
        // Roll through each id and create a new JSONObject per id
        if (debug.val)
            LOG.debug("Serializing " + this.markovs.get(id).size() + " graphs for id " + id);
        stringer.key(id.toString()).object();
        for (Entry<Procedure, MarkovGraph> e : this.markovs.get(id).entrySet()) {
            // Optimization: Hex-encode all of the MarkovGraphs so that we don't get crushed
            // when trying to read them all back at once when we create the JSONObject
            try {
                FastSerializer fs = new FastSerializer(false, false); // C++ needs little-endian
                fs.write(e.getValue().toJSONString().getBytes());
                String hexString = fs.getHexEncodedBytes();
                stringer.key(CatalogKey.createKey(e.getKey())).value(hexString);
            } catch (Exception ex) {
                String msg = String.format("Failed to serialize %s MarkovGraph for Id %d", e.getKey(), id);
                LOG.fatal(msg);
                throw new JSONException(ex);
            }
        } // FOR
        stringer.endObject();
    } // FOR
    stringer.endObject();
}
项目:s-store    文件:PartitionSet.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {
    stringer.key("P").array();
    for (Integer partition : this) {
        stringer.value(partition);
    } // FOR
    stringer.endArray();
}
项目:AutoInteraction-Library    文件:Util.java   
/**
 * @param key
 * @param value
 * @return
 * @throws
 * @Title: createJsonString
 * @Description: 生成json字符串
 * @return: String
 */
public static String createJsonString(String key, JSONArray value) {
    JSONStringer jsonStringer = new JSONStringer();
    try {
        jsonStringer.object().key(key).value(value).endObject();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return jsonStringer.toString();
}
项目:s-store    文件:AbstractExpression.java   
public String toJSONString() {
    JSONStringer stringer = new JSONStringer();
    try {
    stringer.object();
    toJSONString(stringer);
    stringer.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
    return stringer.toString();
}
项目:quorrabot    文件:SoundBoard.java   
private void doDBDecr(WebSocket webSocket, String id, String table, String key, String value) {
    JSONStringer jsonObject = new JSONStringer();
    try {
        Quorrabot.instance().getDataStore().decr(table, key, Integer.parseInt(value));
    } catch (NullPointerException ex) {
        if (!dbCallNull) {
            debugMsg("NULL returned from DB. DB Object not created yet.");
        }
        return;
    }
    jsonObject.object().key("query_id").value(id).endObject();
    webSocket.send(jsonObject.toString());
}
项目:sstore-soft    文件:JSONUtil.java   
/**
 * JSON Pretty Print
 * 
 * @param <T>
 * @param object
 * @return
 */
public static <T extends JSONSerializable> String format(T object) {
    JSONStringer stringer = new JSONStringer();
    try {
        if (object instanceof JSONObject)
            return ((JSONObject) object).toString(2);
        stringer.object();
        object.toJSON(stringer);
        stringer.endObject();
    } catch (JSONException ex) {
        throw new RuntimeException(ex);
    }
    return (JSONUtil.format(stringer.toString()));
}
项目:sstore-soft    文件:JSONUtil.java   
/**
 * For a given list of Fields, write out the contents of the corresponding
 * field to the JSONObject The each of the JSONObject's elements will be the
 * upper case version of the Field's name
 * 
 * @param <T>
 * @param stringer
 * @param object
 * @param base_class
 * @param fields
 * @throws JSONException
 */
public static <T> void fieldsToJSON(JSONStringer stringer, T object, Class<? extends T> base_class, Field fields[]) throws JSONException {
    if (debug.val)
        LOG.debug("Serializing out " + fields.length + " elements for " + base_class.getSimpleName());
    for (Field f : fields) {
        String json_key = f.getName().toUpperCase();
        stringer.key(json_key);

        try {
            Class<?> f_class = f.getType();
            Object f_value = f.get(object);

            // Null
            if (f_value == null) {
                writeFieldValue(stringer, f_class, f_value);
                // Maps
            } else if (f_value instanceof Map) {
                writeFieldValue(stringer, f_class, f_value);
                // Everything else
            } else {
                writeFieldValue(stringer, f_class, f_value);
                addClassForField(stringer, json_key, f_class, f_value);
            }
        } catch (Exception ex) {
            throw new JSONException(ex);
        }
    } // FOR
}
项目:s-store    文件:JSONUtil.java   
/**
 * For a given list of Fields, write out the contents of the corresponding
 * field to the JSONObject The each of the JSONObject's elements will be the
 * upper case version of the Field's name
 * 
 * @param <T>
 * @param stringer
 * @param object
 * @param base_class
 * @param fields
 * @throws JSONException
 */
public static <T> void fieldsToJSON(JSONStringer stringer, T object, Class<? extends T> base_class, Field fields[]) throws JSONException {
    if (debug.val)
        LOG.debug("Serializing out " + fields.length + " elements for " + base_class.getSimpleName());
    for (Field f : fields) {
        String json_key = f.getName().toUpperCase();
        stringer.key(json_key);

        try {
            Class<?> f_class = f.getType();
            Object f_value = f.get(object);

            // Null
            if (f_value == null) {
                writeFieldValue(stringer, f_class, f_value);
                // Maps
            } else if (f_value instanceof Map) {
                writeFieldValue(stringer, f_class, f_value);
                // Everything else
            } else {
                writeFieldValue(stringer, f_class, f_value);
                addClassForField(stringer, json_key, f_class, f_value);
            }
        } catch (Exception ex) {
            throw new JSONException(ex);
        }
    } // FOR
}
项目:s-store    文件:ObjectHistogram.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {
    for (Members element : ObjectHistogram.Members.values()) {
        try {
            Field field = ObjectHistogram.class.getDeclaredField(element.toString().toLowerCase());
            switch (element) {
                case HISTOGRAM: {
                    if (this.histogram.isEmpty() == false) {
                        stringer.key(element.name()).object();
                        synchronized (this) {
                            for (Object value : this.histogram.keySet()) {
                                stringer.key(value.toString())
                                        .value(this.histogram.get(value));
                            } // FOR
                        } // SYNCH
                        stringer.endObject();
                    }
                    break;
                }
                case KEEP_ZERO_ENTRIES: {
                    if (this.keep_zero_entries) {
                        stringer.key(element.name())
                                .value(this.keep_zero_entries);
                    }
                    break;
                }
                case VALUE_TYPE: {
                    VoltType vtype = (VoltType)field.get(this); 
                    stringer.key(element.name()).value(vtype.name());
                    break;
                }
                default:
                    stringer.key(element.name())
                            .value(field.get(this));
            } // SWITCH
        } catch (Exception ex) {
            throw new RuntimeException("Failed to serialize '" + element + "'", ex);
        }
    } // FOR
}
项目:sstore-soft    文件:ParameterMappingsSet.java   
public void toJSON(JSONStringer stringer) throws JSONException {
    stringer.key("MAPPINGS").array();
    for (ParameterMapping c : this) {
        assert(c != null);
        stringer.value(c);   
    } // FOR
    stringer.endArray();
}
项目:s-store    文件:ColumnStatistics.java   
@Override
public void toJSONString(JSONStringer stringer) throws JSONException {
    // Read-only
    stringer.key(Members.READONLY.name()).value(this.readonly);

    // Histogram
    stringer.key(Members.HISTOGRAM.name()).object();
    this.histogram.toJSON(stringer);
    stringer.endObject();
}
项目:sstore-soft    文件:ProfileMeasurement.java   
@Override
public void toJSON(JSONStringer stringer) throws JSONException {
    stringer.key("NAME").value(this.name);
    stringer.key("TIME").value(this.total_time);
    stringer.key("INVOCATIONS").value(this.invocations);
    if (this.history != null) {
        stringer.key("HISTORY").array();
        for (long val : this.history) {
            stringer.value(val);
        } // FOR
        stringer.endArray();
    }
}
项目:sstore-soft    文件:TransactionTrace.java   
public void toJSONString(JSONStringer stringer, Database catalog_db) throws JSONException {
    super.toJSONString(stringer, catalog_db);
    stringer.key(Members.TXN_ID.name()).value(this.txn_id);

    stringer.key(Members.QUERIES.name()).array();
    for (QueryTrace query : this.queries) {
        stringer.object();
        query.toJSONString(stringer, catalog_db);
        stringer.endObject();
    } // FOR
    stringer.endArray();
}
项目:s-store    文件:ParameterMappingsSet.java   
public void toJSON(JSONStringer stringer) throws JSONException {
    stringer.key("MAPPINGS").array();
    for (ParameterMapping c : this) {
        assert(c != null);
        stringer.value(c);   
    } // FOR
    stringer.endArray();
}
项目:sstore-soft    文件:SiteEntry.java   
public void toJSONString(JSONStringer stringer) throws JSONException {
    stringer.key(Members.ID.name()).value(this.id);
    stringer.key(Members.HOST.name()).value(this.host_key);

    stringer.key(Members.FRAGMENTS.name()).array();
    for (FragmentEntry fragment : this.fragments) {
        stringer.object();
        fragment.toJSONString(stringer);
        stringer.endObject();
    }
    stringer.endArray();
}
项目:s-store    文件:TupleValueExpression.java   
@Override
public void toJSONString(JSONStringer stringer) throws JSONException {
    super.toJSONString(stringer);
    stringer.key(Members.COLUMN_IDX.name()).value(m_columnIndex);
    stringer.key(Members.TABLE_NAME.name()).value(m_tableName);
    stringer.key(Members.COLUMN_NAME.name()).value(m_columnName);
    stringer.key(Members.COLUMN_ALIAS.name()).value(m_columnAlias);
}
项目:sstore-soft    文件:FragmentEntry.java   
/**
 * 
 */
@Override
public String toJSONString() {
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        this.toJSONString(stringer);
        stringer.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return stringer.toString();
}
项目:s-store    文件:PlanNodeTree.java   
public void toJSONString(JSONStringer stringer) throws JSONException {
    stringer.key(Members.PLAN_NODES.name()).array();
    for (AbstractPlanNode node : m_planNodes) {
        assert (node instanceof JSONString);
        stringer.value(node);
    }
    stringer.endArray(); // end entries

    stringer.key(Members.PARAMETERS.name()).array();
    for (Pair<Integer, VoltType> parameter : m_parameters) {
        stringer.array().value(parameter.getFirst()).value(parameter.getSecond().name()).endArray();
    }
    stringer.endArray();
}
项目:sstore-soft    文件:AbstractStatistics.java   
/**
 * 
 */
@Override
public String toJSONString() {
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        this.toJSONString(stringer);
        stringer.endObject();
    } catch (JSONException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return stringer.toString();
}