001 // Copyright 2007 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.waterken.syntax.json; 004 005 import java.io.BufferedReader; 006 import java.io.IOException; 007 import java.io.InputStream; 008 import java.io.Serializable; 009 import java.lang.reflect.Type; 010 011 import org.joe_e.Struct; 012 import org.joe_e.array.ConstArray; 013 import org.joe_e.charset.UTF8; 014 import org.ref_send.Record; 015 import org.waterken.syntax.BadSyntax; 016 import org.waterken.syntax.Deserializer; 017 import org.waterken.syntax.Importer; 018 019 /** 020 * Deserializes a JSON byte stream. 021 */ 022 public final class 023 JSONDeserializer extends Struct implements Deserializer, Record, Serializable { 024 static private final long serialVersionUID = 1L; 025 026 public Object 027 deserialize(final InputStream content, final Importer connect, 028 final String base, final ClassLoader code, 029 final Type type) throws IOException, BadSyntax { 030 return new JSONParser(base, connect, code, 031 new BufferedReader(UTF8.input(content))).readValue(type); 032 } 033 034 public ConstArray<?> 035 deserializeTuple(final InputStream content, final Importer connect, 036 final String base, final ClassLoader code, 037 final Type... types) throws Exception { 038 return new JSONParser(base, connect, code, 039 new BufferedReader(UTF8.input(content))).readTuple(types); 040 } 041 }