diff --git a/processing/src/main/java/io/druid/segment/data/BitmapSerde.java b/processing/src/main/java/io/druid/segment/data/BitmapSerde.java index 6e47dd765e9..b68a2bddf1c 100644 --- a/processing/src/main/java/io/druid/segment/data/BitmapSerde.java +++ b/processing/src/main/java/io/druid/segment/data/BitmapSerde.java @@ -19,15 +19,19 @@ package io.druid.segment.data; -import com.metamx.common.ISE; +import com.fasterxml.jackson.annotation.JsonTypeName; public class BitmapSerde { // default bitmap indices for Druid >= 0.7.x + // annotation required so Jackson doesn't get confused + @JsonTypeName("concise") public static class DefaultBitmapSerdeFactory extends ConciseBitmapSerdeFactory {} // default bitmap indices in Druid <= 0.6.x + @JsonTypeName("concise") + // annotation required so Jackson doesn't get confused by subclassing public static class LegacyBitmapSerdeFactory extends ConciseBitmapSerdeFactory {} public static BitmapSerdeFactory createLegacyFactory() diff --git a/processing/src/test/java/io/druid/segment/data/BitmapSerdeFactoryTest.java b/processing/src/test/java/io/druid/segment/data/BitmapSerdeFactoryTest.java new file mode 100644 index 00000000000..4438ab787f0 --- /dev/null +++ b/processing/src/test/java/io/druid/segment/data/BitmapSerdeFactoryTest.java @@ -0,0 +1,48 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2014 Metamarkets Group Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package io.druid.segment.data; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.druid.jackson.DefaultObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +public class BitmapSerdeFactoryTest +{ + @Test + public void testSerialization() throws Exception + { + ObjectMapper mapper = new DefaultObjectMapper(); + Assert.assertEquals("{\"type\":\"roaring\"}", mapper.writeValueAsString(new RoaringBitmapSerdeFactory())); + Assert.assertEquals("{\"type\":\"concise\"}", mapper.writeValueAsString(new ConciseBitmapSerdeFactory())); + Assert.assertEquals("{\"type\":\"concise\"}", mapper.writeValueAsString(BitmapSerde.createLegacyFactory())); + Assert.assertEquals("{\"type\":\"concise\"}", mapper.writeValueAsString(new BitmapSerde.DefaultBitmapSerdeFactory())); + Assert.assertEquals("{\"type\":\"concise\"}", mapper.writeValueAsString(new BitmapSerde.LegacyBitmapSerdeFactory())); + } + + @Test + public void testDeserialization() throws Exception + { + ObjectMapper mapper = new DefaultObjectMapper(); + Assert.assertTrue(mapper.readValue("{\"type\":\"roaring\"}", BitmapSerdeFactory.class) instanceof RoaringBitmapSerdeFactory); + Assert.assertTrue(mapper.readValue("{\"type\":\"concise\"}", BitmapSerdeFactory.class) instanceof ConciseBitmapSerdeFactory); + Assert.assertTrue(mapper.readValue("{\"type\":\"BitmapSerde$SomeRandomClass\"}", BitmapSerdeFactory.class) instanceof ConciseBitmapSerdeFactory); + } +}