Search in sources :

Example 11 with ObjectMapperModule

use of com.fasterxml.jackson.module.guice.ObjectMapperModule in project api-core by ca-cwds.

the class ObjectMapperModuleTest method testModulesRegisteredThroughInjectionWithAnnotation.

@Test
public void testModulesRegisteredThroughInjectionWithAnnotation() throws Exception {
    final Injector injector = Guice.createInjector(new ObjectMapperModule().registerModule(IntegerAsBase16Module.class, SystemCodeSerializer.class), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(IntegerAsBase16Module.class).annotatedWith(SystemCodeSerializer.class).to(IntegerAsBase16Module.class);
        }
    });
    final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    Assert.assertEquals(mapper.writeValueAsString(new Integer(10)), "\"A\"");
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) BigInteger(java.math.BigInteger) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) SystemCodeSerializer(gov.ca.cwds.data.SystemCodeSerializer) Module(com.google.inject.Module) ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with ObjectMapperModule

use of com.fasterxml.jackson.module.guice.ObjectMapperModule in project embulk by embulk.

the class ExecModule method configure.

@Override
public void configure(Binder binder) {
    Preconditions.checkNotNull(binder, "binder is null.");
    binder.bind(BulkLoader.class);
    binder.bind(ILoggerFactory.class).toProvider(LoggerProvider.class).in(Scopes.SINGLETON);
    binder.bind(ModelManager.class).in(Scopes.SINGLETON);
    binder.bind(BufferAllocator.class).to(PooledBufferAllocator.class).in(Scopes.SINGLETON);
    binder.bind(TempFileAllocator.class).in(Scopes.SINGLETON);
    // GuessExecutor, PreviewExecutor
    registerPluginTo(binder, ParserPlugin.class, "system_guess", GuessExecutor.GuessParserPlugin.class);
    registerPluginTo(binder, ParserPlugin.class, "system_sampling", SamplingParserPlugin.class);
    // LocalExecutorPlugin
    registerPluginTo(binder, ExecutorPlugin.class, "local", LocalExecutorPlugin.class);
    // serde
    ObjectMapperModule mapper = new ObjectMapperModule();
    DateTimeZoneSerDe.configure(mapper);
    TimestampSerDe.configure(mapper);
    CharsetSerDe.configure(mapper);
    LocalFileSerDe.configure(mapper);
    // jackson-datatype-guava
    mapper.registerModule(new GuavaModule());
    // jackson-datatype-joda
    mapper.registerModule(new JodaModule());
    mapper.configure(binder);
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ModelManager(org.embulk.config.ModelManager) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Aggregations

ObjectMapperModule (com.fasterxml.jackson.module.guice.ObjectMapperModule)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Injector (com.google.inject.Injector)11 BigInteger (java.math.BigInteger)6 Test (org.junit.Test)6 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 Binder (com.google.inject.Binder)4 Module (com.google.inject.Module)3 DruidModule (org.apache.druid.initialization.DruidModule)3 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)3 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 Module (com.fasterxml.jackson.databind.Module)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 ImmutableList (com.google.common.collect.ImmutableList)1 Provides (com.google.inject.Provides)1 SystemCodeSerializer (gov.ca.cwds.data.SystemCodeSerializer)1 List (java.util.List)1 ModelManager (org.embulk.config.ModelManager)1