Class Params<T>
- java.lang.Object
-
- io.jpostman.Params<T>
-
- Type Parameters:
T- the type produced byend()
public class Params<T> extends Object
Generic fluent builder for Postman parameter maps. Wraps domain-specific add/set/resolve/build logic via lambdas so thatHeader,Body,Auth,Url, andEnvironmentcan share one builder class instead of duplicating the same fluent API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceParams.Builder<T>static classParams.EntryStores one Postman parameter value together with its enabled/disabled state.
-
Field Summary
Fields Modifier and Type Field Description static PatternHANDLEBARS_TOKEN
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Params<T>add(String key, Object value)Adds or overwrites the key unconditionally.static Map<String,String>addTokens(Map<String,String> target, String value)Adds all Handlebars-style{{token}}placeholders found in a text value to the supplied target map.static Map<String,String>addTokens(Map<String,String> target, Map<String,String> values)Adds all Handlebars-style{{token}}placeholders found in a map's keys and values to the supplied target map.static Map<String,Object>asJson(Object... values)Creates an ordered variable map and JSON-stringifies String values.static <T> List<T>asList(T... values)Creates a mutable list from the supplied values.static Map<String,Object>asMap(Object... values)Creates an ordered variable map from alternating key/value pairs.static Map<String,Object>copy(Map<String,?>... maps)Creates a mutable ordered map by merging the supplied maps.Tend()Produces the final object.Tend(Map<String,?> vars)Resolves only variables present in the local parameter map, then produces the final object.Tjson(Object... values)Resolves variables using local key/value pairs where String values are JSON-stringified, then produces the final object.static <T> List<T>jsonList(T... values)Creates a mutable JSON-ready list from the supplied values.static <T> Map<String,T>jsonMap(Object... values)Creates a mutable ordered JSON-ready map from alternating String keys and typed values.Tmap(Object... values)Resolves variables using local key/value pairs, then produces the final object.static <T> Tpath(com.google.gson.JsonElement root, String path)Reads a value from a JSON element using a simple dot/bracket path.static com.google.gson.JsonElementpathElement(com.google.gson.JsonElement root, String path)Reads a JSON element from a parsed JSON root using a simple dot/bracket path.static Map<String,String>props(Environment env, Set<String> keys)Creates a copy of environment values and overrides matching keys with non-empty system property values.static Map<String,String>props(Map<String,String> values)Creates a copy of the supplied values and overrides matching keys with non-empty system property values.static Map<String,String>props(Map<String,String> values, Set<String> keys)Creates a copy of the supplied values and overrides matching keys with non-empty system property values.Params<T>resolve(Map<String,?> vars)Substitutes all{{key}}tokens using the supplied variable map.static Map<String,String>resolve(Map<String,String> result, Map<String,String> params)Fills an unresolved token map from the supplied parameter map.Params<T>set(String key, Object value)Updates an existing key.static StringsubstituteVars(String value, Map<String,?> vars)Replaces all{{key}}tokens invaluewith entries fromvarsusing Handlebars.
-
-
-
Field Detail
-
HANDLEBARS_TOKEN
public static final Pattern HANDLEBARS_TOKEN
-
-
Method Detail
-
set
public Params<T> set(String key, Object value)
Updates an existing key.- Throws:
IllegalArgumentException- if the target object requires the key to exist and the key is missing
-
resolve
public Params<T> resolve(Map<String,?> vars)
Substitutes all{{key}}tokens using the supplied variable map.
-
end
public T end()
Produces the final object.
-
end
public T end(Map<String,?> vars)
Resolves only variables present in the local parameter map, then produces the final object.Values resolved here have priority over later request-level resolution because replaced tokens are no longer available for
build(env). Variables not present invarsare intentionally left unchanged sobuild(env)can resolve them later.- Parameters:
vars- local variables used only for this builder- Returns:
- final object
-
asMap
public static Map<String,Object> asMap(Object... values)
Creates an ordered variable map from alternating key/value pairs.- Parameters:
values- alternating key/value pairs- Returns:
- ordered variable map
-
asJson
public static Map<String,Object> asJson(Object... values)
Creates an ordered variable map and JSON-stringifies String values.- Parameters:
values- alternating key/value pairs- Returns:
- ordered JSON-ready variable map
-
copy
@SafeVarargs public static Map<String,Object> copy(Map<String,?>... maps)
Creates a mutable ordered map by merging the supplied maps.When the same key exists in multiple maps, the later map wins.
- Parameters:
maps- source maps; null maps are ignored- Returns:
- mutable merged map
-
props
public static Map<String,String> props(Environment env, Set<String> keys)
Creates a copy of environment values and overrides matching keys with non-empty system property values.- Parameters:
env- environment containing default valueskeys- keys allowed to be overridden; when null or empty, all keys are checked- Returns:
- copied values with system property overrides
-
props
public static Map<String,String> props(Map<String,String> values, Set<String> keys)
Creates a copy of the supplied values and overrides matching keys with non-empty system property values.- Parameters:
values- default valueskeys- keys allowed to be overridden; when null or empty, all keys are checked- Returns:
- copied values with system property overrides
-
props
public static Map<String,String> props(Map<String,String> values)
Creates a copy of the supplied values and overrides matching keys with non-empty system property values.- Parameters:
values- default values- Returns:
- copied values with system property overrides
-
asList
@SafeVarargs public static <T> List<T> asList(T... values)
Creates a mutable list from the supplied values.- Type Parameters:
T- value type- Parameters:
values- list values- Returns:
- mutable list containing the supplied values
-
jsonList
@SafeVarargs public static <T> List<T> jsonList(T... values)
Creates a mutable JSON-ready list from the supplied values.The returned value remains a normal typed Java
List. When passed as a value tojson(Object...), it is serialized as a JSON array.- Type Parameters:
T- value type- Parameters:
values- list values- Returns:
- mutable list containing the supplied values
-
jsonMap
public static <T> Map<String,T> jsonMap(Object... values)
Creates a mutable ordered JSON-ready map from alternating String keys and typed values.The returned value remains a normal typed Java
Map. When passed as a value tojson(Object...), it is serialized as a JSON object.- Type Parameters:
T- value type- Parameters:
values- alternating String keys and values- Returns:
- mutable ordered map
- Throws:
IllegalArgumentException- when values are not key/value pairs or a key is not a String
-
map
public T map(Object... values)
Resolves variables using local key/value pairs, then produces the final object.- Parameters:
values- alternating key/value pairs- Returns:
- final object
-
json
public T json(Object... values)
Resolves variables using local key/value pairs where String values are JSON-stringified, then produces the final object.- Parameters:
values- alternating key/value pairs- Returns:
- final object
-
addTokens
public static Map<String,String> addTokens(Map<String,String> target, String value)
Adds all Handlebars-style{{token}}placeholders found in a text value to the supplied target map.Every discovered token is inserted with an empty string value and existing entries are preserved. Passing
nullfor either argument is treated as a no-op.- Parameters:
target- destination token mapvalue- text to scan for tokens- Returns:
target, or an empty map whentargetisnull
-
addTokens
public static Map<String,String> addTokens(Map<String,String> target, Map<String,String> values)
Adds all Handlebars-style{{token}}placeholders found in a map's keys and values to the supplied target map.This is useful for request parts where both parameter names and parameter values may contain unresolved tokens. Existing entries in
targetare not overwritten.- Parameters:
target- destination token mapvalues- map whose keys and values should be scanned- Returns:
target, or an empty map whentargetisnull
-
substituteVars
public static String substituteVars(String value, Map<String,?> vars)
Replaces all{{key}}tokens invaluewith entries fromvarsusing Handlebars. Unknown tokens use normal Handlebars behavior and render as empty strings.- Parameters:
value- source text; may benullvars- variable map; may benull- Returns:
- substituted text, or
nullwhenvalueis null
-
resolve
public static Map<String,String> resolve(Map<String,String> result, Map<String,String> params)
Fills an unresolved token map from the supplied parameter map.Only keys already present in
resultare updated. Keys that do not exist inparamskeep their current value, usually an empty string.- Parameters:
result- unresolved token map to updateparams- source parameter values- Returns:
result, or an empty map when either argument isnull
-
path
public static <T> T path(com.google.gson.JsonElement root, String path)Reads a value from a JSON element using a simple dot/bracket path.- Type Parameters:
T- expected return type- Parameters:
root- parsed JSON rootpath- simple JSON path (e.g., "user.id", "products[0].title")- Returns:
- selected value converted to a Java value
- Throws:
IllegalArgumentException- if the path is not found or invalidClassCastException- if the caller assigns the value to the wrong type
-
pathElement
public static com.google.gson.JsonElement pathElement(com.google.gson.JsonElement root, String path)Reads a JSON element from a parsed JSON root using a simple dot/bracket path.- Parameters:
root- parsed JSON rootpath- simple JSON path- Returns:
- matching JSON element, or
nullwhen the path is not found or the selected value is JSONnull
-
-