Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.gson;
 
Created by koush on 5/27/13.
public class GsonParser<T extends JsonElementimplements AsyncParser<T> {
    public GsonParser() {
    }
    @Override
    public Future<T> parse(DataEmitter emitter) {
        return new TransformFuture<T, ByteBufferList>() {
            @Override
            protected void transform(ByteBufferList resultthrows Exception {
                JsonParser parser = new JsonParser();
                T parsed = (T)parser.parse(new JsonReader(new InputStreamReader(new ByteBufferListInputStream(result))));
                if (parsed.isJsonNull() || parsed.isJsonPrimitive())
                    throw new JsonParseException("unable to parse json");
                setComplete(nullparsed);
            }
        }
        .from(new ByteBufferListParser().parse(emitter));
    }
    @Override
    public void write(DataSink sink, T valueCompletedCallback completed) {
        new StringParser().write(sinkvalue.toString(), completed);
    }
New to GrepCode? Check out our FAQ X