org.bson.codecs.configuration.CodecProvider Java Examples

The following examples show how to use org.bson.codecs.configuration.CodecProvider. 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: MongoClientProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
CodecProviderBuildItem collectCodecProviders(CombinedIndexBuildItem indexBuildItem) {
    Collection<ClassInfo> codecProviderClasses = indexBuildItem.getIndex()
            .getAllKnownImplementors(DotName.createSimple(CodecProvider.class.getName()));
    List<String> names = codecProviderClasses.stream().map(ci -> ci.name().toString()).collect(Collectors.toList());
    return new CodecProviderBuildItem(names);
}
 
Example #2
Source File: MongoClients.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private List<CodecProvider> getCodecProviders(List<String> classNames) {
    List<CodecProvider> providers = new ArrayList<>();
    for (String name : classNames) {
        try {
            Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(name);
            Constructor clazzConstructor = clazz.getConstructor();
            providers.add((CodecProvider) clazzConstructor.newInstance());
        } catch (Exception e) {
            LOGGER.warnf(e, "Unable to load the codec provider class %s", name);
        }
    }

    return providers;
}
 
Example #3
Source File: MongoMapperTest.java    From mongo-mapper with Apache License 2.0 5 votes vote down vote up
@Test
public void testMongoMapper() throws Exception {
    List<CodecProvider> providers = MongoMapper.getProviders();
    Assert.assertFalse(providers.isEmpty());

    int size = providers.size();
    // Check for unmodifiable list.
    providers.add(new CustomFieldCodecProvider());

    MongoMapper.addProvider(new CustomFieldCodecProvider());
    providers = MongoMapper.getProviders();
    Assert.assertEquals(size + 1, providers.size());
}
 
Example #4
Source File: MongoMapper.java    From mongo-mapper with Apache License 2.0 4 votes vote down vote up
public static List<CodecProvider> getProviders() {
    return (ArrayList) providers.clone();
}
 
Example #5
Source File: MongoMapper.java    From mongo-mapper with Apache License 2.0 4 votes vote down vote up
public static void addProvider(CodecProvider provider) {
    providers.add(provider);
}
 
Example #6
Source File: JacksonCodecs.java    From immutables with Apache License 2.0 4 votes vote down vote up
/**
 * Create module from existing provider
 */
public static Module module(CodecProvider provider) {
  return module(CodecRegistries.fromProviders(provider));
}