Search in sources :

Example 6 with Std

use of com.fasterxml.jackson.databind.InjectableValues.Std in project druid by druid-io.

the class HttpInputSourceTest method testSerde.

@Test
public void testSerde() throws IOException {
    HttpInputSourceConfig httpInputSourceConfig = new HttpInputSourceConfig(null);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setInjectableValues(new Std().addValue(HttpInputSourceConfig.class, httpInputSourceConfig));
    final HttpInputSource source = new HttpInputSource(ImmutableList.of(URI.create("http://test.com/http-test")), "myName", new DefaultPasswordProvider("myPassword"), httpInputSourceConfig);
    final byte[] json = mapper.writeValueAsBytes(source);
    final HttpInputSource fromJson = (HttpInputSource) mapper.readValue(json, InputSource.class);
    Assert.assertEquals(source, fromJson);
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) InputSource(org.apache.druid.data.input.InputSource) DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with Std

use of com.fasterxml.jackson.databind.InjectableValues.Std in project druid by druid-io.

the class ShardSpecTestUtils method initObjectMapper.

public static ObjectMapper initObjectMapper() {
    // Copied configurations from org.apache.druid.jackson.DefaultObjectMapper
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper));
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    // See https://github.com/FasterXML/jackson-databind/issues/170
    // configure(MapperFeature.AUTO_DETECT_CREATORS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    mapper.configure(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
    mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
    return mapper;
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with Std

use of com.fasterxml.jackson.databind.InjectableValues.Std in project druid by druid-io.

the class SingleDimensionRangeBucketShardSpecTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final ObjectMapper mapper = ShardSpecTestUtils.initObjectMapper();
    mapper.registerSubtypes(new NamedType(SingleDimensionRangeBucketShardSpec.class, ShardSpec.Type.BUCKET_SINGLE_DIM));
    mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper));
    final SingleDimensionRangeBucketShardSpec original = new SingleDimensionRangeBucketShardSpec(1, "dim", "start", "end");
    final String json = mapper.writeValueAsString(original);
    ShardSpec shardSpec = mapper.readValue(json, ShardSpec.class);
    Assert.assertEquals(ShardSpec.Type.BUCKET_SINGLE_DIM, shardSpec.getType());
    final SingleDimensionRangeBucketShardSpec fromJson = (SingleDimensionRangeBucketShardSpec) shardSpec;
    Assert.assertEquals(original, fromJson);
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with Std

use of com.fasterxml.jackson.databind.InjectableValues.Std in project druid by druid-io.

the class BuildingDimensionRangeShardSpecTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final ObjectMapper mapper = ShardSpecTestUtils.initObjectMapper();
    mapper.registerSubtypes(new NamedType(BuildingDimensionRangeShardSpec.class, ShardSpec.Type.BUILDING_RANGE));
    mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper));
    final BuildingDimensionRangeShardSpec original = new BuildingDimensionRangeShardSpec(1, Arrays.asList("dim1", "dim2"), StringTuple.create("start1", "start2"), StringTuple.create("end1", "end2"), 5);
    final String json = mapper.writeValueAsString(original);
    ShardSpec shardSpec = mapper.readValue(json, ShardSpec.class);
    Assert.assertEquals(ShardSpec.Type.BUILDING_RANGE, shardSpec.getType());
    final BuildingDimensionRangeShardSpec fromJson = (BuildingDimensionRangeShardSpec) shardSpec;
    Assert.assertEquals(original, fromJson);
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with Std

use of com.fasterxml.jackson.databind.InjectableValues.Std in project druid by druid-io.

the class DimensionRangeBucketShardSpecTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final ObjectMapper mapper = ShardSpecTestUtils.initObjectMapper();
    mapper.registerSubtypes(new NamedType(DimensionRangeBucketShardSpec.class, ShardSpec.Type.BUCKET_RANGE));
    mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper));
    final DimensionRangeBucketShardSpec original = new DimensionRangeBucketShardSpec(1, DIMENSIONS, StringTuple.create("start1", "start2"), StringTuple.create("end1", "end2"));
    final String json = mapper.writeValueAsString(original);
    ShardSpec shardSpec = mapper.readValue(json, ShardSpec.class);
    Assert.assertEquals(ShardSpec.Type.BUCKET_RANGE, shardSpec.getType());
    Assert.assertEquals(original, shardSpec);
}
Also used : Std(com.fasterxml.jackson.databind.InjectableValues.Std) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Std (com.fasterxml.jackson.databind.InjectableValues.Std)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 Test (org.junit.Test)9 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)7 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)5 DefaultPasswordProvider (org.apache.druid.metadata.DefaultPasswordProvider)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 InputSource (org.apache.druid.data.input.InputSource)1 HttpInputSourceConfig (org.apache.druid.data.input.impl.HttpInputSourceConfig)1 ServerModule (org.apache.druid.guice.ServerModule)1 HdfsInputSourceConfig (org.apache.druid.inputsource.hdfs.HdfsInputSourceConfig)1 ExtractionNamespace (org.apache.druid.query.lookup.namespace.ExtractionNamespace)1 JdbcExtractionNamespace (org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace)1 IndexIO (org.apache.druid.segment.IndexIO)1 SegmentLoaderConfig (org.apache.druid.segment.loading.SegmentLoaderConfig)1 SegmentLocalCacheLoader (org.apache.druid.segment.loading.SegmentLocalCacheLoader)1 SegmentLocalCacheManager (org.apache.druid.segment.loading.SegmentLocalCacheManager)1 StorageLocationConfig (org.apache.druid.segment.loading.StorageLocationConfig)1 JdbcAccessSecurityConfig (org.apache.druid.server.initialization.JdbcAccessSecurityConfig)1 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)1