private DatabaseReader(Builder builder) throws IOException { if (builder.stream != null) { this.reader = new Reader(builder.stream); } else if (builder.database != null) { this.reader = new Reader(builder.database, builder.mode); } else { // This should never happen. If it does, review the Builder class // constructors for errors. throw new IllegalArgumentException("Unsupported Builder configuration: expected either File or URL"); } this.om = new ObjectMapper(); this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.om.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); InjectableValues inject = new InjectableValues.Std().addValue("locales", builder.locales); this.om.setInjectableValues(inject); }
private DatabaseReader(final Builder builder) throws IOException { if (builder.stream != null) { this.reader = new Reader(builder.stream); } else if (builder.database != null) { this.reader = new Reader(builder.database, builder.mode); } else { // This should never happen. If it does, review the Builder class // constructors for errors. throw new IllegalArgumentException("Unsupported Builder configuration: expected either File or URL"); } this.om = new ObjectMapper(); this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); this.om.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); InjectableValues inject = new InjectableValues.Std().addValue("locales", builder.locales); this.om.setInjectableValues(inject); this.locales = builder.locales; }
public static ObjectMapper makeSmileMapper() { final ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std() .addValue(ExprMacroTable.class.getName(), TestExprMacroTable.INSTANCE) .addValue(ObjectMapper.class.getName(), mapper) ); return mapper; }
public static ObjectMapper makeJsonMapper() { final ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std() .addValue(ExprMacroTable.class.getName(), TestExprMacroTable.INSTANCE) .addValue(ObjectMapper.class.getName(), mapper) .addValue(DataSegment.PruneLoadSpecHolder.class, DataSegment.PruneLoadSpecHolder.DEFAULT) ); return mapper; }
@Before public void setUp() { InjectableValues.Std injectableValues = new InjectableValues.Std(); injectableValues.addValue(DataSegment.PruneLoadSpecHolder.class, DataSegment.PruneLoadSpecHolder.DEFAULT); mapper.setInjectableValues(injectableValues); }
private void setupJackson(Injector injector, final ObjectMapper mapper) { final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); mapper.setInjectableValues(new GuiceInjectableValues(injector)); mapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector()) ); } }
public DruidNodeTest() { mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std() .addValue(Integer.class, Integer.MAX_VALUE) .addValue(String.class, "DUMMY") ); }
@Test public void testSerde() throws Exception { final ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues() { @Override public Object findInjectableValue( Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1 ) { return null; } } ); final EC2AutoScaler autoScaler = (EC2AutoScaler) objectMapper.readValue(json, AutoScaler.class); verifyAutoScaler(autoScaler); final EC2AutoScaler roundTripAutoScaler = (EC2AutoScaler) objectMapper.readValue( objectMapper.writeValueAsBytes(autoScaler), AutoScaler.class ); verifyAutoScaler(roundTripAutoScaler); Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler); }
mapper.setInjectableValues( new InjectableValues.Std().addValue( IndexIO.class,
@Test public void testSerde() throws Exception { ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, JavaScriptConfig.getEnabledInstance() ) ); Assert.assertEquals( STRATEGY, mapper.readValue( mapper.writeValueAsString(STRATEGY), WorkerSelectStrategy.class ) ); }
@Test public void testSerde() throws Exception { ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, JavaScriptConfig.getEnabledInstance() ) ); Assert.assertEquals( STRATEGY, mapper.readValue( mapper.writeValueAsString(STRATEGY), JavaScriptTieredBrokerSelectorStrategy.class ) ); }
@Test public void testDisabled() throws Exception { ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, new JavaScriptConfig(false) ) ); final String strategyString = mapper.writeValueAsString(STRATEGY); expectedException.expect(JsonMappingException.class); expectedException.expectCause(CoreMatchers.instanceOf(IllegalStateException.class)); expectedException.expectMessage("JavaScript is disabled"); mapper.readValue(strategyString, JavaScriptTieredBrokerSelectorStrategy.class); }
@Test public void testDisabled() throws Exception { ObjectMapper mapper = new DefaultObjectMapper(); mapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, new JavaScriptConfig(false) ) ); final String strategyString = mapper.writeValueAsString(STRATEGY); expectedException.expect(JsonMappingException.class); expectedException.expectCause(CoreMatchers.instanceOf(IllegalStateException.class)); expectedException.expectMessage("JavaScript is disabled"); mapper.readValue(strategyString, WorkerSelectStrategy.class); }
@Test public void testSerde() throws Exception { final ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, JavaScriptConfig.getEnabledInstance() ) ); final String json = "{ \"type\" : \"javascript\", \"function\" : \"function(str) { return str.substring(0,3); }\" }"; JavaScriptExtractionFn extractionFn = (JavaScriptExtractionFn) objectMapper.readValue(json, ExtractionFn.class); Assert.assertEquals("function(str) { return str.substring(0,3); }", extractionFn.getFunction()); // round trip Assert.assertEquals( extractionFn, objectMapper.readValue( objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class ) ); }
private static ObjectMapper setupInjectablesInObjectMapper(ObjectMapper objectMapper) { final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector() ), new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector() ) ); GuiceInjectableValues injectableValues = new GuiceInjectableValues( GuiceInjectors.makeStartupInjectorWithModules( ImmutableList.of( binder -> { binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER); binder.bind(ChatHandlerProvider.class).toInstance(new NoopChatHandlerProvider()); binder.bind(RowIngestionMetersFactory.class).toInstance(rowIngestionMetersFactory); } ) ) ); objectMapper.setInjectableValues(injectableValues); objectMapper.registerModule( new SimpleModule().registerSubtypes(new NamedType(NumberedShardSpec.class, "NumberedShardSpec")) ); return objectMapper; }
public SegmentLoaderLocalCacheManagerTest(SegmentWriteOutMediumFactory segmentWriteOutMediumFactory) { jsonMapper = new DefaultObjectMapper(); jsonMapper.registerSubtypes(new NamedType(LocalLoadSpec.class, "local")); jsonMapper.setInjectableValues( new InjectableValues.Std().addValue( LocalDataSegmentPuller.class, new LocalDataSegmentPuller() ) ); this.segmentWriteOutMediumFactory = segmentWriteOutMediumFactory; }
objectMapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class,
objectMapper.setInjectableValues( new GuiceInjectableValues( GuiceInjectors.makeStartupInjectorWithModules(
@BeforeClass public static void setUp() { final Injector injector = GuiceInjectors.makeStartupInjectorWithModules( ImmutableList.of( new Module() { @Override public void configure(Binder binder) { binder.bind(LocalDataSegmentPuller.class); } } ) ); mapper = new DefaultObjectMapper(); mapper.registerModule(new SimpleModule("loadSpecTest").registerSubtypes(LocalLoadSpec.class)); mapper.setInjectableValues(new GuiceInjectableValues(injector)); final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); mapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector()) ); }
@Test public void testSerde() throws IOException { jsonMapper.setInjectableValues( new InjectableValues.Std().addValue( JavaScriptConfig.class, JavaScriptConfig.getEnabledInstance() ) ); JavaScriptParseSpec spec = new JavaScriptParseSpec( new TimestampSpec("abc", "iso", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Collections.singletonList("abc")), null, null), "abc", JavaScriptConfig.getEnabledInstance() ); final JavaScriptParseSpec serde = (JavaScriptParseSpec) jsonMapper.readValue( jsonMapper.writeValueAsString(spec), ParseSpec.class ); Assert.assertEquals("abc", serde.getTimestampSpec().getTimestampColumn()); Assert.assertEquals("iso", serde.getTimestampSpec().getTimestampFormat()); Assert.assertEquals("abc", serde.getFunction()); Assert.assertEquals(Collections.singletonList("abc"), serde.getDimensionsSpec().getDimensionNames()); }