/** * Shortcut method * The method uses a TypeKey and null injection message to obtain an instance. * * @param type * @param <T> * @return */ default <T> T instance(Class<T> type) throws UnsatisfiedInjectionException { return instance(new TypeKey<>(type), null); }
/** * Shortcut method * The method uses a TypeKey and null injection message to obtain a plyprovider. * * @return */ default <T> Polysupplier<T> polysupplier(Class<T> type) { return polysupplier(new TypeKey<>(type)); } }
/** * Shortcut method * The method uses a TypeKey and null injection message to obtain a provider. * * @param type * @param <T> * @return */ default <T> Provider<T> provider(Class<T> type) throws UnsatisfiedInjectionException { return provider(new TypeKey<>(type), null); }
@Override public <V> V read(Class<V> type, ReaderContext context) { // try get accurate reader final Supplier<RestletTeleReader> supplier = ioc.supplierOrNull(new ClassedKey<>(RestletTeleReader.class, type)); if (supplier != null) { final TeleReader<V, ReaderContext> reader = supplier.get(null); return reader.read(context); } // no accurate reader. read as json HttpContext httpContext = httpContextProv.get(); try (InputStream is = httpContext.getRequest().getInputStream()) { return jsonConverter.fromJson(is, type); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Shortcut method * @param type * @param <T> * @return * @throws UnsatisfiedInjectionException */ default <T> Supplier<T> supplier(Class<T> type) throws UnsatisfiedInjectionException { return supplier(new TypeKey<>(type)); }
@Override public <V> void write(Class<V> type, V value, WriterContext context) { final Supplier<RestletTeleWriter> supplier = ioc.supplierOrNull(new ClassedKey<>(RestletTeleWriter.class, type)); if (supplier != null) { final TeleWriter<V, WriterContext> writer = supplier.get(null); writer.write(value, context); return; } HttpContext httpContext = httpContextProv.get(); HttpResponse httpResponse = httpContext.getResponse(); String json = jsonConverter.toJson(value); if (json == null) { httpResponse.sendText("", RESPONSE_CONTENT_TYPE, 204); } else { httpResponse.sendData(ByteBuffer.wrap(json.getBytes()), RESPONSE_CONTENT_TYPE, 200); } }
@Override public <V> void write(Class<V> type, V value, WriterContext context) { final WebletTeleWriter<V> writer = ioc.instance(new ClassedKey<>(WebletTeleWriter.class, type), null); writer.write(value, context); }
@Override public <V> V read(Class<V> type, ReaderContext context) { final WebletTeleReader<V> reader = ioc.instance(new ClassedKey<>(WebletTeleReader.class, type), null); return reader.read(context); }