Package com.oltpbenchmark.util.json

Examples of com.oltpbenchmark.util.json.JSONObject


     * testFromJSON
     */
    public void testFromJSON() throws Exception {
        String json = h.toJSONString();
        assertNotNull(json);
        JSONObject jsonObject = new JSONObject(json);
        System.err.println(jsonObject.toString(1));
       
        Histogram<Integer> copy = new Histogram<Integer>();
        copy.fromJSON(jsonObject);
        assertEquals(h.getValueCount(), copy.getValueCount());
        for (Histogram.Members element : Histogram.Members.values()) {
View Full Code Here


     * @return
     * @throws JSONException
     */
    public static String format(String json) {
        try {
            return (JSONUtil.format(new JSONObject(json)));
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
View Full Code Here

        return (stringer.toString());
    }
   
    public static <T extends JSONSerializable> T fromJSONString(T t, String json) {
        try {
            JSONObject json_object = new JSONObject(json);
            t.fromJSON(json_object);
        } catch (JSONException ex) {
            throw new RuntimeException("Failed to deserialize object " + t, ex);
        }
        return (t);
View Full Code Here

        String contents = FileUtil.readFile(input_path);
        if (contents.isEmpty()) {
            throw new IOException("The " + object.getClass().getSimpleName() + " file '" + input_path + "' is empty");
        }
        try {
            object.fromJSON(new JSONObject(contents));
        } catch (Exception ex) {
            if (LOG.isDebugEnabled()) LOG.error("Failed to deserialize the " + object.getClass().getSimpleName() + " from file '" + input_path + "'", ex);
            throw new IOException(ex);
        }
        if (LOG.isDebugEnabled()) LOG.debug("The loading of the " + object.getClass().getSimpleName() + " is complete");
View Full Code Here

            assert(field_object != null);
            Stack<Class> inner_classes = new Stack<Class>();
            inner_classes.addAll(ClassUtil.getGenericTypes(field_handle));
            Collections.reverse(inner_classes);
           
            JSONObject json_inner = json_object.getJSONObject(json_key);
            if (json_inner == null) throw new JSONException("No object exists for '" + json_key + "'");
            readMapField(json_inner, (Map)field_object, inner_classes);
           
        // Everything else...
        } else {
View Full Code Here

            } // FOR
            throw new JSONException("Invalid enum value '" + json_value + "': " + Arrays.toString(field_class.getEnumConstants()));
         // JSONSerializable
        } else if (ClassUtil.getInterfaces(field_class).contains(JSONSerializable.class)) {
            value = ClassUtil.newInstance(field_class, null, null);
            ((JSONSerializable)value).fromJSON(new JSONObject(json_value));
        // Boolean
        } else if (field_class.equals(Boolean.class) || field_class.equals(boolean.class)) {
            // We have to use field_class.equals() because the value may be null
            value = Boolean.parseBoolean(json_value);
        // Short
View Full Code Here

TOP

Related Classes of com.oltpbenchmark.util.json.JSONObject

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.