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));
}
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);
}
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);
}
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>>() {
}));
}
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>>() {
}));
}
Aggregations