use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestTupleDomain method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {
@Override
public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return new JsonObjectMapperProvider().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>>() {
}));
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestHttpQueryStatsClient method setUp.
@BeforeMethod
public void setUp() {
ObjectMapper objectMapper = new JsonObjectMapperProvider().get();
TestingHttpClient httpClient = new TestingHttpClient(httpRequest -> httpResponse);
this.queryStatsClient = new HttpQueryStatsClient(httpClient, objectMapper, BASE_URL);
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class JsonUtils method parseJson.
public static <T> T parseJson(Path path, Class<T> javaType) {
if (!path.isAbsolute()) {
path = path.toAbsolutePath();
}
checkArgument(exists(path), "File does not exist: %s", path);
checkArgument(isReadable(path), "File is not readable: %s", path);
try {
byte[] json = Files.readAllBytes(path);
ObjectMapper mapper = new JsonObjectMapperProvider().get().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
return mapper.readValue(json, javaType);
} catch (IOException e) {
throw new IllegalArgumentException(format("Invalid JSON file '%s' for '%s'", path, javaType), e);
}
}
use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.
the class TestQueues method setup.
@BeforeMethod
public void setup() throws Exception {
queryRunner = createQueryRunner();
client = new JettyHttpClient();
objectMapper = new JsonObjectMapperProvider().get();
objectMapper.registerModule(new SimpleModule() {
{
addKeyDeserializer(VariableReferenceExpression.class, new Serialization.VariableReferenceExpressionDeserializer(createTestFunctionAndTypeManager()));
}
});
}
Aggregations