public void bindListThriftCodec(Class<?> type) { requireNonNull(type, "type is null"); ParameterizedTypeImpl listType = new ParameterizedTypeImpl(null, List.class, type); binder.bind(getThriftCodecKey(listType)).toProvider(new ThriftCodecProvider(listType)).in(Scopes.SINGLETON); }
public void bindMapThriftCodec(Class<?> keyType, Class<?> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(null, Map.class, keyType, valueType); binder.bind(getThriftCodecKey(mapType)).toProvider(new ThriftCodecProvider(mapType)).in(Scopes.SINGLETON); }
private Key<ThriftCodec<?>> getThriftCodecKey(Type type) { return (Key<ThriftCodec<?>>) Key.get(new ParameterizedTypeImpl(null, ThriftCodec.class, type)); }
@Override public Object getValue(HttpContext ctx) { HttpRequestContext request = ctx.getRequest(); Object deserialized = null; if (HttpMethod.POST.equals(request.getMethod()) || HttpMethod.PUT.equals(request.getMethod())) { if (type instanceof Class && Model.class.isAssignableFrom((Class<?>) type)) { App app = App.get(); // We cannot actually use this instance with jersey, but at // least we know // which implementation is to be used for the given interface. deserialized = (Model) app.inject((Class<?>) type); if (deserialized != null) { // Let jersey instantiate and populate the model object // using // the implementation object we located via guice. deserialized = request.getEntity(deserialized.getClass()); // Because jersey creates a new instance, instead of using // the one // created by guice, we inject the members manually // afterwards. if (deserialized != null) app.injectMembers(deserialized); } } else if (type instanceof ParameterizedType) { List<Class<?>> genTypes = Reflect.getGenericType(type); Class<?> genType = genTypes != null && genTypes.size() > 0 ? genTypes.get(0) : null; if (genType != null && Model.class.isAssignableFrom(genType)) { Model m = (Model) App.get().inject((Class<?>) genType); // We need to create the generic type manually. ParameterizedTypeImpl genericType = new ParameterizedTypeImpl(null, List.class, new Type[] { m.getClass() }); deserialized = request.getEntity(List.class, genericType, List.class.getAnnotations()); } } } return deserialized; }
/** * Returns a new parameterized type, applying {@code typeArguments} to * {@code rawType} and enclosed by {@code ownerType}. * * @return a {@link java.io.Serializable serializable} parameterized type. */ public static ParameterizedType newParameterizedTypeWithOwner( Type ownerType, Type rawType, Type... typeArguments) { return new ParameterizedTypeImpl(ownerType, rawType, typeArguments); }
/** * Returns a new parameterized type, applying {@code typeArguments} to {@code rawType} and * enclosed by {@code ownerType}. * * @return a {@link java.io.Serializable serializable} parameterized type. */ public static ParameterizedType newParameterizedTypeWithOwner( Type ownerType, Type rawType, Type... typeArguments) { return new ParameterizedTypeImpl(ownerType, rawType, typeArguments); }