com.mongodb.BasicDBObject.toJson()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.mongodb.BasicDBObject.toJson()方法的一些代码示例,展示了BasicDBObject.toJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.toJson()方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:toJson

BasicDBObject.toJson介绍

[英]Gets a JSON representation of this document using the org.bson.json.JsonMode#STRICT output mode, and otherwise the default settings of JsonWriterSettings.Builder and DBObjectCodec.
[中]使用组织获取此文档的JSON表示形式。布森。json。JsonMode#严格输出模式,否则为JsonWriterSettings的默认设置。生成器和DBObjectCodec。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * <p>Returns a JSON serialization of this object</p>
 *
 * <p>The output will look like: {@code  {"a":1, "b":["x","y","z"]} }</p>
 *
 * @return JSON serialization
 */
@SuppressWarnings("deprecation")
public String toString() {
  return toJson();
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Gets a JSON representation of this document using the {@link org.bson.json.JsonMode#STRICT} output mode, and otherwise the default
 * settings of {@link JsonWriterSettings.Builder} and {@link DBObjectCodec}.
 *
 * @return a JSON representation of this document
 * @throws org.bson.codecs.configuration.CodecConfigurationException if the document contains types not in the default registry
 * @see #toJson(JsonWriterSettings)
 * @see JsonWriterSettings
 */
@SuppressWarnings("deprecation")
public String toJson() {
  return toJson(new JsonWriterSettings());
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Gets a JSON representation of this document
 *
 * <p>With the default {@link JsonWriterSettings}.</p>
 *
 * @param encoder the BasicDBObject codec instance to encode the document with
 * @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.
 */
@SuppressWarnings("deprecation")
public String toJson(final Encoder<BasicDBObject> encoder) {
  return toJson(new JsonWriterSettings(), encoder);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Gets a JSON representation of this document
 *
 * <p>With the default {@link DBObjectCodec}.</p>
 *
 * @param writerSettings the json writer settings to use when encoding
 * @return a JSON representation of this document
 * @throws org.bson.codecs.configuration.CodecConfigurationException if the document contains types not in the default registry
 */
public String toJson(final JsonWriterSettings writerSettings) {
  return toJson(writerSettings, DBObjectCodec.getDefaultRegistry().get(BasicDBObject.class));
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * <p>Returns a JSON serialization of this object</p>
 *
 * <p>The output will look like: {@code  {"a":1, "b":["x","y","z"]} }</p>
 *
 * @return JSON serialization
 */
@SuppressWarnings("deprecation")
public String toString() {
  return toJson();
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
  public String toString() {
    return new BasicDBObject(revision.toString(), value).toJson();
  }
}

代码示例来源:origin: org.apache.jackrabbit/oak-store-document

@Override
  public String toString() {
    return new BasicDBObject(revision.toString(), value).toJson();
  }
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * Gets a JSON representation of this document
 *
 * <p>With the default {@link JsonWriterSettings}.</p>
 *
 * @param encoder the BasicDBObject codec instance to encode the document with
 * @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.
 */
@SuppressWarnings("deprecation")
public String toJson(final Encoder<BasicDBObject> encoder) {
  return toJson(new JsonWriterSettings(), encoder);
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * Gets a JSON representation of this document using the {@link org.bson.json.JsonMode#STRICT} output mode, and otherwise the default
 * settings of {@link JsonWriterSettings.Builder} and {@link DBObjectCodec}.
 *
 * @return a JSON representation of this document
 * @throws org.bson.codecs.configuration.CodecConfigurationException if the document contains types not in the default registry
 * @see #toJson(JsonWriterSettings)
 * @see JsonWriterSettings
 */
@SuppressWarnings("deprecation")
public String toJson() {
  return toJson(new JsonWriterSettings());
}

代码示例来源:origin: org.mongodb/mongodb-driver-core

/**
 * Gets a JSON representation of this document
 *
 * <p>With the default {@link DBObjectCodec}.</p>
 *
 * @param writerSettings the json writer settings to use when encoding
 * @return a JSON representation of this document
 * @throws org.bson.codecs.configuration.CodecConfigurationException if the document contains types not in the default registry
 */
public String toJson(final JsonWriterSettings writerSettings) {
  return toJson(writerSettings, DBObjectCodec.getDefaultRegistry().get(BasicDBObject.class));
}

代码示例来源:origin: ru.sbtqa.tag.datajack.adaptors/datajack-excel-adaptor

@Override
public TestDataObject getReference() throws DataException {
  if (null != this.basicObj.get(VALUE_TPL) && !(this.basicObj.get(VALUE_TPL) instanceof String)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField(SHEET_NAME_TPL)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField("path")) {
    if (this.rootObj == null) {
      this.rootObj = this.basicObj;
    } else {
      String rootJson = this.rootObj.toJson();
      String baseJson = this.basicObj.toJson();
      if (rootJson.equals(baseJson)) {
        throw new CyclicReferencesExeption("Cyclic references in database:\n" + rootJson);
      }
    }
    String referencedCollection = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString(SHEET_NAME_TPL);
    this.path = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString("path");
    ExcelDataObjectAdaptor reference = this.fromCollection(referencedCollection);
    reference.setRootObj(this.rootObj, referencedCollection + "." + this.path);
    return reference.get(this.path);
  } else {
    throw new ReferenceException(String.format("There is no reference in '%s'. Collection '%s'",
        this.path, this.sheetName));
  }
}

代码示例来源:origin: ru.sbtqa.tag.datajack.adaptors/datajack-json-adaptor

@Override
public TestDataObject getReference() throws DataException {
  if (null != this.basicObj.get(VALUE_TPL) && !(this.basicObj.get(VALUE_TPL) instanceof String)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField(COLLECTION_TPL)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField("path")) {
    if (this.rootObj == null) {
      this.rootObj = this.basicObj;
    } else {
      String rootJson = this.rootObj.toJson();
      String baseJson = this.basicObj.toJson();
      if (rootJson.equals(baseJson)) {
        throw new CyclicReferencesExeption("Cyclic references in database:\n" + rootJson);
      }
    }
    String referencedCollection = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString(COLLECTION_TPL);
    this.path = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString("path");
    JsonDataObjectAdaptor reference = this.fromCollection(((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString(COLLECTION_TPL));
    reference.setRootObj(this.rootObj, referencedCollection + "." + this.path);
    return reference.get(this.path);
  } else {
    throw new ReferenceException(String.format("There is no reference in \"%s\". Collection \"%s\"",
        this.path, this.collectionName));
  }
}

代码示例来源:origin: ru.sbtqa.tag.datajack.adaptors/json-adaptor

@Override
public TestDataProvider getReference() throws DataException {
  if (null != this.basicObj.get(VALUE_TPL) && !(this.basicObj.get(VALUE_TPL) instanceof String)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField(COLLECTION_TPL)
      && ((BasicDBObject) this.basicObj.get(VALUE_TPL)).containsField("path")) {
    if (this.rootObj == null) {
      this.rootObj = this.basicObj;
    } else {
      String rootJson = this.rootObj.toJson();
      String baseJson = this.basicObj.toJson();
      if (rootJson.equals(baseJson)) {
        throw new CyclicReferencesExeption("Cyclic references in database:\n" + rootJson);
      }
    }
    String referencedCollection = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString(COLLECTION_TPL);
    this.path = ((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString("path");
    JsonDataAdaptor reference = this.fromCollection(((BasicBSONObject) this.basicObj.get(VALUE_TPL)).getString(COLLECTION_TPL));
    reference.setRootObj(this.rootObj, referencedCollection + "." + this.path);
    return reference.get(this.path);
  } else {
    throw new ReferenceException(String.format("There is no reference in \"%s\". Collection \"%s\"",
        this.path, this.collectionName));
  }
}

相关文章