Dropwizard deserializing generic list from JerseyClient

前端 未结 2 1809
执笔经年
执笔经年 2021-01-14 12:12

I wanted to implement a generic class to use for caching results from a REST API in a local MongoDB-instance. For this to work, I need to deserialize a collection I get from

2条回答
  •  迷失自我
    2021-01-14 12:50

    Java's most popular excuse for Generics: Type Erasure

    If you can pass your class type as Class clazz, then you can use this:

    GenericType> genericType = new GenericType<>(new ParameterizedType() {
      public Type[] getActualTypeArguments() {
        return new Type[]{clazz};
      }
    
      public Type getRawType() {
        return List.class;
      }
    
      public Type getOwnerType() {
        return null;
      }
    });
    response.readEntity(genericType);
    

提交回复
热议问题