Class AbstractJsonParameterDefinition

java.lang.Object
hudson.model.ParameterDefinition
com.github.cyanbaz.jenkins.plugins.jsonparameter.AbstractJsonParameterDefinition
All Implemented Interfaces:
ExtensionPoint, Describable<ParameterDefinition>, Serializable
Direct Known Subclasses:
JsonParameterDefinition, JsonParameterReferenceDefinition

public abstract class AbstractJsonParameterDefinition extends ParameterDefinition
Base class for JSON-backed build parameters.

Implementations provide a JsonSource and a JSONPath query which, together, define how the selectable values are derived for a dropdown (or any UI that consumes those options). This class itself does not perform JSON evaluation; it only stores configuration and handles value binding for web and CLI.

Responsibilities

  • Holds the configured defaultValue, JsonSource, and JSONPath query.
  • Creates StringParameterValues from Web UI submissions and CLI invocations.
  • Exposes a localized placeholder message for empty option lists.

Value binding

  • Web UI (form submit): expects a single form field named value. If empty/missing, defaultValue is used.
  • Web UI (JSON submit): expects a JSON property "value" (string).
  • CLI: if the argument is empty or null, the parameter falls back to defaultValue.

Note: Option loading (AJAX/Stapler endpoints) and JSON evaluation are handled by concrete subclasses/descriptors and are out of scope for this base class.

Since:
1.0
Author:
Caner Yanbaz
See Also:
  • Constructor Details

    • AbstractJsonParameterDefinition

      public AbstractJsonParameterDefinition(String name, String defaultValue, JsonSource source, String query)
      Creates a new JSON-backed parameter definition.
      Parameters:
      name - the parameter name as shown in Jenkins
      defaultValue - the fallback value when no user input is provided (can be null or empty)
      source - the JSON source implementation providing raw JSON content (must not be null)
      query - the JSONPath used to extract option values (may contain placeholders for refs)
  • Method Details

    • getDefaultValue

      public String getDefaultValue()
    • getSource

      public JsonSource getSource()
    • getQuery

      public String getQuery()
    • getDefaultParameterValue

      public ParameterValue getDefaultParameterValue()
      Returns the default parameter value as configured.
      Overrides:
      getDefaultParameterValue in class ParameterDefinition
      Returns:
      StringParameterValue with default value
    • createValue

      public ParameterValue createValue(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject jo)
      Creates a parameter value from a JSON-backed web form submission.

      Expects a "value" property in the submitted JSON. If it's not present or not a string, falls back to an empty string which, depending on consumers, may trigger the use of getDefaultParameterValue() downstream.

      Overrides:
      createValue in class ParameterDefinition
      Parameters:
      req - the Stapler request (unused here)
      jo - the submitted JSON object (must contain "value" as a string)
      Returns:
      a StringParameterValue for Jenkins build execution
    • createValue

      public ParameterValue createValue(org.kohsuke.stapler.StaplerRequest2 req)
      Creates a parameter value from a standard web form submission.
      Overrides:
      createValue in class ParameterDefinition
      Parameters:
      req - The stapler request
      Returns:
      A new StringParameterValue instance
    • createValue

      public ParameterValue createValue(CLICommand command, String value)
      Creates a parameter value from a CLI command.
      Overrides:
      createValue in class ParameterDefinition
      Parameters:
      command - The CLI command
      value - The CLI argument provided
      Returns:
      A new StringParameterValue instance