Interface Renderer<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Class<T> getType()
      The type of object that this renderer can render.
      static <T> Renderer<T> of​(java.lang.Class<T> type, java.util.function.BiConsumer<? super Context,​? super T> impl)
      Creates a renderer implementation from the given arguments.
      void render​(Context context, T object)
      Render the given object to the response.
      static <T> com.google.common.reflect.TypeToken<Renderer<T>> typeOf​(java.lang.Class<T> typeToRender)
      Creates a type token for a renderer of the given type of object.
    • Method Detail

      • of

        static <T> Renderer<T> of​(java.lang.Class<T> type,
                                  java.util.function.BiConsumer<? super Context,​? super T> impl)
        Creates a renderer implementation from the given arguments.
        Type Parameters:
        T - the type of object-to-render
        Parameters:
        type - the type of object-to-render
        impl - the implementation of the render(Context, Object) method
        Returns:
        a renderer implementation
      • typeOf

        static <T> com.google.common.reflect.TypeToken<Renderer<T>> typeOf​(java.lang.Class<T> typeToRender)
        Creates a type token for a renderer of the given type of object.
        Type Parameters:
        T - the type that the renderer renders
        Parameters:
        typeToRender - the type that the renderer renders
        Returns:
        a type token for a renderer of the given type of object
      • getType

        java.lang.Class<T> getType()
        The type of object that this renderer can render.
        Returns:
        The type of object that this renderer can render.
      • render

        @NonBlocking
        void render​(Context context,
                    T object)
             throws java.lang.Exception
        Render the given object to the response.

        Calling this method will finalize the processing, sending the response to the client.

        Any errors that occur during rendering will be sent to Context.error(Throwable).

        Parameters:
        context - the context for the operation
        object - the object to render
        Throws:
        java.lang.Exception - if anything goes wrong while rendering