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
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 JSONPathquery
. - Creates
StringParameterValue
s 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 todefaultValue
.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class hudson.model.ParameterDefinition
ParameterDefinition.ParameterDescriptor
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Fields inherited from class hudson.model.ParameterDefinition
LIST
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractJsonParameterDefinition
(String name, String defaultValue, JsonSource source, String query) Creates a new JSON-backed parameter definition. -
Method Summary
Modifier and TypeMethodDescriptioncreateValue
(CLICommand command, String value) Creates a parameter value from a CLI command.createValue
(org.kohsuke.stapler.StaplerRequest2 req) Creates a parameter value from a standard web form submission.createValue
(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject jo) Creates a parameter value from a JSON-backed web form submission.Returns the default parameter value as configured.getQuery()
Methods inherited from class hudson.model.ParameterDefinition
all, copyWithDefaultValue, createValue, createValue, equals, getDescription, getDescriptor, getFormattedDescription, getName, getType, hashCode, isValid, setDescription
-
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 JenkinsdefaultValue
- the fallback value when no user input is provided (can benull
or empty)source
- the JSON source implementation providing raw JSON content (must not benull
)query
- the JSONPath used to extract option values (may contain placeholders for refs)
-
-
Method Details
-
getDefaultValue
-
getSource
-
getQuery
-
getDefaultParameterValue
Returns the default parameter value as configured.- Overrides:
getDefaultParameterValue
in classParameterDefinition
- 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 ofgetDefaultParameterValue()
downstream.- Overrides:
createValue
in classParameterDefinition
- 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
Creates a parameter value from a standard web form submission.- Overrides:
createValue
in classParameterDefinition
- Parameters:
req
- The stapler request- Returns:
- A new StringParameterValue instance
-
createValue
Creates a parameter value from a CLI command.- Overrides:
createValue
in classParameterDefinition
- Parameters:
command
- The CLI commandvalue
- The CLI argument provided- Returns:
- A new StringParameterValue instance
-