code: public String toJson(final JsonWriterSettings writerSettings, final Encoder<Document> encoder) {
          JsonWriter writer = new JsonWriter(new StringWriter(), writerSettings);
          encoder.encode(writer, this, EncoderContext.builder().isEncodingCollectibleDocument(true).build());
          return writer.getWriter().toString();
      }
docs: Gets a JSON representation of this document
  
  @param writerSettings the json writer settings to use when encoding
  @param encoder the document codec instance to use to encode the document
  @return a JSON representation of this document
  @throws org.bson.codecs.configuration.CodecConfigurationException if the registry does not contain a codec for the document values.