Search in sources :

Example 1 with MacroReader

use of org.apache.pivot.serialization.MacroReader in project pivot by apache.

the class JSONSerializer method readObject.

/**
 * Reads data from a JSON stream.
 * <p> Processes macros at this level using {@link MacroReader}.
 *
 * @param reader The reader from which data will be read.
 * @return One of the following types, depending on the content of the stream
 * and the value of {@link #getType()}:
 * <ul>
 * <li>pivot.collections.Dictionary</li>
 * <li>pivot.collections.Sequence</li>
 * <li>java.lang.String</li>
 * <li>java.lang.Number</li>
 * <li>java.lang.Boolean</li>
 * <li><tt>null</tt></li>
 * <li>A JavaBean object</li>
 * </ul>
 * @throws IOException for any I/O related errors while reading.
 * @throws SerializationException for any formatting errors in the data.
 */
public Object readObject(Reader reader) throws IOException, SerializationException {
    Utils.checkNull(reader, "reader");
    // Move to the first character
    LineNumberReader lineNumberReader = new LineNumberReader(reader);
    MacroReader macroReader = new MacroReader(lineNumberReader);
    c = macroReader.read();
    // Ignore BOM (if present)
    if (c == 0xFEFF) {
        c = macroReader.read();
    }
    // Read the root value
    Object object;
    try {
        object = readValue(macroReader, type, type.getTypeName());
    } catch (SerializationException exception) {
        System.err.println("An error occurred while processing input at line number " + (lineNumberReader.getLineNumber() + 1));
        throw exception;
    }
    return object;
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) MacroReader(org.apache.pivot.serialization.MacroReader) LineNumberReader(java.io.LineNumberReader)

Aggregations

LineNumberReader (java.io.LineNumberReader)1 MacroReader (org.apache.pivot.serialization.MacroReader)1 SerializationException (org.apache.pivot.serialization.SerializationException)1