Esempio n. 1
0
 public CodecSupplier(Class<T> clazz, Metadata metadata) {
   this.clazz = clazz;
   this.metadata = metadata;
   ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
   objectMapperProvider.setJsonDeserializers(
       ImmutableMap.<Class<?>, JsonDeserializer<?>>of(Type.class, new TypeDeserializer()));
   this.codecFactory = new JsonCodecFactory(objectMapperProvider);
 }
Esempio n. 2
0
  @Test
  public void testRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(
        ImmutableMap.<Class<?>, JsonDeserializer<?>>of(
            Type.class, new TypeDeserializer(new TypeRegistry())));
    JsonCodec<Signature> codec =
        new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);

    Signature expected =
        new Signature("function", BIGINT, ImmutableList.of(BOOLEAN, DOUBLE, VARCHAR));

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