Package com.granule.json

Examples of com.granule.json.JSONException


    public Parser(Reader reader) throws JSONException {
        super();    
        try {
            this.tokenizer = new Tokenizer(reader, false);
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.initCause(iox);
            throw jex;
        }
    }
View Full Code Here


    public Parser(Reader reader, boolean strict) throws JSONException {
        super();    
        try {
            this.tokenizer = new Tokenizer(reader, strict);
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.initCause(iox);
            throw jex;
        }
    }
View Full Code Here

     */
    public JSONObject parse(boolean ordered) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.initCause(iox);
            throw jex;
        }
        return parseObject(ordered, null);
    }
View Full Code Here

     */
    public JSONObject parse(boolean ordered, JSONObject jObj) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.initCause(iox);
            throw jex;
        }
        return parseObject(ordered, jObj);
    }
View Full Code Here

     */
    public JSONArray parse(boolean ordered, JSONArray jObj) throws JSONException {
        try {
            lastToken = tokenizer.next();
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during input read.");
            jex.initCause(iox);
            throw jex;
        }
        return parseArray(ordered, jObj);
    }
View Full Code Here

                } else {
                    result = new OrderedJSONObject();
                }
            }

            if (lastToken != Token.TokenBraceL) throw new JSONException("Expecting '{' " + tokenizer.onLineCol() + " instead, obtained token: '" + lastToken + "'");
            lastToken = tokenizer.next();

            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated object " + tokenizer.onLineCol());

                if (lastToken == Token.TokenBraceR) {
                    lastToken = tokenizer.next();
                    break;
                }

                if (!lastToken.isString()) throw new JSONException("Expecting string key " + tokenizer.onLineCol());
                String key = lastToken.getString();

                lastToken = tokenizer.next();
                if (lastToken != Token.TokenColon) throw new JSONException("Expecting colon " + tokenizer.onLineCol());

                lastToken = tokenizer.next();
                Object val = parseValue(ordered);

                result.put(key, val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                }

                else if (lastToken != Token.TokenBraceR) {
                    throw new JSONException("expecting either ',' or '}' " + tokenizer.onLineCol());
                }
            }
            return result;
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during object input read.");
            jex.initCause(iox);
            throw jex;
        }
    }
View Full Code Here

        } else {
            result = new JSONArray();
        }

        try {
            if (lastToken != Token.TokenBrackL) throw new JSONException("Expecting '[' " + tokenizer.onLineCol());
            lastToken = tokenizer.next();
            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated array " + tokenizer.onLineCol());

                /**
                 * End of the array.
                 */
                if (lastToken == Token.TokenBrackR) {
                    lastToken = tokenizer.next();
                    break;
                }

                Object val = parseValue(ordered);
                result.add(val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                } else if (lastToken != Token.TokenBrackR) {
                    throw new JSONException("expecting either ',' or ']' " + tokenizer.onLineCol());
                }
            }
        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during array input read.");
            jex.initCause(iox);
            throw jex;
        }
        return result;
    }
View Full Code Here

     * @param ordered Flag to denote if the parse should contruct JSON objects and arrays which maintain serialization order of the attributes.    
     *
     * @throws JSONException Thrown if an IO error (read incomplete token) occurs.
     */
    public Object parseValue(boolean ordered) throws JSONException {
        if (lastToken == Token.TokenEOF) throw new JSONException("Expecting property value " + tokenizer.onLineCol());

        try {
            if (lastToken.isNumber()) {
                Object result = lastToken.getNumber();
                lastToken = tokenizer.next();
                return result;
            }

            if (lastToken.isString()) {
                Object result = lastToken.getString();
                lastToken = tokenizer.next();
                return result;
            }

            if (lastToken == Token.TokenFalse) {
                lastToken = tokenizer.next();
                return Boolean.FALSE;
            }

            if (lastToken == Token.TokenTrue) {
                lastToken = tokenizer.next();
                return Boolean.TRUE;
            }

            if (lastToken == Token.TokenNull) {
                lastToken = tokenizer.next();
                return null;
            }

            if (lastToken == Token.TokenBrackL) return parseArray(ordered, null);
            if (lastToken == Token.TokenBraceL) return parseObject(ordered, null);

        } catch (IOException iox) {
            JSONException jex = new JSONException("Error occurred during value input read.");
            jex.initCause(iox);
            throw jex;
        }
        throw new JSONException("Invalid token " + tokenizer.onLineCol());
    }
View Full Code Here

                                                    }
                                                }
                                            }
                                        } else {
                                            // Dunno?
                                            throw new JSONException("Unknown type: [" + vClazz.getName() + "]");
                                        }
                                    } else {
                                        try {
                                            m = clazz.getMethod(setter, (Class[])null);
                                        } catch (NoSuchMethodException nmex){
                                            // Ignore, no setter.
                                        }
                                    }
                                    if (m != null) {
                                        m.invoke(obj, new Object[] { val });
                                    }
                                }
                            }
                        }
                    } else {
                        throw new JSONException("Could not locate class: [" + cName + "]");
                    }
                } catch (Exception ex) {
                    if (ex instanceof JSONException) {
                        throw (JSONException)ex;
                    } else {
                        JSONException jex = new JSONException("Error in converting JSON to Java Class");
                        jex.initCause(ex);
                        throw jex;
                    }
                }
            } else {
                throw new JSONException("Provided JSONObject does not contain attributes '_classname' or '_type'");
            }
        }
        return obj;
    }
View Full Code Here

TOP

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