com.mongodb.util.JSON.serialize()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(220)

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

JSON.serialize介绍

[英]Serializes an object into its JSON form.

This method delegates serialization to JSONSerializers.getLegacy
[中]将对象序列化为其JSON格式。
此方法将序列化委托给JSONSerializer。获得遗产

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

@Override
  public String encode(CodecRegistryProvider provider, boolean quoted) {
    return JSON.serialize(this.value);
  }
}

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

/**
   * Returns a JSON serialization of this object
   *
   * @return JSON serialization
   */
  @SuppressWarnings("deprecation")
  public String toString() {
    return com.mongodb.util.JSON.serialize(this);
  }
}

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

@Override
@SuppressWarnings("deprecation")
public String toString() {
  return com.mongodb.util.JSON.serialize(this);
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

@Override
public String toString() {
  return "Timestamp.BSON(ts=" + JSON.serialize(ts) + ")";
}

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

/**
   * Returns a JSON serialization of this object
   *
   * @return JSON serialization
   */
  @SuppressWarnings("deprecation")
  public String toString() {
    return com.mongodb.util.JSON.serialize(this);
  }
}

代码示例来源:origin: spring-projects/spring-batch

private String getParameterWithIndex(List<Object> values, int index) {
  return JSON.serialize(values.get(index));
}

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

/**
 * <p>Serializes an object into its JSON form.</p>
 *
 * <p>This method delegates serialization to {@code JSONSerializers.getLegacy}</p>
 *
 * @param object object to serialize
 * @return String containing JSON form of the object
 * @see JSONSerializers#getLegacy()
 */
public static String serialize(final Object object) {
  StringBuilder buf = new StringBuilder();
  serialize(object, buf);
  return buf.toString();
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

@Override
  public void saveFields(XContentBuilder builder) throws IOException {
    builder.field(MongoDBRiver.LAST_TIMESTAMP_FIELD, JSON.serialize(ts));
  }
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

@Override
public String toString() {
  return "Timestamp.GTID(ts=" + JSON.serialize(ts) + ", gtid=" + JSONSerializers.getStrict().serialize(gtid) + ")";
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Serializes the given object into pseudo-JSON meaning it's trying to create a JSON representation as far as possible
 * but falling back to the given object's {@link Object#toString()} method if it's not serializable. Useful for
 * printing raw {@link Document}s containing complex values before actually converting them into Mongo native types.
 *
 * @param value
 * @return the serialized value or {@literal null}.
 */
@Nullable
public static String serializeToJsonSafely(@Nullable Object value) {
  if (value == null) {
    return null;
  }
  try {
    return value instanceof Document ? ((Document) value).toJson() : JSON.serialize(value);
  } catch (Exception e) {
    if (value instanceof Collection) {
      return toString((Collection<?>) value);
    } else if (value instanceof Map) {
      return toString((Map<?, ?>) value);
    } else {
      return String.format("{ \"$java\" : %s }", value.toString());
    }
  }
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

@Override
  public void saveFields(XContentBuilder builder) throws IOException {
    builder.field(MongoDBRiver.LAST_TIMESTAMP_FIELD, JSON.serialize(ts));
    builder.field(MongoDBRiver.LAST_GTID_FIELD, JSONSerializers.getStrict().serialize(gtid));
  }
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Returns the serialized value to be used for the given {@link ParameterBinding}.
 *
 * @param accessor must not be {@literal null}.
 * @param parameters
 * @param binding must not be {@literal null}.
 * @return
 */
@SuppressWarnings("unchecked")
private String getParameterValueForBinding(MongoParameterAccessor accessor, MongoParameters parameters,
    ParameterBinding binding) {
  Object value = binding.isExpression()
      ? evaluateExpression(binding.getExpression(), parameters, accessor.getValues())
      : accessor.getBindableValue(binding.getParameterIndex());
  if (value instanceof String && binding.isQuoted()) {
    if (binding.isExpression() && ((String) value).startsWith("{")) {
      return (String) value;
    }
    return binding.isExpression() ? JSON.serialize(value) : QuotedString.unquote(JSON.serialize(value));
  }
  return EncodableValue.create(value).encode(codecRegistryProvider, binding.isQuoted());
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

@Override
  public String encode(CodecRegistryProvider provider, boolean quoted) {
    return JSON.serialize(this.value);
  }
}

代码示例来源:origin: geotools/geotools

@Override
public void storeSchema(SimpleFeatureType schema) throws IOException {
  if (schema == null) {
    return;
  }
  File schemaFile = schemaFile(schema.getTypeName());
  BufferedWriter writer = new BufferedWriter(new FileWriter(schemaFile));
  try {
    writer.write(JSON.serialize(FeatureTypeDBObject.convert(schema)));
  } finally {
    writer.close();
  }
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Serializes the given object into pseudo-JSON meaning it's trying to create a JSON representation as far as possible
 * but falling back to the given object's {@link Object#toString()} method if it's not serializable. Useful for
 * printing raw {@link Document}s containing complex values before actually converting them into Mongo native types.
 *
 * @param value
 * @return the serialized value or {@literal null}.
 */
@Nullable
public static String serializeToJsonSafely(@Nullable Object value) {
  if (value == null) {
    return null;
  }
  try {
    return value instanceof Document ? ((Document) value).toJson() : JSON.serialize(value);
  } catch (Exception e) {
    if (value instanceof Collection) {
      return toString((Collection<?>) value);
    } else if (value instanceof Map) {
      return toString((Map<?, ?>) value);
    } else {
      return String.format("{ \"$java\" : %s }", value.toString());
    }
  }
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Returns the serialized value to be used for the given {@link ParameterBinding}.
 *
 * @param accessor must not be {@literal null}.
 * @param parameters
 * @param binding must not be {@literal null}.
 * @return
 */
@SuppressWarnings("unchecked")
private String getParameterValueForBinding(MongoParameterAccessor accessor, MongoParameters parameters,
    ParameterBinding binding) {
  Object value = binding.isExpression()
      ? evaluateExpression(binding.getExpression(), parameters, accessor.getValues())
      : accessor.getBindableValue(binding.getParameterIndex());
  if (value instanceof String && binding.isQuoted()) {
    if (binding.isExpression() && ((String) value).startsWith("{")) {
      return (String) value;
    }
    return binding.isExpression() ? JSON.serialize(value) : QuotedString.unquote(JSON.serialize(value));
  }
  return EncodableValue.create(value).encode(codecRegistryProvider, binding.isQuoted());
}

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

/**
   * Returns a JSON serialization of this object
   *
   * @return JSON serialization
   */
  @SuppressWarnings("deprecation")
  public String toString() {
    return com.mongodb.util.JSON.serialize(this);
  }
}

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

@Override
@SuppressWarnings("deprecation")
public String toString() {
  return com.mongodb.util.JSON.serialize(this);
}

代码示例来源:origin: restx/restx

@Override
  public String map(DBObject result) {
    return JSON.serialize(result);
  }
});

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

public String toJSON() {
  BasicDBList returnVal = new BasicDBList();
  for (CollectionSplitterConf conf : collectionSplitters) {
    returnVal.add(new BasicDBObject(conf.toConfigMap()));
  }
  return JSON.serialize(returnVal);
}

相关文章