Class JsonHttpResponse

java.lang.Object
io.jenkins.plugins.interactiveinput.rest.JsonHttpResponse
All Implemented Interfaces:
org.kohsuke.stapler.HttpResponse

public class JsonHttpResponse extends Object implements org.kohsuke.stapler.HttpResponse
An HttpResponse that writes a JSON body with an explicit HTTP status code.

All REST responses use this so both success and error payloads are valid JSON (ยง8.6), letting external agents parse errors uniformly instead of receiving Jenkins' HTML error pages.

  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonHttpResponse(int status, net.sf.json.JSONObject body)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    error(int status, String message)
    Convenience factory for a JSON error envelope: {"error": true, "message": ...}.
    void
    generateResponse(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object node)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.kohsuke.stapler.HttpResponse

    generateResponse
  • Constructor Details

    • JsonHttpResponse

      public JsonHttpResponse(int status, @NonNull net.sf.json.JSONObject body)
  • Method Details

    • error

      @NonNull public static JsonHttpResponse error(int status, @NonNull String message)
      Convenience factory for a JSON error envelope: {"error": true, "message": ...}.
    • generateResponse

      public void generateResponse(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, Object node) throws IOException
      Specified by:
      generateResponse in interface org.kohsuke.stapler.HttpResponse
      Throws:
      IOException