Package com.google.genai
Class Common
java.lang.Object
com.google.genai.Common
Common utility methods for the GenAI SDK.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA class that holds the path, body, and http options of an API request. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic @Nullable ObjectgetValueByPath(com.fasterxml.jackson.databind.JsonNode object, String[] keys) Gets the value of an object by a path.static @Nullable ObjectgetValueByPath(com.fasterxml.jackson.databind.JsonNode object, String[] keys, @Nullable Object defaultValue) Gets the value of an object by a path, returning a default value if the path does not exist.static booleanstatic voidmoveValueByPath(com.fasterxml.jackson.databind.JsonNode data, Map<String, String> paths) Moves values from source paths to destination paths.static voidmoveValueRecursive(com.fasterxml.jackson.databind.JsonNode data, String[] sourceKeys, String[] destKeys, int keyIdx, Set<String> excludeKeys) Recursively moves values from source path to destination path.static voidsetValueByPath(com.fasterxml.jackson.databind.node.ObjectNode jsonObject, String[] path, Object value) Sets the value of an object by a path.static StringsnakeToCamel(String str) Converts a snake_case string to camelCase.static StringurlEncode(com.fasterxml.jackson.databind.node.ObjectNode paramsNode) Converts a Jackson ObjectNode into a URL-encoded query string.
-
Method Details
-
setValueByPath
public static void setValueByPath(com.fasterxml.jackson.databind.node.ObjectNode jsonObject, 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
public static @Nullable Object getValueByPath(com.fasterxml.jackson.databind.JsonNode object, 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
public static @Nullable Object getValueByPath(com.fasterxml.jackson.databind.JsonNode object, 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'
-
formatMap
-
isZero
-
urlEncode
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").
-
snakeToCamel
Converts a snake_case string to camelCase. -
moveValueByPath
public static void moveValueByPath(com.fasterxml.jackson.databind.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
public static void moveValueRecursive(com.fasterxml.jackson.databind.JsonNode data, String[] sourceKeys, String[] destKeys, int keyIdx, Set<String> excludeKeys) Recursively moves values from source path to destination path.- Parameters:
data- The current node being processedsourceKeys- The source path keysdestKeys- The destination path keyskeyIdx- The current index in the key arraysexcludeKeys- Keys to exclude when processing wildcards
-