Search in sources :

Example 6 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class InlineSchemaAvroBytesDecoderTest method testSerde.

@Test
public void testSerde() throws Exception {
    String jsonStr = "{\n" + "  \"type\": \"schema_inline\",\n" + "  \"schema\": {\n" + "    \"namespace\": \"io.druid.data.input\",\n" + "   \"name\": \"SomeData\",\n" + "    \"type\": \"record\",\n" + "    \"fields\" : [\n" + "      {\"name\":\"timestamp\",\"type\":\"long\"},\n" + "      {\"name\":\"eventType\",\"type\":\"string\"},\n" + "      {\"name\":\"id\",\"type\":\"long\"}\n" + "    ]\n" + "  }\n" + "}";
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, mapper));
    InlineSchemaAvroBytesDecoder actual = (InlineSchemaAvroBytesDecoder) mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, AvroBytesDecoder.class)), AvroBytesDecoder.class);
    Assert.assertEquals(actual.getSchema().get("name"), "SomeData");
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test) AvroStreamInputRowParserTest(io.druid.data.input.AvroStreamInputRowParserTest)

Example 7 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class InlineSchemasAvroBytesDecoderTest method testSerde.

@Test
public void testSerde() throws Exception {
    String jsonStr = "{\n" + "  \"type\": \"multiple_schemas_inline\",\n" + "  \"schemas\": {\n" + "    \"5\": {\n" + "      \"namespace\": \"io.druid.data.input\",\n" + "      \"name\": \"name5\",\n" + "      \"type\": \"record\",\n" + "      \"fields\" : [\n" + "        {\"name\":\"eventType\",\"type\":\"string\"},\n" + "        {\"name\":\"id\",\"type\":\"long\"}\n" + "      ]\n" + "    },\n" + "    \"8\": {\n" + "      \"namespace\": \"io.druid.data.input\",\n" + "      \"name\": \"name8\",\n" + "      \"type\": \"record\",\n" + "      \"fields\" : [\n" + "       {\"name\":\"eventType\",\"type\":\"string\"},\n" + "       {\"name\":\"id\",\"type\":\"long\"}\n" + "      ]\n" + "    }\n" + "  }\n" + "}\n";
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, mapper));
    InlineSchemasAvroBytesDecoder actual = (InlineSchemasAvroBytesDecoder) mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, AvroBytesDecoder.class)), AvroBytesDecoder.class);
    Assert.assertEquals(actual.getSchemas().get("5").get("name"), "name5");
    Assert.assertEquals(actual.getSchemas().get("8").get("name"), "name8");
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test) AvroStreamInputRowParserTest(io.druid.data.input.AvroStreamInputRowParserTest)

Example 8 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class LoadingLookupFactoryTest method testSerDeser.

@Test
public void testSerDeser() throws IOException {
    ObjectMapper mapper = TestHelper.getObjectMapper();
    LoadingLookupFactory loadingLookupFactory = new LoadingLookupFactory(new MockDataFetcher(), new OnHeapLoadingCache<String, String>(0, 100, 100L, 0L, 0L), new OffHeapLoadingCache<String, List<String>>(100, 100L, 0L, 0L));
    mapper.registerSubtypes(MockDataFetcher.class);
    mapper.registerSubtypes(LoadingLookupFactory.class);
    Assert.assertEquals(loadingLookupFactory, mapper.reader(LookupExtractorFactory.class).readValue(mapper.writeValueAsString(loadingLookupFactory)));
}
Also used : List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class LoadingCacheTest method testSerDeser.

@Test
public void testSerDeser() throws IOException {
    ObjectMapper mapper = new DefaultObjectMapper();
    Assert.assertEquals(loadingCache, mapper.reader(LoadingCache.class).readValue(mapper.writeValueAsString(loadingCache)));
    Assert.assertTrue(loadingCache.hashCode() == mapper.reader(LoadingCache.class).readValue(mapper.writeValueAsString(loadingCache)).hashCode());
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 10 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class StaticS3FirehoseFactoryTest method testSerde.

@Test
public void testSerde() throws Exception {
    ObjectMapper mapper = new DefaultObjectMapper();
    final List<URI> uris = Arrays.asList(new URI("s3://foo/bar/file.gz"), new URI("s3://bar/foo/file2.gz"));
    TestStaticS3FirehoseFactory factory = new TestStaticS3FirehoseFactory(uris);
    TestStaticS3FirehoseFactory outputFact = mapper.readValue(mapper.writeValueAsString(factory), TestStaticS3FirehoseFactory.class);
    Assert.assertEquals(factory, outputFact);
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) URI(java.net.URI) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5262 Test (org.junit.Test)1989 IOException (java.io.IOException)837 JsonNode (com.fasterxml.jackson.databind.JsonNode)724 HashMap (java.util.HashMap)375 Map (java.util.Map)367 ArrayList (java.util.ArrayList)346 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)318 File (java.io.File)282 List (java.util.List)222 Test (org.junit.jupiter.api.Test)205 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 Before (org.junit.Before)202 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)197 InputStream (java.io.InputStream)143 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)137 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Matchers.containsString (org.hamcrest.Matchers.containsString)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)108 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)99