Package org.json

Examples of org.json.JSONStringer


        // Can't be implemented since we always need to have a Database catalog object
        return null;
    }
   
    public String toJSONString(Database catalog_db) {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            this.toJSONString(stringer, catalog_db);
            stringer.endObject();
        } catch (JSONException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        return stringer.toString();
    }
View Full Code Here


    /**
     *
     */
    @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();
    }
View Full Code Here

    /**
     *
     */
    @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();
    }
View Full Code Here

    /**
     *
     */
    @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();
    }
View Full Code Here

     * @throws Exception
     */
    public static <V extends AbstractVertex, E extends AbstractEdge> void save(IGraph<V, E> graph, File output_path) throws IOException {
        if (debug.val) LOG.debug("Writing out graph to '" + output_path + "'");
       
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            GraphUtil.serialize(graph, stringer);
            stringer.endObject();
        } catch (Exception ex) {
            throw new IOException(ex);
        }
       
        String json = stringer.toString();
        try {
            FileUtil.writeStringToFile(output_path, JSONUtil.format(json));
        } catch (Exception ex) {
            throw new IOException(ex);
        }
View Full Code Here

     * @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()));
    }
View Full Code Here

     * @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());
    }
View Full Code Here

        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);
View Full Code Here

    /**
     *
     */
    @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();
    }
View Full Code Here

        // 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);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.json.JSONStringer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.