Search in sources :

Example 6 with ObjectMapperModule

use of com.fasterxml.jackson.module.guice.ObjectMapperModule in project druid by druid-io.

the class StaticAzureBlobStoreFirehoseFactoryTest method createObjectMapper.

private static ObjectMapper createObjectMapper(DruidModule baseModule) {
    final ObjectMapper baseMapper = new DefaultObjectMapper();
    baseModule.getJacksonModules().forEach(baseMapper::registerModule);
    final Injector injector = Guice.createInjector(new ObjectMapperModule(), baseModule);
    return injector.getInstance(ObjectMapper.class);
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) Injector(com.google.inject.Injector) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper)

Example 7 with ObjectMapperModule

use of com.fasterxml.jackson.module.guice.ObjectMapperModule in project druid by druid-io.

the class GoogleCloudStorageInputSourceTest method createGoogleObjectMapper.

public static ObjectMapper createGoogleObjectMapper() {
    final DruidModule baseModule = new TestGoogleModule();
    final ObjectMapper baseMapper = new DefaultObjectMapper();
    baseModule.getJacksonModules().forEach(baseMapper::registerModule);
    final Injector injector = Guice.createInjector(new ObjectMapperModule(), baseModule);
    return injector.getInstance(ObjectMapper.class);
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) Injector(com.google.inject.Injector) DruidModule(org.apache.druid.initialization.DruidModule) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper)

Example 8 with ObjectMapperModule

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

the class ObjectMapperModuleTest method testJacksonInjectThroughGuice.

@Test
public void testJacksonInjectThroughGuice() throws Exception {
    final Injector injector = Guice.createInjector(new ObjectMapperModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(Integer.class).toInstance(1);
            // guice based named injection
            binder.bind(Integer.class).annotatedWith(Names.named("two")).toInstance(2);
            binder.bind(Integer.class).annotatedWith(SystemCodeSerializer.class).toInstance(3);
            // javax based named injection
            binder.bind(Integer.class).annotatedWith(Names.named("five")).toInstance(5);
            // guice based method injection
            binder.bind(Integer.class).annotatedWith(Names.named("six")).toInstance(6);
            // javax based method injection
            binder.bind(Integer.class).annotatedWith(Names.named("seven")).toInstance(7);
            // test other method injections (need different keys, so use Long
            binder.bind(Long.class).annotatedWith(SystemCodeSerializer.class).toInstance(8L);
            binder.bind(Long.class).toInstance(9L);
        }
    });
    final ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
    mapper.readValue("{\"four\": 4}", SomeBean.class).verify();
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) BigInteger(java.math.BigInteger) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) 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 9 with ObjectMapperModule

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

the class ObjectMapperModuleTest method testModulesRegisteredThroughNormalInstantiation.

@Test
public void testModulesRegisteredThroughNormalInstantiation() throws Exception {
    final Injector injector = Guice.createInjector(new ObjectMapperModule().registerModule(new IntegerAsBase16Module()));
    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) Injector(com.google.inject.Injector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with ObjectMapperModule

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

the class ObjectMapperModuleTest method testModulesRegisteredThroughInjectionWithNameAnnotation.

@Test
public void testModulesRegisteredThroughInjectionWithNameAnnotation() throws Exception {
    final Injector injector = Guice.createInjector(new ObjectMapperModule().registerModule(IntegerAsBase16Module.class, Names.named("billy")), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(IntegerAsBase16Module.class).annotatedWith(Names.named("billy")).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) 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)

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