KangarooCustomTypesModule extends Module { @Override public void setupModule(final SetupContext context) { SimpleDeserializers des = new SimpleDeserializers(); des.addDeserializer(BigInteger.class, new Base16BigIntegerDeserializer()); des.addDeserializer(Calendar.class, new UnixTimestampDeserializer()); SimpleSerializers ser = new SimpleSerializers(); ser.addSerializer(BigInteger.class, new Base16BigIntegerSerializer()); ser.addSerializer(Calendar.class, new UnixTimestampSerializer()); context.addDeserializers(des); context.addSerializers(ser); } KangarooCustomTypesModule(); @Override String getModuleName(); @Override Version version(); @Override void setupModule(final SetupContext context);  }
@Test public void setupModule() throws Exception { KangarooCustomTypesModule module = new KangarooCustomTypesModule(); SetupContext c = mock(SetupContext.class); final ArgumentCaptor<Serializers> serializers = ArgumentCaptor.forClass(Serializers.class); final ArgumentCaptor<Deserializers> deserializers = ArgumentCaptor.forClass(Deserializers.class); module.setupModule(c); verify(c).addSerializers(serializers.capture()); verify(c).addDeserializers(deserializers.capture()); TypeFactory t = TypeFactory.defaultInstance(); JavaType bigIntegerType = t.constructType(BigInteger.class); JavaType calendarType = t.constructType(Calendar.class); SimpleSerializers s = (SimpleSerializers) serializers.getValue(); JsonSerializer byteSerializer = s.findSerializer(null, bigIntegerType, null); assertTrue(byteSerializer instanceof Base16BigIntegerSerializer); JsonSerializer calSerializer = s.findSerializer(null, calendarType, null); assertTrue(calSerializer instanceof UnixTimestampSerializer); SimpleDeserializers d = (SimpleDeserializers) deserializers.getValue(); JsonDeserializer byteDeserializer = d.findBeanDeserializer(bigIntegerType, null, null); assertTrue(byteDeserializer instanceof Base16BigIntegerDeserializer); JsonDeserializer calDeserializer = d.findBeanDeserializer(calendarType, null, null); assertTrue(calDeserializer instanceof UnixTimestampDeserializer); }