org.bson.BSON.applyEncodingHooks()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(207)

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

BSON.applyEncodingHooks介绍

[英]Transforms the objectToEncode using all transformers registered for the class of this object.
[中]使用为此对象的类注册的所有转换器将objectToEncode转换。

代码示例

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

@SuppressWarnings("unchecked")
private void writeValue(final BsonWriter bsonWriter, final EncoderContext encoderContext, final Object initialValue) {
  Object value = org.bson.BSON.applyEncodingHooks(initialValue);
  if (value == null) {
    bsonWriter.writeNull();
  } else if (value instanceof DBRef) {
    encodeDBRef(bsonWriter, (DBRef) value);
  } else if (value instanceof Map) {
    encodeMap(bsonWriter, (Map<String, Object>) value);
  } else if (value instanceof Iterable) {
    encodeIterable(bsonWriter, (Iterable) value);
  } else if (value instanceof BSONObject) {
    encodeBsonObject(bsonWriter, ((BSONObject) value));
  } else if (value instanceof CodeWScope) {
    encodeCodeWScope(bsonWriter, (CodeWScope) value);
  } else if (value instanceof byte[]) {
    encodeByteArray(bsonWriter, (byte[]) value);
  } else if (value.getClass().isArray()) {
    encodeArray(bsonWriter, value);
  } else if (value instanceof Symbol) {
    bsonWriter.writeSymbol(((Symbol) value).getSymbol());
  } else {
    Codec codec = codecRegistry.get(value.getClass());
    codec.encode(bsonWriter, value, encoderContext);
  }
}

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

Object value = BSON.applyEncodingHooks(initialValue);

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

/**
 * 
 * @param obj
 *            the object to be serialized
 * @param buf
 *            StringBuilder containing the JSON representation of the object
 */
//@Override
public void serialize(Object obj, StringBuilder buf) {
  obj = BSON.applyEncodingHooks(obj);
  if (obj == null) {
    buf.append(" null ");
    return;
  }
  ObjectSerializer serializer = null;
  List<Class<?>> ancestors;
  ancestors = ClassMap.getAncestry(obj.getClass());
  for (final Class<?> ancestor : ancestors) {
    serializer = _serializers.get(ancestor);
    if (serializer != null) break;
  }
  if (serializer == null && obj.getClass().isArray()) serializer = _serializers.get(Object[].class);
  if (serializer == null) throw new RuntimeException("json can't serialize type : " + obj.getClass());
  serializer.serialize(obj, buf);
}

代码示例来源:origin: com.foursquare/fongo

public Object replaceListAndMap(Object value) {
 Object replacementValue = BSON.applyEncodingHooks(value);
 if (replacementValue instanceof DBObject) {
  replacementValue = filterLists((DBObject) replacementValue);
 } else if (replacementValue instanceof List) {
  BasicDBList list = new BasicDBList();
  for (Object listItem : (List) replacementValue) {
   list.add(replaceListAndMap(listItem));
  }
  replacementValue = list;
 } else if (replacementValue instanceof Object[]) {
  BasicDBList list = new BasicDBList();
  for (Object listItem : (Object[]) replacementValue) {
   list.add(replaceListAndMap(listItem));
  }
  replacementValue = list;
 } else if (replacementValue instanceof Map) {
  BasicDBObject newDbo = new BasicDBObject();
  for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) ((Map) replacementValue).entrySet()) {
   newDbo.put(entry.getKey(), replaceListAndMap(entry.getValue()));
  }
  replacementValue = newDbo;
 }
 return replacementValue;
}

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

@SuppressWarnings("unchecked")
private void writeValue(final BsonWriter bsonWriter, final EncoderContext encoderContext, final Object initialValue) {
  Object value = org.bson.BSON.applyEncodingHooks(initialValue);
  if (value == null) {
    bsonWriter.writeNull();
  } else if (value instanceof DBRef) {
    encodeDBRef(bsonWriter, (DBRef) value);
  } else if (value instanceof Map) {
    encodeMap(bsonWriter, (Map<String, Object>) value);
  } else if (value instanceof Iterable) {
    encodeIterable(bsonWriter, (Iterable) value);
  } else if (value instanceof BSONObject) {
    encodeBsonObject(bsonWriter, ((BSONObject) value));
  } else if (value instanceof CodeWScope) {
    encodeCodeWScope(bsonWriter, (CodeWScope) value);
  } else if (value instanceof byte[]) {
    encodeByteArray(bsonWriter, (byte[]) value);
  } else if (value.getClass().isArray()) {
    encodeArray(bsonWriter, value);
  } else if (value instanceof Symbol) {
    bsonWriter.writeSymbol(((Symbol) value).getSymbol());
  } else {
    Codec codec = codecRegistry.get(value.getClass());
    codec.encode(bsonWriter, value, encoderContext);
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

val = BSON.applyEncodingHooks(val);

代码示例来源:origin: Aresyi/smart-api

this._putValueString(val.toString());
} else {
  val = BSON.applyEncodingHooks(val);
  if(val == null || "null".equals(val)) {
    this.putNull(name);

相关文章