Class JSONResponse

java.lang.Object
org.apache.sling.servlets.post.AbstractPostResponse
org.apache.sling.servlets.post.JSONResponse
All Implemented Interfaces:
PostResponse

public class JSONResponse extends AbstractPostResponse
The JSONResponse is an AbstractPostResponse preparing the response in JSON.
  • Field Details

  • Constructor Details

    • JSONResponse

      public JSONResponse()
  • Method Details

    • onChange

      public void onChange(String type, String... arguments)
      Description copied from interface: PostResponse
      Records a generic change of the given type with arguments.
      Parameters:
      type - The type of the modification
      arguments - The arguments to the modifications
    • setError

      public void setError(Throwable error)
      Description copied from interface: PostResponse
      Sets the recorded error causing the operation to fail.
      Specified by:
      setError in interface PostResponse
      Overrides:
      setError in class AbstractPostResponse
      Parameters:
      error - the throwable
    • getError

      public Throwable getError()
      Description copied from class: AbstractPostResponse
      Returns any recorded error or null
      Specified by:
      getError in interface PostResponse
      Overrides:
      getError in class AbstractPostResponse
      Returns:
      an error or null
    • setProperty

      public void setProperty(String name, Object value)
      This method accepts values that correspond to json primitives or otherwise assumes that the toString() of the value can be parsed as json. If neither is the case it will throw an Exception. Assuming the above holds, it will put the value as json directly into the json value part of the response.
      Overrides:
      setProperty in class AbstractPostResponse
      Parameters:
      name - name of the property
      value - value of the property - either of type {String, Boolean, Number, null} or the toString() is parseable as json
      Throws:
      JSONResponse.JSONResponseException - if the value is not usable
    • getProperty

      public Object getProperty(String name)
      Description copied from class: AbstractPostResponse
      Returns the generic response property with the given name and type or null if no such property exists.
      Overrides:
      getProperty in class AbstractPostResponse
      Parameters:
      name - the name of the response property
      Returns:
      the requested property (might be null)
    • doSend

      protected void doSend(javax.servlet.http.HttpServletResponse response) throws IOException
      Specified by:
      doSend in class AbstractPostResponse
      Throws:
      IOException