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_empty_string() {
    PrimitiveTypeMsg msg = PrimitiveTypeMsg.newBuilder().setStringField("").build();

    // field is present
    assertThat(msg.hasStringField()).isTrue();
    assertThat(msg.getStringField()).isEmpty();

    assertThat(toJson(msg)).isEqualTo("{\"stringField\":\"\"}");
  }