Source:
public void testSerDe() throws Exception { final Injector injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), ImmutableList.of( new Module() { @Override public void configure(Binder binder) { JsonConfigProvider.bindInstance( binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, new ServerConfig()) ); } } ) ); final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class)); mapper.registerSubtypes(NamespaceLookupExtractorFactory.class); final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }"; final LookupExtractorFactory factory = mapper.readValue(str, LookupExtractorFactory.class); Assert.assertTrue(factory instanceof NamespaceLookupExtractorFactory); final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = (NamespaceLookupExtractorFactory) factory; Assert.assertNotNull(mapper.writeValueAsString(factory)); Assert.assertFalse(factory.replaces(mapper.readValue( mapper.writeValueAsString(factory), LookupExtractorFactory.class ))); Assert.assertEquals( URIExtractionNamespace.class, namespaceLookupExtractorFactory.getExtractionNamespace().getClass() ); Assert.assertFalse(namespaceLookupExtractorFactory.replaces(mapper.readValue(str, LookupExtractorFactory.class))); final Map<String, Object> map = new HashMap<>(mapper.<Map<String, Object>>readValue( str, new TypeReference<Map<String, Object>>() { } )); map.put("firstCacheTimeout", "1"); Assert.assertTrue(namespaceLookupExtractorFactory.replaces(mapper.convertValue(map, LookupExtractorFactory.class))); }

Target:
public void testSerDe() throws Exception { final Injector injector = makeInjector(); final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class)); mapper.registerSubtypes(NamespaceLookupExtractorFactory.class); final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"uri\", \"uriPrefix\": \"s3://bucket/prefix/\", \"fileRegex\": \"foo.*\\\\.gz\", \"namespaceParseSpec\": { \"format\": \"customJson\", \"keyFieldName\": \"someKey\", \"valueFieldName\": \"someVal\" }, \"pollPeriod\": \"PT5M\" } } }"; final LookupExtractorFactory factory = mapper.readValue(str, LookupExtractorFactory.class); Assert.assertTrue(factory instanceof NamespaceLookupExtractorFactory); final NamespaceLookupExtractorFactory namespaceLookupExtractorFactory = (NamespaceLookupExtractorFactory) factory; Assert.assertNotNull(mapper.writeValueAsString(factory)); Assert.assertFalse(factory.replaces(mapper.readValue( mapper.writeValueAsString(factory), LookupExtractorFactory.class ))); Assert.assertEquals( UriExtractionNamespace.class, namespaceLookupExtractorFactory.getExtractionNamespace().getClass() ); Assert.assertFalse(namespaceLookupExtractorFactory.replaces(mapper.readValue(str, LookupExtractorFactory.class))); final Map<String, Object> map = new HashMap<>(mapper.<Map<String, Object>>readValue( str, new TypeReference<Map<String, Object>>() { } )); map.put("firstCacheTimeout", "1"); Assert.assertTrue(namespaceLookupExtractorFactory.replaces(mapper.convertValue(map, LookupExtractorFactory.class))); }