Package org.apache.pivot.serialization

Examples of org.apache.pivot.serialization.SerializationException


                // The key is an undelimited string; it must adhere to Java
                // identifier syntax
                StringBuilder keyStringBuilder = new StringBuilder();

                if (!Character.isJavaIdentifierStart(c)) {
                    throw new SerializationException("Illegal identifier start character.");
                }

                while (c != -1
                    && c != ':' && !Character.isWhitespace(c)) {
                    if (!Character.isJavaIdentifierPart(c)) {
                        throw new SerializationException("Illegal identifier character.");
                    }

                    keyStringBuilder.append((char)c);
                    c = reader.read();
                }

                if (c == -1) {
                    throw new SerializationException("Unexpected end of input stream.");
                }

                key = keyStringBuilder.toString();
            }

            if (key == null
                || key.length() == 0) {
                throw new SerializationException("\"" + key + "\" is not a valid key.");
            }

            skipWhitespaceAndComments(reader);

            if (c != ':') {
                throw new SerializationException("Unexpected character in input stream.");
            }

            // Move to the first character after ':'
            c = reader.read();
            dictionary.put(key, readValue(reader, (valueType == null) ?
                ((BeanAdapter)dictionary).getGenericType(key) : valueType));

            skipWhitespaceAndComments(reader);

            if (c == ',') {
                c = reader.read();
                skipWhitespaceAndComments(reader);
            } else if (c == -1) {
                throw new SerializationException("Unexpected end of input stream.");
            } else {
                if (c != '}') {
                    throw new SerializationException("Unexpected character in input stream.");
                }
            }
        }

        // Move to the first character after '}'
View Full Code Here


            if (number instanceof Float) {
                Float f = (Float)number;
                if (f.isNaN()
                    || f.isInfinite()) {
                    throw new SerializationException(number + " is not a valid value.");
                }
            } else if (number instanceof Double) {
                Double d = (Double)number;
                if (d.isNaN()
                    || d.isInfinite()) {
                    throw new SerializationException(number + " is not a valid value.");
                }
            }

            writer.append(number.toString());
        } else if (object instanceof Boolean) {
View Full Code Here

        Object object = null;

        skipWhitespaceAndComments(reader);

        if (c == -1) {
            throw new SerializationException("Unexpected end of input stream.");
        }

        if (c == 'n') {
            object = readNullValue(reader);
        } else if (c == '"' || c == '\'') {
            object = readStringValue(reader, typeArgument);
        } else if (c == '+' || c == '-' || Character.isDigit(c)) {
            object = readNumberValue(reader, typeArgument);
        } else if (c == 't' || c == 'f') {
            object = readBooleanValue(reader, typeArgument);
        } else if (c == '[') {
            object = readListValue(reader, typeArgument);
        } else if (c == '{') {
            object = readMapValue(reader, typeArgument);
        } else {
            throw new SerializationException("Unexpected character in input stream.");
        }

        return object;
    }
View Full Code Here

                            closed = (c == '/');
                        }
                    }

                    if (!closed) {
                        throw new SerializationException("Unexpected end of input stream.");
                    }

                    if (c != -1) {
                        c = reader.read();
                    }
                } else {
                    throw new SerializationException("Unexpected character in input stream.");
                }
            }
        }
    }
View Full Code Here

        int n = nullString.length();
        int i = 0;

        while (c != -1 && i < n) {
            if (nullString.charAt(i) != c) {
                throw new SerializationException("Unexpected character in input stream.");
            }

            c = reader.read();
            i++;
        }

        if (i < n) {
            throw new SerializationException("Incomplete null value in input stream.");
        }

        // Notify the listeners
        if (jsonSerializerListeners != null) {
            jsonSerializerListeners.readNull(this);
View Full Code Here

                        if (!(c == '\\'
                            || c == '/'
                            || c == '\"'
                            || c == '\''
                            || c == t)) {
                            throw new SerializationException("Unsupported escape sequence in input stream.");
                        }
                    }
                }

                stringBuilder.append((char)c);
            }

            c = reader.read();
        }

        if (c != t) {
            throw new SerializationException("Unterminated string in input stream.");
        }

        // Move to the next character after the delimiter
        c = reader.read();
View Full Code Here

    }

    private Object readStringValue(Reader reader, Type typeArgument)
        throws IOException, SerializationException {
        if (!(typeArgument instanceof Class<?>)) {
            throw new SerializationException("Cannot convert string to " + typeArgument + ".");
        }

        String string = readString(reader);

        // Notify the listeners
View Full Code Here

    }

    private Object readNumberValue(Reader reader, Type typeArgument)
        throws IOException, SerializationException {
        if (!(typeArgument instanceof Class<?>)) {
            throw new SerializationException("Cannot convert number to " + typeArgument + ".");
        }

        Number number = null;

        StringBuilder stringBuilder = new StringBuilder();
View Full Code Here

    }

    private Object readBooleanValue(Reader reader, Type typeArgument)
        throws IOException, SerializationException {
        if (!(typeArgument instanceof Class<?>)) {
            throw new SerializationException("Cannot convert boolean to " + typeArgument + ".");
        }

        String text = (c == 't') ? "true" : "false";
        int n = text.length();
        int i = 0;

        while (c != -1 && i < n) {
            if (text.charAt(i) != c) {
                throw new SerializationException("Unexpected character in input stream.");
            }

            c = reader.read();
            i++;
        }

        if (i < n) {
            throw new SerializationException("Incomplete boolean value in input stream.");
        }

        // Get the boolean value
        Boolean value = Boolean.parseBoolean(text);
View Full Code Here

                parentType = classType.getGenericSuperclass();
            }

            if (itemType == null) {
                throw new SerializationException("Could not determine sequence item type.");
            }

            // Instantiate the sequence type
            Class<?> sequenceType;
            if (typeArgument instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType)typeArgument;
                sequenceType = (Class<?>)parameterizedType.getRawType();
            } else {
                sequenceType = (Class<?>)typeArgument;
            }

            try {
                sequence = (Sequence<Object>)sequenceType.newInstance();
            } catch (InstantiationException exception) {
                throw new RuntimeException(exception);
            } catch (IllegalAccessException exception) {
                throw new RuntimeException(exception);
            }
        }

        // Notify the listeners
        if (jsonSerializerListeners != null) {
            jsonSerializerListeners.beginSequence(this, sequence);
        }

        // Move to the next character after '['
        c = reader.read();
        skipWhitespaceAndComments(reader);

        while (c != -1 && c != ']') {
            sequence.add(readValue(reader, itemType));
            skipWhitespaceAndComments(reader);

            if (c == ',') {
                c = reader.read();
                skipWhitespaceAndComments(reader);
            } else if (c == -1) {
                throw new SerializationException("Unexpected end of input stream.");
            } else {
                if (c != ']') {
                    throw new SerializationException("Unexpected character in input stream.");
                }
            }
        }

        // Move to the next character after ']'
View Full Code Here

TOP

Related Classes of org.apache.pivot.serialization.SerializationException

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.