// Path: graphql-rest/src/main/java/org/objectstyle/graphql/rest/GraphQLRestException.java
// public class GraphQLRestException extends RuntimeException {
// 
//     private static final long serialVersionUID = -1228276457093874409L;
// 
//     private Status status;
// 
//     public GraphQLRestException() {
//         this(Status.INTERNAL_SERVER_ERROR);
//     }
// 
//     public GraphQLRestException(Status status) {
//         this(status, null, null);
//     }
// 
//     public GraphQLRestException(Status status, String message) {
//         this(status, message, null);
//     }
// 
//     public GraphQLRestException(Status status, String message, Throwable cause) {
//         super(message, cause);
//         this.status = status;
//     }
// 
//     public Status getStatus() {
//         return status;
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;
import javax.ws.rs.core.Response.Status;
import org.objectstyle.graphql.rest.GraphQLRestException;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
package org.objectstyle.graphql.rest.json;





public class JacksonReaderWriter implements JsonReader, JsonWriter {

    private ObjectMapper sharedMapper;
    private JsonFactory sharedFactory;

    public JacksonReaderWriter() {

        // fun Jackson API with circular dependencies ... so we create a mapper
        // first, and grab implicitly created factory from it
        this.sharedMapper = new ObjectMapper();
        this.sharedFactory = sharedMapper.getFactory();

        // make sure mapper does not attempt closing streams it does not
        // manage... why is this even a default in jackson?
        sharedFactory.disable(Feature.AUTO_CLOSE_TARGET);

        // do not flush every time. why would we want to do that?
        // this is having a HUGE impact on extrest serializers (5x speedup)
        sharedMapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
    }

    private JsonNode parseJson(InputStream jsonStream) {
        Objects.requireNonNull(jsonStream);

        try {
            com.fasterxml.jackson.core.JsonParser parser = sharedFactory.createParser(jsonStream);
            return new ObjectMapper().readTree(parser);
        } catch (IOException e) {
// Path: graphql-rest/src/main/java/org/objectstyle/graphql/rest/GraphQLRestException.java
// public class GraphQLRestException extends RuntimeException {
// 
//     private static final long serialVersionUID = -1228276457093874409L;
// 
//     private Status status;
// 
//     public GraphQLRestException() {
//         this(Status.INTERNAL_SERVER_ERROR);
//     }
// 
//     public GraphQLRestException(Status status) {
//         this(status, null, null);
//     }
// 
//     public GraphQLRestException(Status status, String message) {
//         this(status, message, null);
//     }
// 
//     public GraphQLRestException(Status status, String message, Throwable cause) {
//         super(message, cause);
//         this.status = status;
//     }
// 
//     public Status getStatus() {
//         return status;
//     }
// }


// Path: graphql-rest/src/main/java/org/objectstyle/graphql/rest/json/JacksonReaderWriter.java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;
import javax.ws.rs.core.Response.Status;
import org.objectstyle.graphql.rest.GraphQLRestException;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;

package org.objectstyle.graphql.rest.json;





public class JacksonReaderWriter implements JsonReader, JsonWriter {

    private ObjectMapper sharedMapper;
    private JsonFactory sharedFactory;

    public JacksonReaderWriter() {

        // fun Jackson API with circular dependencies ... so we create a mapper
        // first, and grab implicitly created factory from it
        this.sharedMapper = new ObjectMapper();
        this.sharedFactory = sharedMapper.getFactory();

        // make sure mapper does not attempt closing streams it does not
        // manage... why is this even a default in jackson?
        sharedFactory.disable(Feature.AUTO_CLOSE_TARGET);

        // do not flush every time. why would we want to do that?
        // this is having a HUGE impact on extrest serializers (5x speedup)
        sharedMapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
    }

    private JsonNode parseJson(InputStream jsonStream) {
        Objects.requireNonNull(jsonStream);

        try {
            com.fasterxml.jackson.core.JsonParser parser = sharedFactory.createParser(jsonStream);
            return new ObjectMapper().readTree(parser);
        } catch (IOException e) {
            throw new GraphQLRestException(Status.BAD_REQUEST, "Error parsing JSON", e);