public static String toJson(Message message) {
    StringWriter json = new StringWriter();
    try (JsonWriter jsonWriter = JsonWriter.of(json)) {
      write(message, jsonWriter);
    }
    return json.toString();
  }
@Test
  public void write_map() {
    TestMap.Builder builder = TestMap.newBuilder();
    builder.getMutableStringMap().put("one", "un");
    builder.getMutableStringMap().put("two", "deux");
    builder.getMutableNestedMap().put("three", NestedMsg.newBuilder().setLabel("trois").build());
    builder.getMutableNestedMap().put("four", NestedMsg.newBuilder().setLabel("quatre").build());
    assertThat(toJson(builder.build())).isEqualTo(
      "{\"stringMap\":{\"one\":\"un\",\"two\":\"deux\"},\"nestedMap\":{\"three\":{\"label\":\"trois\"},\"four\":{\"label\":\"quatre\"}}}");
  }