### Question:
JcrJsonAdapter extends TypeAdapter<Node> { @Override public void write(JsonWriter writer, Node t) throws IOException { if (t != null) { try { writer.beginObject(); for (PropertyIterator pi = t.getProperties(); pi.hasNext();) { Property p = (Property) pi.next(); writer.name(p.getName()); if (p.isMultiple()) { writer.beginArray(); for (Value v : p.getValues()) { writeValue(writer, v); } writer.endArray(); } else { writeValue(writer, p.getValue()); } } for (NodeIterator ni = t.getNodes(); ni.hasNext();) { Node child = ni.nextNode(); writer.name(child.getName()); write(writer, child); } writer.endObject(); } catch (RepositoryException ex) { throw new IOException(ex); } } }  @Override void write(JsonWriter writer, Node t); @Override Node read(JsonReader reader);  }### Answer:
@Test public void testWrite() throws RepositoryException { Node root = JcrUtils.getOrCreateByPath("/test/level1", JcrConstants.NT_UNSTRUCTURED, session); root.setProperty("level",1); Node l2 = JcrUtils.getOrCreateByPath("/test/level1/l2", JcrConstants.NT_UNSTRUCTURED, session); l2.setProperty("level",2); Node l3 = JcrUtils.getOrCreateByPath("/test/level1/l2/l3", JcrConstants.NT_UNSTRUCTURED, session); l3.setProperty("level",3); JsonObject jsonObject = toJsonObject(root); assertNotNull(jsonObject); assertEquals(1L, getInteger(jsonObject, "level").longValue()); assertTrue(jsonObject.has("l2")); assertEquals(2L, getInteger(jsonObject.get("l2").getAsJsonObject(), "level").longValue()); assertTrue(jsonObject.get("l2").getAsJsonObject().has("l3")); assertEquals(3L, getInteger(jsonObject.get("l2").getAsJsonObject().get("l3").getAsJsonObject(), "level").longValue()); }