protected Document read( InputStream stream ) throws IOException { return Json.read(stream, false); }
protected void write( Document document, OutputStream stream ) throws IOException { Json.write(document, stream); }
/** * Write to the supplied writer the modified JSON representation of the supplied in-memory {@link Document}. The resulting * JSON will have no embedded line feeds or extra spaces. * <p> * This format is compact and easy for software to read, but usually very difficult for people to read anything but very small * documents. * </p> * * @param bson the BSON object or BSON value; may not be null * @param writer the writer; may not be null * @throws IOException if there was a problem reading from the stream */ public static void write( Document bson, Writer writer ) throws IOException { getCompactJsonWriter().write(bson, writer); }
@Test public void shouldMergeTwoDocuments() throws Exception { Document doc1 = Json.read(stream("json/merge-1.json")); Document doc2 = Json.read(stream("json/merge-2.json")); Document doc3 = Json.read(stream("json/merge-3.json")); EditableDocument editor = new DocumentEditor((MutableDocument)doc1); assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(false)); editor.merge(doc2); assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(true)); } }
protected void print( Document doc ) { if (print) { try { Json.writePretty(doc, System.out); System.out.flush(); } catch (IOException err) { throw new AssertionError(err); } } }
/** * Return the modified JSON representation for the supplied in-memory {@link Document}. The resulting JSON will be indented * for each name/value pair and each array value. * <p> * This format is very readable by people and software, but is less compact due to the extra whitespace. * </p> * * @param bson the BSON object or BSON value; may not be null * @return the JSON representation; never null */ public static String writePretty( Document bson ) { return getPrettyWriter().write(bson); }
documents = Json.readMultiple(stream, false);
protected void print( Document doc, boolean deep ) { if (print) { try { Json.writePretty(doc, System.out); System.out.flush(); if (deep) { Document info = doc.getDocument(DocumentTranslator.CHILDREN_INFO); if (info != null) { String nextBlockKey = info.getString(DocumentTranslator.NEXT_BLOCK); if (nextBlockKey != null) { Document next = schematicDb.get(nextBlockKey); if (next != null) { print(next, true); } } } } } catch (IOException err) { throw new AssertionError(err); } } }
/** * Return the modified JSON representation for the supplied object value. The resulting JSON will be indented for each * name/value pair and each array value. * <p> * This format is very readable by people and software, but is less compact due to the extra whitespace. * </p> * * @param value the BSON object or BSON value; may not be null * @return the JSON representation; never null */ public static String writePretty( Object value ) { return getPrettyWriter().write(value); }
documents = Json.readMultiple(stream, false);
protected Document read( InputStream stream ) throws IOException { return Json.read(stream, false); }
@Override public String toString() { return Json.write(value); } }
/** * Return the modified JSON representation for the supplied object value. The resulting JSON will have no embedded line feeds * or extra spaces. * <p> * This format is compact and easy for software to read, but usually very difficult for people to read anything but very small * documents. * </p> * * @param value the BSON object or BSON value; may not be null * @return the string; may not be null */ public static String write( Object value ) { return getCompactJsonWriter().write(value); }
/** * Return the modified JSON representation for the supplied in-memory {@link Document}. The resulting JSON will be indented * for each name/value pair and each array value. * <p> * This format is very readable by people and software, but is less compact due to the extra whitespace. * </p> * * @param bson the BSON object or BSON value; may not be null * @return the JSON representation; never null */ public static String writePretty( Document bson ) { return getPrettyWriter().write(bson); }
/** * Reads document content from the stream. * * @param in input stream. * @throws IOException */ private void readFromStream(InputStream in) throws IOException { document = DocumentFactory.newDocument(Json.read(in)); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { return Json.write(doc); }
/** * Return the modified JSON representation for the supplied object value. The resulting JSON will have no embedded line feeds * or extra spaces. * <p> * This format is compact and easy for software to read, but usually very difficult for people to read anything but very small * documents. * </p> * * @param value the BSON object or BSON value; may not be null * @return the string; may not be null */ public static String write( Object value ) { return getCompactJsonWriter().write(value); }
/** * Return the modified JSON representation for the supplied object value. The resulting JSON will be indented for each * name/value pair and each array value. * <p> * This format is very readable by people and software, but is less compact due to the extra whitespace. * </p> * * @param value the BSON object or BSON value; may not be null * @return the JSON representation; never null */ public static String writePretty( Object value ) { return getPrettyWriter().write(value); }
/** * Returns a DB with reads the given input stream as a configuration document {@code Document}. This document is * expected to contain a {@link Schematic#TYPE_FIELD type field} to indicate the type * of DB. * * @see #getDb(Document, ClassLoader) * @throws ParsingException if the given input stream is not a valid JSON document */ public static <T extends SchematicDb> T getDb(InputStream configInputStream) throws ParsingException, RuntimeException { Document document = Json.read(configInputStream).withVariablesReplacedWithSystemProperties(); return getDb(document, Schematic.class.getClassLoader()); }
@Override public String toString() { return Json.write(this); }