JsonFormatter { public String format(Explainer explainer) { StringWriter str = new StringWriter(); try { JsonGenerator generator = pretty ? createPrettyJsonGenerator(str) : createJsonGenerator(str); generate(generator, explainer); generator.flush(); } catch (IOException ex) { throw new AkibanInternalException("Error writing to string", ex); } return str.toString(); }  String format(Explainer explainer); void format(Explainer explainer, Writer writer); void format(Explainer explainer, OutputStream stream); void format(Explainer explainer, JsonGenerator generator); void generate(JsonGenerator generator, Explainer explainer);  }
@Test public void testDescribe_Explainer() { PrimitiveExplainer s = PrimitiveExplainer.getInstance("string"); PrimitiveExplainer l = PrimitiveExplainer.getInstance(123); PrimitiveExplainer n = PrimitiveExplainer.getInstance(3.14); PrimitiveExplainer b = PrimitiveExplainer.getInstance(true); Attributes a = new Attributes(); a.put(Label.NAME, PrimitiveExplainer.getInstance("TEST")); a.put(Label.OPERAND, s); a.put(Label.OPERAND, l); a.put(Label.OPERAND, n); a.put(Label.OPERAND, b); CompoundExplainer c = new CompoundExplainer(Type.FUNCTION, a); CompoundExplainer c2 = new CompoundExplainer(Type.EXTRA_INFO); c2.addAttribute(Label.COST, PrimitiveExplainer.getInstance("a lot")); c.addAttribute(Label.EXTRA_TAG, c2); String expected = "{\n" + " \"type\" : \"function\",\n" + " \"operand\" : [ \"string\", 123, 3.14, true ],\n" + " \"extra_tag\" : [ {\n" + " \"type\" : \"extra_info\",\n" + " \"cost\" : [ \"a lot\" ]\n" + " } ],\n" + " \"name\" : [ \"TEST\" ]\n" + "}"; JsonFormatter f = new JsonFormatter(); assertEquals(expected, f.format(c)); }