ObjectMapperModule implements com.google.inject.Module { public ObjectMapperModule registerModule(Module module) { modulesToAdd.add(module); return this; } ObjectMapperModule();  ObjectMapperModule(Class<? extends Annotation> annotation);  ObjectMapperModule(Annotation annotation);  ObjectMapperModule(Key<ObjectMapper> objectMapperKey); ObjectMapperModule in(Class<? extends Annotation> scopeAnnotation); ObjectMapperModule registerModule(Module module); ObjectMapperModule registerModule(Class<? extends Module> clazz); ObjectMapperModule registerModule(Class<? extends Module> clazz, Class<? extends Annotation> annotation); ObjectMapperModule registerModule(Class<? extends Module> clazz, Annotation annotation); ObjectMapperModule registerModule(Key<? extends Module> key); ObjectMapperModule withObjectMapper(ObjectMapper m); @Override void configure(Binder binder);  }
@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(Integer.valueOf(10)), "\"A\""); }
@Test public void testModulesRegisteredThroughInjection() throws Exception { final Injector injector = Guice.createInjector( new ObjectMapperModule().registerModule(IntegerAsBase16Module.class) ); final ObjectMapper mapper = injector.getInstance(ObjectMapper.class); Assert.assertEquals(mapper.writeValueAsString(Integer.valueOf(10)), "\"A\""); }
@Test public void testModulesRegisteredThroughInjectionWithAnnotation() throws Exception { final Injector injector = Guice.createInjector( new ObjectMapperModule().registerModule(IntegerAsBase16Module.class, Ann.class), new Module() { @Override public void configure(Binder binder) { binder.bind(IntegerAsBase16Module.class).annotatedWith(Ann.class).to(IntegerAsBase16Module.class); } } ); final ObjectMapper mapper = injector.getInstance(ObjectMapper.class); Assert.assertEquals(mapper.writeValueAsString(Integer.valueOf(10)), "\"A\""); }
@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(Integer.valueOf(10)), "\"A\""); }
@Test public void testModulesRegisteredThroughInjectionWithKey() throws Exception { final Injector injector = Guice.createInjector( new ObjectMapperModule().registerModule(Key.get(IntegerAsBase16Module.class)) ); final ObjectMapper mapper = injector.getInstance(ObjectMapper.class); Assert.assertEquals(mapper.writeValueAsString(Integer.valueOf(10)), "\"A\""); }