private static <T> JsonCodec<T> getJsonCodecForType(Type type) {
   if (VarcharType.VARCHAR.equals(type)) {
     return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class);
   }
   if (BooleanType.BOOLEAN.equals(type)) {
     return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class);
   }
   if (BigintType.BIGINT.equals(type)) {
     return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class);
   }
   if (DoubleType.DOUBLE.equals(type)) {
     return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
   }
   if (type instanceof ArrayType) {
     Type elementType = ((ArrayType) type).getElementType();
     return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
   }
   if (type instanceof MapType) {
     Type keyType = ((MapType) type).getKeyType();
     Type valueType = ((MapType) type).getValueType();
     return (JsonCodec<T>)
         JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType));
   }
   throw new PrestoException(
       INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
 }
 private static Class<?> getMapKeyType(Type type) {
   if (VarcharType.VARCHAR.equals(type)) {
     return String.class;
   }
   if (BooleanType.BOOLEAN.equals(type)) {
     return Boolean.class;
   }
   if (BigintType.BIGINT.equals(type)) {
     return Long.class;
   }
   if (DoubleType.DOUBLE.equals(type)) {
     return Double.class;
   }
   throw new PrestoException(
       INVALID_SESSION_PROPERTY,
       format("Session property map key type %s is not supported", type));
 }
 private static Object deserializeSessionProperty(Type type, String value) {
   if (value == null) {
     throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null");
   }
   if (VarcharType.VARCHAR.equals(type)) {
     return value;
   }
   if (BooleanType.BOOLEAN.equals(type)) {
     return Boolean.valueOf(value);
   }
   if (BigintType.BIGINT.equals(type)) {
     return Long.valueOf(value);
   }
   if (DoubleType.DOUBLE.equals(type)) {
     return Double.valueOf(value);
   }
   if (type instanceof ArrayType || type instanceof MapType) {
     return getJsonCodecForType(type).fromJson(value);
   }
   throw new PrestoException(
       INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
 }