Search in sources :

Example 1 with DeserializationContext

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

the class WorkerBehaviorConfigTest method testSerde.

@Test
public void testSerde() throws Exception {
    WorkerBehaviorConfig config = new WorkerBehaviorConfig(new FillCapacityWithAffinityWorkerSelectStrategy(new FillCapacityWithAffinityConfig(ImmutableMap.of("foo", Arrays.asList("localhost")))), new EC2AutoScaler(7, 11, new EC2EnvironmentConfig("us-east-1a", new EC2NodeData("amiid", "instanceType", 3, 5, Arrays.asList("securityGroupIds"), "keyNames", "subnetId", null, null), new StringEC2UserData("availZone", "replace", "version")), null, null));
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
            return null;
        }
    });
    Assert.assertEquals(config, mapper.readValue(mapper.writeValueAsBytes(config), WorkerBehaviorConfig.class));
}
Also used : EC2EnvironmentConfig(io.druid.indexing.overlord.autoscaling.ec2.EC2EnvironmentConfig) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) StringEC2UserData(io.druid.indexing.overlord.autoscaling.ec2.StringEC2UserData) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) EC2NodeData(io.druid.indexing.overlord.autoscaling.ec2.EC2NodeData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 2 with DeserializationContext

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

the class EC2AutoScalerSerdeTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    objectMapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1) {
            return null;
        }
    });
    final EC2AutoScaler autoScaler = objectMapper.readValue(json, EC2AutoScaler.class);
    verifyAutoScaler(autoScaler);
    final EC2AutoScaler roundTripAutoScaler = objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), EC2AutoScaler.class);
    verifyAutoScaler(roundTripAutoScaler);
    Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) Test(org.junit.Test)

Example 3 with DeserializationContext

use of com.fasterxml.jackson.databind.DeserializationContext in project java-chassis by ServiceComb.

the class TestAbstractDeserializer method testDeserialize.

@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
    boolean status = false;
    try {
        DeserializationContext ctxt = Mockito.mock(DeserializationContext.class);
        @SuppressWarnings("rawtypes") JsonDeserializer JsonDeserializer = Mockito.mock(JsonDeserializer.class);
        Object object = null;
        Mockito.when(jsonParser.nextFieldName()).thenReturn("abc", (String) null);
        Mockito.when(readerHelpData.getDeser()).thenReturn(JsonDeserializer);
        Mockito.when(JsonDeserializer.deserialize(jsonParser, ctxt)).thenReturn(object);
        Object deserializeObject = abstractDeserializer.deserialize(jsonParser, ctxt);
        Assert.assertNotNull(deserializeObject);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Test(org.junit.Test)

Example 4 with DeserializationContext

use of com.fasterxml.jackson.databind.DeserializationContext in project presto by prestodb.

the class TestLocalProperties method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }));
    TestingColumnHandle columnHandle = new TestingColumnHandle("a");
    LocalProperty<ColumnHandle> property1 = new ConstantProperty<>(columnHandle);
    assertEquals(property1, mapper.readValue(mapper.writeValueAsString(property1), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property2 = new SortingProperty<>(columnHandle, SortOrder.ASC_NULLS_FIRST);
    assertEquals(property2, mapper.readValue(mapper.writeValueAsString(property2), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property3 = new GroupingProperty<>(ImmutableList.of(columnHandle));
    assertEquals(property3, mapper.readValue(mapper.writeValueAsString(property3), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) ConstantProperty(com.facebook.presto.spi.ConstantProperty) GroupingProperty(com.facebook.presto.spi.GroupingProperty) SortingProperty(com.facebook.presto.spi.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 5 with DeserializationContext

use of com.fasterxml.jackson.databind.DeserializationContext in project presto by prestodb.

the class TestTupleDomain method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde(typeManager);
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.all();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.none();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(A, NullableValue.of(BIGINT, 1L), B, NullableValue.asNull(VARCHAR)));
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(com.facebook.presto.spi.TestingColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TestingBlockEncodingSerde(com.facebook.presto.spi.block.TestingBlockEncodingSerde) IOException(java.io.IOException) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(com.facebook.presto.spi.TestingColumnHandle) Type(com.facebook.presto.spi.type.Type) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(com.facebook.presto.spi.block.Block) TestingBlockJsonSerde(com.facebook.presto.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Aggregations

DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)3 Test (org.junit.Test)3 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)2 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)2 EC2AutoScaler (io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)2 Test (org.testng.annotations.Test)2 ConstantProperty (com.facebook.presto.spi.ConstantProperty)1 GroupingProperty (com.facebook.presto.spi.GroupingProperty)1 SortingProperty (com.facebook.presto.spi.SortingProperty)1 TestingColumnHandle (com.facebook.presto.spi.TestingColumnHandle)1 Block (com.facebook.presto.spi.block.Block)1 TestingBlockEncodingSerde (com.facebook.presto.spi.block.TestingBlockEncodingSerde)1