use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class StrlenExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"strlen\" }";
StrlenExtractionFn extractionFn = (StrlenExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
StrlenExtractionFn extractionFnRoundTrip = (StrlenExtractionFn) objectMapper.readValue(objectMapper.writeValueAsString(extractionFn), ExtractionFn.class);
// Should all actually be the same instance.
Assert.assertTrue(extractionFn == extractionFnRoundTrip);
Assert.assertTrue(extractionFn == StrlenExtractionFn.instance());
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class TimeDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"time\", \"timeFormat\" : \"MM/dd/yyyy\", \"resultFormat\" : \"yyyy-MM-dd\", \"joda\" : true }";
TimeDimExtractionFn extractionFn = (TimeDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals("MM/dd/yyyy", extractionFn.getTimeFormat());
Assert.assertEquals("yyyy-MM-dd", extractionFn.getResultFormat());
// 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 BucketExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json1 = "{ \"type\" : \"bucket\", \"size\" : \"2\", \"offset\" : \"0.5\" }";
BucketExtractionFn extractionFn1 = (BucketExtractionFn) objectMapper.readValue(json1, ExtractionFn.class);
Assert.assertEquals(2, extractionFn1.getSize(), DELTA);
Assert.assertEquals(0.5, extractionFn1.getOffset(), DELTA);
Assert.assertEquals(extractionFn1, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn1), ExtractionFn.class));
final String json2 = "{ \"type\" : \"bucket\"}";
BucketExtractionFn extractionFn2 = (BucketExtractionFn) objectMapper.readValue(json2, ExtractionFn.class);
Assert.assertEquals(1, extractionFn2.getSize(), DELTA);
Assert.assertEquals(0, extractionFn2.getOffset(), DELTA);
Assert.assertEquals(extractionFn2, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn2), ExtractionFn.class));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class RegexDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"regex\", \"expr\" : \".(...)?\" , " + "\"replaceMissingValue\": true, \"replaceMissingValueWith\":\"foobar\"}";
RegexDimExtractionFn extractionFn = (RegexDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals(".(...)?", extractionFn.getExpr());
Assert.assertTrue(extractionFn.isReplaceMissingValue());
Assert.assertEquals("foobar", extractionFn.getReplaceMissingValueWith());
// 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 StringFormatExtractionFnTest method validateSerde.
private void validateSerde(String json) throws IOException {
final ObjectMapper objectMapper = new DefaultObjectMapper();
StringFormatExtractionFn extractionFn = (StringFormatExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals("[%s]", extractionFn.getFormat());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
Aggregations