use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class LikeDimFilterTest method testSerde.
@Test
public void testSerde() throws IOException {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
final DimFilter filter2 = objectMapper.readValue(objectMapper.writeValueAsString(filter), DimFilter.class);
Assert.assertEquals(filter, filter2);
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class TimeFormatExtractionFnTest method testSerdeFromJson.
@Test
public void testSerdeFromJson() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"timeFormat\", \"format\" : \"HH\" }";
TimeFormatExtractionFn extractionFn = (TimeFormatExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals("HH", extractionFn.getFormat());
Assert.assertEquals(null, extractionFn.getLocale());
Assert.assertEquals(null, extractionFn.getTimeZone());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class CascadeExtractionFnTest method testSerde.
@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\" : \"cascade\", \"extractionFns\": [" + regexDimExtractionFnJson + "," + javascriptExtractionFnJson + "," + substringDimExtractionFnJson + "]}";
CascadeExtractionFn cascadeExtractionFn = (CascadeExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
RegexDimExtractionFn regexDimExtractionFn = (RegexDimExtractionFn) objectMapper.readValue(regexDimExtractionFnJson, ExtractionFn.class);
JavaScriptExtractionFn javascriptExtractionFn = (JavaScriptExtractionFn) objectMapper.readValue(javascriptExtractionFnJson, ExtractionFn.class);
SubstringDimExtractionFn substringDimExtractionFn = (SubstringDimExtractionFn) objectMapper.readValue(substringDimExtractionFnJson, ExtractionFn.class);
Assert.assertEquals(regexDimExtractionFn, cascadeExtractionFn.getExtractionFns()[0]);
Assert.assertEquals(javascriptExtractionFn, cascadeExtractionFn.getExtractionFns()[1]);
Assert.assertEquals(substringDimExtractionFn, cascadeExtractionFn.getExtractionFns()[2]);
Assert.assertEquals(cascadeExtractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(cascadeExtractionFn), ExtractionFn.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class MatchingDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"partial\", \"expr\" : \".(...)?\" }";
MatchingDimExtractionFn extractionFn = (MatchingDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals(".(...)?", extractionFn.getExpr());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class SearchQuerySpecDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
ObjectMapper objectMapper = new DefaultObjectMapper();
SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("to", "yo"), true);
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
ExtractionFn extractionFn2 = objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class);
FragmentSearchQuerySpec spec2 = (FragmentSearchQuerySpec) ((SearchQuerySpecDimExtractionFn) extractionFn2).getSearchQuerySpec();
Assert.assertEquals(extractionFn, extractionFn2);
Assert.assertEquals(true, spec2.isCaseSensitive());
Assert.assertEquals(ImmutableList.of("to", "yo"), spec2.getValues());
}
Aggregations