Search in sources :

Example 1 with TypeSignatureDeserializer

use of io.trino.type.TypeSignatureDeserializer in project trino by trinodb.

the class TestSignature method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(TESTING_TYPE_MANAGER), TypeSignature.class, new TypeSignatureDeserializer()));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);
    Signature expected = new Signature("function", BIGINT.getTypeSignature(), ImmutableList.of(BOOLEAN.getTypeSignature(), DOUBLE.getTypeSignature(), VARCHAR.getTypeSignature()));
    String json = codec.toJson(expected);
    Signature actual = codec.fromJson(json);
    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
Also used : Type(io.trino.spi.type.Type) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureDeserializer(io.trino.type.TypeSignatureDeserializer) TypeDeserializer(io.trino.type.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Aggregations

JsonCodecFactory (io.airlift.json.JsonCodecFactory)1 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 Type (io.trino.spi.type.Type)1 TypeSignature (io.trino.spi.type.TypeSignature)1 TypeDeserializer (io.trino.type.TypeDeserializer)1 TypeSignatureDeserializer (io.trino.type.TypeSignatureDeserializer)1 Test (org.testng.annotations.Test)1