Class Common

  • All Implemented Interfaces:

    @InternalApi() 
    public final class Common
    
                        

    Common utility methods for the GenAI SDK.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class Common.BuiltRequest

      A class that holds the path, body, and http options of an API request.

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • setValueByPath

         static void setValueByPath(ObjectNode jsonObject, Array<String> path, Object value)

        Sets the value of an object by a path.

        setValueByPath({}, ['a', 'b'], v) -> {'a': {'b': v}}

        setValueByPath({}, ['a', 'b[]', c], [v1, v2]) -> {'a': {'b': [{'c': v1}, {'c': v2}]}}

        setValueByPath({'a': {'b':[{'c': v1}, {'c': v2}]}}, ['a', 'b[]', 'd'], v3) -> {'a': {'b': [{'c': v1, 'd': v3}, {'c': v2,'d': v3}]}}

      • getValueByPath

        @Nullable() static Object getValueByPath(JsonNode object, Array<String> keys)

        Gets the value of an object by a path.

        getValueByPath({'a': {'b': v}}, ['a', 'b']) -> v

        getValueByPath({'a': {'b': [{'c': v1}, {'c': v2}]}}, ['a', 'b[]', 'c']) -> [v1, v2]

      • getValueByPath

        @Nullable() static Object getValueByPath(JsonNode object, Array<String> keys, @Nullable() Object defaultValue)

        Gets the value of an object by a path, returning a default value if the path does not exist.

        getValueByPath({'a': {'b': v}}, ['a', 'b'], 'default') -> v

        getValueByPath({'a': {'c': v}}, ['a', 'b'], 'default') -> 'default'

      • urlEncode

         static String urlEncode(ObjectNode paramsNode)

        Converts a Jackson ObjectNode into a URL-encoded query string. Assumes values are simple types (text, number, boolean, or null) that can be represented as a single string.

        Parameters:
        paramsNode - The ObjectNode containing the parameters to encode.
        Returns:

        A URL-encoded string (e.g., "key1=value1&key2=value2").

      • moveValueByPath

         static void moveValueByPath(JsonNode data, Map<String, String> paths)

        Moves values from source paths to destination paths.

        Example: moveValueByPath( {'requests': [{'content': v1}, {'content': v2}]}, {'requests[].*': 'requests[].request.*'} ) -> {'requests': [{'request': {'content': v1}}, {'request': {'content': v2}}]}

      • moveValueRecursive

         static void moveValueRecursive(JsonNode data, Array<String> sourceKeys, Array<String> destKeys, int keyIdx, Set<String> excludeKeys)

        Recursively moves values from source path to destination path.

        Parameters:
        data - The current node being processed
        sourceKeys - The source path keys
        destKeys - The destination path keys
        keyIdx - The current index in the key arrays
        excludeKeys - Keys to exclude when processing wildcards