Java Code Examples for com.mongodb.MongoClientSettings#getDefaultCodecRegistry()

The following examples show how to use com.mongodb.MongoClientSettings#getDefaultCodecRegistry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregationQuery.java    From immutables with Apache License 2.0 7 votes vote down vote up
AggregationQuery(Query query, PathNaming pathNaming) {
  this.query = maybeRewriteDistinctToGroupBy(query);
  this.pathNaming = Objects.requireNonNull(pathNaming, "naming");

  BiMap<Expression, String> biMap = HashBiMap.create();

  List<Path> paths = Stream.concat(query.projections().stream(), Stream.concat(query.groupBy().stream(), query.collations().stream().map(Collation::expression)))
          .map(AggregationQuery::extractPath).collect(Collectors.toList());

  @SuppressWarnings("unchecked")
  ExpressionNaming naming = ExpressionNaming.from(UniqueCachedNaming.of(paths.iterator()));
  paths.forEach(p -> biMap.put(p, naming.name(p)));

  this.projectionNaming = ExpressionNaming.from(UniqueCachedNaming.of(query.projections()));
  this.naming = ImmutableBiMap.copyOf(biMap);
  this.codecRegistry = MongoClientSettings.getDefaultCodecRegistry();
}
 
Example 2
Source File: BsonLogParamTest.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
@Test
void append() {
    var param = new BsonLogParam(Filters.eq("field", "value"), MongoClientSettings.getDefaultCodecRegistry());
    var builder = new StringBuilder();
    param.append(builder, Set.of(), 1000);
    assertThat(builder.toString()).isEqualTo("{\"field\": \"value\"}");
}
 
Example 3
Source File: Parsers.java    From immutables with Apache License 2.0 5 votes vote down vote up
static BsonParser createParser(BsonDocument bson) {
  BasicOutputBuffer buffer = new BasicOutputBuffer();
  CodecRegistry registry = MongoClientSettings.getDefaultCodecRegistry();
  registry.get(BsonDocument.class)
          .encode(new BsonBinaryWriter(buffer), bson, EncoderContext.builder().build());

  BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(buffer.toByteArray()));
  IOContext ioContext = new IOContext(new BufferRecycler(), null, false);
  return new BsonParser(ioContext, 0, reader);
}