Package io.jpostman

Class Params<T>

  • Type Parameters:
    T - the type produced by end()

    public class Params<T>
    extends Object
    Generic fluent builder for Postman parameter maps. Wraps domain-specific add/set/resolve/build logic via lambdas so that Header, Body, Auth, Url, and Environment can share one builder class instead of duplicating the same fluent API.
    • Field Detail

      • HANDLEBARS_TOKEN

        public static final Pattern HANDLEBARS_TOKEN
    • Method Detail

      • add

        public Params<T> add​(String key,
                             Object value)
        Adds or overwrites the key unconditionally.
      • 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 in vars are intentionally left unchanged so build(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 values
        keys - 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 values
        keys - 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 to json(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 to json(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 null for either argument is treated as a no-op.

        Parameters:
        target - destination token map
        value - text to scan for tokens
        Returns:
        target, or an empty map when target is null
      • 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 target are not overwritten.

        Parameters:
        target - destination token map
        values - map whose keys and values should be scanned
        Returns:
        target, or an empty map when target is null
      • substituteVars

        public static String substituteVars​(String value,
                                            Map<String,​?> vars)
        Replaces all {{key}} tokens in value with entries from vars using Handlebars. Unknown tokens use normal Handlebars behavior and render as empty strings.
        Parameters:
        value - source text; may be null
        vars - variable map; may be null
        Returns:
        substituted text, or null when value is 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 result are updated. Keys that do not exist in params keep their current value, usually an empty string.

        Parameters:
        result - unresolved token map to update
        params - source parameter values
        Returns:
        result, or an empty map when either argument is null
      • 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 root
        path - 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 invalid
        ClassCastException - 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 root
        path - simple JSON path
        Returns:
        matching JSON element, or null when the path is not found or the selected value is JSON null