Search in sources :

Example 21 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class RegisteredLookupExtractionFnTest method testSerDe.

@Test
public void testSerDe() throws Exception {
    final ObjectMapper mapper = new DefaultObjectMapper();
    final LookupExtractorFactoryContainerProvider manager = EasyMock.createStrictMock(LookupReferencesManager.class);
    managerReturnsMap(manager);
    EasyMock.replay(manager);
    final RegisteredLookupExtractionFn fn = new RegisteredLookupExtractionFn(manager, LOOKUP_NAME, true, null, true, false);
    EasyMock.verify(manager);
    final Map<String, Object> result = mapper.readValue(mapper.writeValueAsString(fn), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
    Assert.assertEquals(mapper.convertValue(fn, JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT), result);
    Assert.assertEquals(LOOKUP_NAME, result.get("lookup"));
    Assert.assertEquals(true, result.get("retainMissingValue"));
    Assert.assertEquals(true, result.get("injective"));
    Assert.assertNull(result.get("replaceMissingValueWith"));
    Assert.assertEquals(false, result.get("optimize"));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 22 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class MapLookupExtractorFactoryTest method testSerDeserMapLookupExtractorFactory.

@Test
public void testSerDeserMapLookupExtractorFactory() throws IOException {
    ObjectMapper mapper = new DefaultObjectMapper();
    mapper.registerSubtypes(MapLookupExtractorFactory.class);
    LookupExtractorFactory lookupExtractorFactory = new MapLookupExtractorFactory(ImmutableMap.of("key", "value"), true);
    Assert.assertEquals(lookupExtractorFactory, mapper.readerFor(LookupExtractorFactory.class).readValue(mapper.writeValueAsString(lookupExtractorFactory)));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 23 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class LookupDimensionSpecTest method testSerDesr.

@Parameters
@Test
public void testSerDesr(DimensionSpec lookupDimSpec) throws IOException {
    ObjectMapper mapper = new DefaultObjectMapper();
    mapper.registerSubtypes(new NamedType(LookupDimensionSpec.class, "lookup"));
    InjectableValues injectableValues = new InjectableValues.Std().addValue(LookupExtractorFactoryContainerProvider.class, LOOKUP_REF_MANAGER);
    String serLookup = mapper.writeValueAsString(lookupDimSpec);
    Assert.assertEquals(lookupDimSpec, mapper.readerFor(DimensionSpec.class).with(injectableValues).readValue(serLookup));
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 24 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class LoadSpecTest method setUp.

@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()));
}
Also used : AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) GuiceAnnotationIntrospector(org.apache.druid.guice.GuiceAnnotationIntrospector) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) GuiceInjectableValues(org.apache.druid.guice.GuiceInjectableValues) BeforeClass(org.junit.BeforeClass)

Example 25 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class IntervalLoadRuleTest method testSerde.

@Test
public void testSerde() throws Exception {
    IntervalLoadRule rule = new IntervalLoadRule(Intervals.of("0/3000"), ImmutableMap.of(DruidServer.DEFAULT_TIER, 2));
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    Rule reread = jsonMapper.readValue(jsonMapper.writeValueAsString(rule), Rule.class);
    Assert.assertEquals(rule, reread);
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)287 Test (org.junit.Test)245 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)177 File (java.io.File)26 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)25 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)21 Before (org.junit.Before)21 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)20 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)16 DataSegment (org.apache.druid.timeline.DataSegment)16 Period (org.joda.time.Period)16 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)14 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)13 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)12 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)11 TaskStatus (org.apache.druid.indexer.TaskStatus)11 AvroStreamInputRowParserTest (org.apache.druid.data.input.AvroStreamInputRowParserTest)10 ImmutableList (com.google.common.collect.ImmutableList)9 Injector (com.google.inject.Injector)9 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)9