Package org.json

Examples of org.json.JSONException


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


                if (ignore_missing) {
                    if (debug.val)
                        LOG.warn(msg);
                    continue;
                } else {
                    throw new JSONException(msg);
                }
            }

            try {
                readFieldValue(json_object, catalog_db, 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

                value = CatalogKey.getFromKey(catalog_db, json_value, catalog_class);
            } catch (Throwable ex) {
                throw new Exception("Failed to get catalog object from \"" + json_value + "\"", ex);
            }
            if (value == null)
                throw new JSONException("Failed to get catalog object from \"" + json_value + "\"");
        }
        // Class
        else 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()) {
            if (field_class.equals(VoltType.class)) {
                json_value = json_value.replace("VoltType.", "");
            }
            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()));
        }
        // 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);
View Full Code Here

                            default:
                                assert(false) : "Unexpected Type: " + attr_type;
                        } // SWITCH
                    } catch (Exception ex) {
                        LOG.fatal("Failed to deserialize TXN_VALUES-" + inner_key + "-" + i);
                        throw new JSONException(ex);
                    }
                }
                this.txn_values.get(txn_id).add(val);
            } // FOR
        } // WHILE
View Full Code Here

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

        else
        {
            switch (m_valueType)
            {
            case INVALID:
                throw new JSONException("ConstantValueExpression.toJSONString(): value_type should never be VoltType.INVALID");
            case NULL:
                throw new JSONException("ConstantValueExpression.toJSONString(): And they should be never be this either! VoltType.NULL");
            case TINYINT:
                stringer.value(Long.valueOf(m_value));
                break;
            case SMALLINT:
                stringer.value(Long.valueOf(m_value));
                break;
            case INTEGER:
                stringer.value(Long.valueOf(m_value));
                break;
            case BIGINT:
                stringer.value(Long.valueOf(m_value));
                break;
            case FLOAT:
                stringer.value(Double.valueOf(m_value));
                break;
            case STRING:
                stringer.value(m_value);
                break;
            case TIMESTAMP:
                stringer.value(Long.valueOf(m_value));
                break;
            case DECIMAL:
                stringer.value(m_value);
                break;
            default:
                throw new JSONException("ConstantValueExpression.toJSONString(): Unrecognized value_type " + m_valueType);
            }
        }
    }
View Full Code Here

  @Test
  public void testDoGetWithHandlerJsonException() throws Exception {
    HttpServletRequest request = createGetRequest("{\"gadgets\":[]}", "function");
    HttpServletResponse response = createHttpResponse("Malformed JSON request.",
        HttpServletResponse.SC_BAD_REQUEST);
    expect(handler.process(isA(JSONObject.class))).andThrow(new JSONException("json"));
    replay(handler);
    servlet.doGet(request, response);
    verify(response);
  }
View Full Code Here

  @Test
  public void testDoGetWithHandlerJsonException() throws Exception {
    HttpServletRequest request = createGetRequest("{\"gadgets\":[]}", "function");
    HttpServletResponse response = createHttpResponse("Malformed JSON request.",
        HttpServletResponse.SC_BAD_REQUEST);
    expect(handler.process(isA(JSONObject.class))).andThrow(new JSONException("json"));
    replay(handler);
    servlet.doGet(request, response);
    verify(response);
  }
View Full Code Here

  public void testDoGetWithHandlerJsonException() throws Exception {
    HttpServletRequest request = createGetRequest("{\"gadgets\":[]}", "function");
    HttpServletResponse response = createHttpResponse("Malformed JSON request.",
        HttpServletResponse.SC_BAD_REQUEST);
    expect(handler.process(isA(JSONObject.class))).andThrow(new JSONException("json"));
    replay(handler);
    servlet.doGet(request, response);
    verify(response);
  }
View Full Code Here

TOP

Related Classes of org.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.