### Question:
JSONResultProducer extends AbstractResultProducer { @Override public void stream(SPARQLQuery query, Writer writer) throws IOException { JsonGenerator generator = jsonFactory.createJsonGenerator(writer); if (query.getResultType().equals(SPARQLQuery.ResultType.BOOLEAN)) { streamBoolean(query, generator); } else { streamTuple(query, generator); } generator.flush(); }  @Override void stream(SPARQLQuery query, Writer writer);  }### Answer:
@Test public void Ask() throws IOException { JSONResultProducer producer = new JSONResultProducer(); SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL, "ASK { ?s ?p ?o }"); StringWriter writer = new StringWriter(); producer.stream(query, writer); assertEquals("{\"head\":null,\"boolean\":true}", writer.toString()); }
@Test public void Select() throws IOException { JSONResultProducer producer = new JSONResultProducer(); SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL, "SELECT * WHERE { ?s ?p ?o } LIMIT 4"); StringWriter writer = new StringWriter(); producer.stream(query, writer); System.out.println(writer.toString()); String response = writer.toString(); assertTrue(response.startsWith("{\"head\":{\"vars\":[\"s\",\"p\",\"o\"]},\"results\":{\"bindings\":[{\"s\":")); assertTrue(response.endsWith("}}]}}")); }