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

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

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

BSON.addEncodingHook介绍

[英]Registers a Transformer to use to encode a specific class into BSON.
[中]注册用于将特定类编码到BSON的转换器。

代码示例

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

private static <T> void hook(Class<T> type, Function<T, Object> fn) {
  BSON.addEncodingHook(type, o -> type.isInstance(o) ? fn.apply(type.cast(o)) : o);
}

代码示例来源:origin: org.ikasan/ikasan-mongo-endpoint

/**
 * Customise java to BSON encoding.
 */
private void addEncodingHooks()
{
  if (bsonEncodingTransformerMap != null)
  {
    for (Class<?> c : bsonEncodingTransformerMap.keySet())
    {
      List<Transformer> transformers = bsonEncodingTransformerMap.get(c);
      for(Transformer transformer : transformers){
        logger.debug(String.format("Adding bsonEncodingTransfomer [%1$s] for class [%2$s]", transformer, c));
        BSON.addEncodingHook(c, transformer);
      }
    }
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-support-mongo-core

BSON.addEncodingHook(ZonedDateTime.class, new BaseConverters.ZonedDateTimeTransformer());

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

public void register() {
    Unpickler.registerConstructor("bson.binary", "Binary",
     new com.mongodb.spark.pickle.BinaryConstructor());
    Unpickler.registerConstructor("bson.code", "Code",
     new com.mongodb.spark.pickle.CodeConstructor());
    Unpickler.registerConstructor("bson.dbref", "DBRef",
     new com.mongodb.spark.pickle.DBRefConstructor());
    Unpickler.registerConstructor("bson.int64", "Int64",
     new com.mongodb.spark.pickle.Int64Constructor());
    Unpickler.registerConstructor("bson.max_key", "MaxKey",
     new com.mongodb.spark.pickle.MaxKeyConstructor());
    Unpickler.registerConstructor("bson.min_key", "MinKey",
     new com.mongodb.spark.pickle.MinKeyConstructor());
    Unpickler.registerConstructor("bson.timestamp", "Timestamp",
     new com.mongodb.spark.pickle.TimestampConstructor());
    Unpickler.registerConstructor("bson.regex", "Regex",
     new com.mongodb.spark.pickle.RegexConstructor());
    Unpickler.registerConstructor("bson.objectid", "ObjectId",
     new com.mongodb.spark.pickle.ObjectIdConstructor());

    BSON.addEncodingHook(
     java.util.GregorianCalendar.class,
     new CalendarTransformer());
  }
}

相关文章