// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
	
	/**
	 * Writes a request.
	 *
	 * @param methodName the method name
	 * @param arguments  the arguments
	 * @param output     the stream
	 * @param id         the optional id
	 * @throws IOException on error
	 */
	private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
		final ObjectNode request = internalCreateRequest(methodName, arguments, id);
		logger.debug("Request {}", request);
		writeAndFlushValue(output, request);
	}
	
	private JsonNode readResponseNode(ReadContext context) throws IOException {
		context.assertReadable();
		JsonNode response = context.nextValue();
		logger.debug("JSON-RPC Response: {}", response);
		return response;
	}
	
	private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
		if (isInvalidResponse(response)) {
			throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
		}
	}
	
	private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) {
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// 
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";


// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;

	
	/**
	 * Writes a request.
	 *
	 * @param methodName the method name
	 * @param arguments  the arguments
	 * @param output     the stream
	 * @param id         the optional id
	 * @throws IOException on error
	 */
	private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
		final ObjectNode request = internalCreateRequest(methodName, arguments, id);
		logger.debug("Request {}", request);
		writeAndFlushValue(output, request);
	}
	
	private JsonNode readResponseNode(ReadContext context) throws IOException {
		context.assertReadable();
		JsonNode response = context.nextValue();
		logger.debug("JSON-RPC Response: {}", response);
		return response;
	}
	
	private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
		if (isInvalidResponse(response)) {
			throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
		}
	}
	
	private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) {
		return !jsonObject.has(ID) || jsonObject.get(ID) == null || !jsonObject.get(ID).asText().equals(id);