public JsonWriter(final Writer writer, final JsonWriterSettings settings) { super(writer, settings); this.settings = settings; if (settings.getOutputMode().equals(JsonMode.SHELL)) throw new IllegalArgumentException("JsonMode must not be SHELL"); setContext(new Context(null, BsonContextType.TOP_LEVEL, "")); }
@Override public String generateResponse(MetricRegistry registry) throws IOException { BsonDocument document = MetricsJsonGenerator.generateMetricsBson(registry, TimeUnit.SECONDS, TimeUnit.MILLISECONDS); return document.toJson( JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).indent(true).build() ); }
public static String formatJson(Document doc) { return doc.toJson(new JsonWriterSettings(JsonMode.SHELL, true)); }
@Test public void bsonDocumentShellTest() { assertNotNull(bsonDocument); assertEquals("{\"_id\":\"5662e5798172910f5a925a43\", \"date\":\"2015-12-05T13:26:23.184\", \"pattern\":\"\\\\d/i\", \"pattern2\":\"\\\\s\", \"long\":9223372036854775807, \"null\":null, \"double\":1.0, \"string\":\"thiago\", \"boolean\":true, \"doc\":{\"key\":\"value\"}, \"list\":[\"value\"], \"map\":{\"key\":\"value\"}}", parse(bsonDocument.toJson(new JsonWriterSettings(JsonMode.SHELL)))); }
@Test public void documentStrictTest() { assertNotNull(document); assertEquals("{\"_id\":\"5662e5798172910f5a925a43\", \"date\":\"2015-12-05T13:26:23.184\", \"pattern\":\"\\\\d/i\", \"pattern2\":\"\\\\s\", \"long\":9223372036854775807, \"null\":null, \"double\":1.0, \"string\":\"thiago\", \"boolean\":true, \"doc\":{\"key\":\"value\"}, \"list\":[\"value\"], \"map\":{\"key\":\"value\"}}", parse(document.toJson(new JsonWriterSettings(JsonMode.STRICT)))); }
@Test public void documentShellTest() { assertNotNull(document); assertEquals("{\"_id\":\"5662e5798172910f5a925a43\", \"date\":\"2015-12-05T13:26:23.184\", \"pattern\":\"\\\\d/i\", \"pattern2\":\"\\\\s\", \"long\":9223372036854775807, \"null\":null, \"double\":1.0, \"string\":\"thiago\", \"boolean\":true, \"doc\":{\"key\":\"value\"}, \"list\":[\"value\"], \"map\":{\"key\":\"value\"}}", parse(document.toJson(new JsonWriterSettings(JsonMode.SHELL)))); }