// Path: bootique-graphql/src/main/java/org/objectstyle/bootique/graphql/jaxrs/BQGraphQLRestException.java
// public class BQGraphQLRestException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -1228276457093874409L;
// 	
// 	private Status status;
// 
// 	public BQGraphQLRestException() {
// 		this(Status.INTERNAL_SERVER_ERROR);
// 	}
// 
// 	public BQGraphQLRestException(Status status) {
// 		this(status, null, null);
// 	}
// 
// 	public BQGraphQLRestException(Status status, String message) {
// 		this(status, message, null);
// 	}
// 
// 	public BQGraphQLRestException(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.bootique.graphql.jaxrs.BQGraphQLRestException;
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.bootique.graphql.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: bootique-graphql/src/main/java/org/objectstyle/bootique/graphql/jaxrs/BQGraphQLRestException.java
// public class BQGraphQLRestException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -1228276457093874409L;
// 	
// 	private Status status;
// 
// 	public BQGraphQLRestException() {
// 		this(Status.INTERNAL_SERVER_ERROR);
// 	}
// 
// 	public BQGraphQLRestException(Status status) {
// 		this(status, null, null);
// 	}
// 
// 	public BQGraphQLRestException(Status status, String message) {
// 		this(status, message, null);
// 	}
// 
// 	public BQGraphQLRestException(Status status, String message, Throwable cause) {
// 		super(message, cause);
// 		this.status = status;
// 	}
// 
// 	public Status getStatus() {
// 		return status;
// 	}
// }


// Path: bootique-graphql/src/main/java/org/objectstyle/bootique/graphql/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.bootique.graphql.jaxrs.BQGraphQLRestException;
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.bootique.graphql.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 BQGraphQLRestException(Status.BAD_REQUEST, "Error parsing JSON", e);