Class JSONPage

java.lang.Object
com.groiss.gui.JSONPage
All Implemented Interfaces:
Page, StreamablePage

public class JSONPage extends Object implements StreamablePage
A page implementation suitable for sending JSON objects to the client.
  • Field Details

    • EMPTY_PAGE

      public static final JSONPage EMPTY_PAGE
      An empty page.
  • Constructor Details

    • JSONPage

      public JSONPage(Object jsonContent)
      Initializes an instance of this class with the content in JSON form. The content should not be manipulated after construction.
      Parameters:
      jsonContent - the response content in JSON form.
  • Method Details

    • getContentType

      public String getContentType()
      Description copied from interface: Page
      Returns the content type of the page, for example "text/html".
      Specified by:
      getContentType in interface Page
      Returns:
      the contents mime type as String
    • getContent

      public Object getContent()
    • show

      public String show()
      For a JSONPage, this is usually never called by the dispatcher; the content will be written directly to the writer of the response.
      Specified by:
      show in interface Page
      See Also:
    • addHeader

      public void addHeader(String header, String value)
      Set a header field in the response before writing the page. Please note that HttpServletResponse.setHeader(String, String) will be used to set to the new value.
      Parameters:
      header - the name of the header
      value - the header value
    • addHeader

      public void addHeader(String header, Date value)
      Set a header field in the response before writing the page. Please note that HttpServletResponse.setDateHeader(String,long) will be used to set to the new value.
      Parameters:
      header - the name of the header
      value - the header value
    • addHeader

      public void addHeader(String header, int value)
      Set a header field in the response before writing the page. Please note that HttpServletResponse.setIntHeader(String,int) will be used to set to the new value.
      Parameters:
      header - the name of the header
      value - the header value
    • getHeaders

      public List<Pair<String,Object>> getHeaders()
      Description copied from interface: Page
      Returns the list of http-response-headers to be set on the HttpServletResponse
      Specified by:
      getHeaders in interface Page
      Returns:
      the http-headers (the value may be one of String, Date or Integer
    • output

      public void output(Writer w)
      Specified by:
      output in interface StreamablePage