Package com.oltpbenchmark.util.json

Examples of com.oltpbenchmark.util.json.JSONException


     */
    public static <E extends Enum<?>, T> void fieldsToJSON(JSONStringer stringer, T object, Class<? extends T> base_class, E members[]) throws JSONException {
        try {
            fieldsToJSON(stringer, object, base_class, ClassUtil.getFieldsFromMembersEnum(base_class, members));   
        } catch (NoSuchFieldException ex) {
            throw new JSONException(ex);
        }
    }
View Full Code Here


                // Everything else
                } else {
                    writeFieldValue(stringer, f_class, f_value);
                }
            } catch (Exception ex) {
                throw new JSONException(ex);
            }
        } // FOR
    }
View Full Code Here

            Stack<Class> inner_classes = new Stack<Class>();
            inner_classes.addAll(ClassUtil.getGenericTypes(field_handle));
            Collections.reverse(inner_classes);
           
            JSONArray json_inner =json_object.getJSONArray(json_key);
            if (json_inner == null) throw new JSONException("No array exists for '" + json_key + "'");
            readCollectionField(json_inner, (Collection)field_object, inner_classes);

        // Maps
        } else if (field_object instanceof Map) {
            if (LOG.isDebugEnabled()) LOG.debug("Field " + json_key + " is a map");
            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 {
            Class explicit_field_class = JSONUtil.getClassForField(json_object, json_key);
View Full Code Here

     */
    public static <E extends Enum<?>, T> void fieldsFromJSON(JSONObject json_object, T object, Class<? extends T> base_class, boolean ignore_missing, E...members) throws JSONException {
        try {
            fieldsFromJSON(json_object, object, base_class, ignore_missing, ClassUtil.getFieldsFromMembersEnum(base_class, members));   
        } catch (NoSuchFieldException ex) {
            throw new JSONException(ex);
        }
    }
View Full Code Here

                String msg = "JSONObject for " + base_class.getSimpleName() + " does not have key '" + json_key + "': " + CollectionUtil.list(json_object.keys());
                if (ignore_missing) {
                    if (LOG.isDebugEnabled()) LOG.warn(msg);
                    continue;
                } else {
                    throw new JSONException(msg);   
                }
            }
           
            try {
                readFieldValue(json_object, json_key, field_handle, object);
            } catch (Exception ex) {
                // System.err.println(field_class + ": " + ClassUtil.getSuperClasses(field_class));
                LOG.error("Unable to deserialize field '" + json_key + "' from " + base_class.getSimpleName(), ex);
                throw new JSONException(ex);
            }
        } // FOR
    }
View Full Code Here

        if (json_object.has(json_key + JSON_CLASS_SUFFIX)) {
            try {
                field_class = ClassUtil.getClass(json_object.getString(json_key + JSON_CLASS_SUFFIX));
            } catch (Exception ex) {
                LOG.error("Failed to include class for field '" + json_key + "'", ex);
                throw new JSONException(ex);
            }
        }
        return (field_class);
       
    }
View Full Code Here

        Object value = null;

        // Class
        if (field_class.equals(Class.class)) {
            value = ClassUtil.getClass(json_value);
            if (value == null) throw new JSONException("Failed to get class from '" + json_value + "'");
        // Enum
        } else if (field_class.isEnum()) {
            for (Object o : field_class.getEnumConstants()) {
                Enum<?> e = (Enum<?>)o;
                if (json_value.equals(e.name())) return (e);
            } // 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
View Full Code Here

TOP

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

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.