Package org.springframework.ai.util
Class JsonHelper
java.lang.Object
org.springframework.ai.util.JsonHelper
Helper for JSON processing.
- Since:
- 2.0.0
- Author:
- Sebastien Deleuze
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TconvertFromMap(Map<String, Object> map, Class<T> type) Converts a map to a Java object.<T> TconvertFromMap(Map<String, Object> map, org.springframework.core.ParameterizedTypeReference<T> type) Converts a map to a Java object.convertToMap(Object object) convertToTypedObject(Object value, Class<?> type) Convert a Java Object to a typed Object.<T> @Nullable TConverts a JSON string to a Java object.<T> @Nullable TConverts a JSON string to a Java object.<T> @Nullable TConverts a JSON string to a Java object.fromJsonToMap(String json) Converts the given JSON string to a Map of String and Object.Converts a Java object to a JSON string.Converts a Java object to a JSON string.
-
Constructor Details
-
JsonHelper
public JsonHelper() -
JsonHelper
public JsonHelper(tools.jackson.databind.json.JsonMapper jsonMapper)
-
-
Method Details
-
fromJson
Converts a JSON string to a Java object.- Parameters:
json- the JSON string to parsetype- the target type- Returns:
- the converted object
-
fromJson
Converts a JSON string to a Java object.- Parameters:
json- the JSON string to parsetype- the target type- Returns:
- the converted object
-
fromJson
public <T> @Nullable T fromJson(String json, org.springframework.core.ParameterizedTypeReference<T> type) Converts a JSON string to a Java object.- Parameters:
json- the JSON string to parsetype- the target type- Returns:
- the converted object
-
fromJsonToMap
Converts the given JSON string to a Map of String and Object.- Parameters:
json- the JSON string to parse- Returns:
- the converted map
-
toJson
Converts a Java object to a JSON string. -
toJson
Converts a Java object to a JSON string.- Parameters:
forwardIfValidJson- when true and object being a valid JSON string, just return it
-
convertFromMap
Converts a map to a Java object.- Parameters:
map- the map to converttype- the target type- Returns:
- the converted object
-
convertFromMap
public <T> T convertFromMap(Map<String, Object> map, org.springframework.core.ParameterizedTypeReference<T> type) Converts a map to a Java object.- Parameters:
map- the map to converttype- the target type- Returns:
- the converted object
-
convertToMap
-
convertToTypedObject
Convert a Java Object to a typed Object. Based on the implementation in MethodToolCallback.- Parameters:
value- the object to converttype- the target type- Returns:
- the converted typed object
-