Package org.springframework.ai.model
Class ModelOptionsUtils
java.lang.Object
org.springframework.ai.model.ModelOptionsUtils
Utility class for manipulating 
ModelOptions objects.- Since:
- 0.8.0
- Author:
- Christian Tzolov, Thomas Vitale
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final com.fasterxml.jackson.databind.ObjectMapper
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <I,S extends I, T extends S> 
 TcopyToTarget(S sourceBean, Class<I> sourceInterfaceClazz, Class<T> targetBeanClazz) Returns a new instance of the targetBeanClazz that copies the bean values from the sourceBean instance.getJsonPropertyValues(Class<?> clazz) Returns the list of name values of theJsonPropertyannotations.static StringgetJsonSchema(Type inputType, boolean toUpperCaseTypeValues) Generates JSON Schema (version 2020_12) for the given class.Converts the given JSON string to a Map of String and Object using the default ObjectMapper.Converts the given JSON string to a Map of String and Object using a custom ObjectMapper.static <T> TjsonToObject(String json, Class<T> type) Converts the given JSON string to an Object of the given type.static <T> TmapToClass(Map<String, Object> source, Class<T> clazz) Converts the given Map to the given class.static <T> TMerges the source object into the target object and returns an object represented by the given class.static <T> TMerges the source object into the target object and returns an object represented by the given class.static <I,S extends I, T extends S> 
 TmergeBeans(S source, T target, Class<I> sourceInterfaceClazz, boolean overrideNonNullTargetValues) Merges the source object into the target object.static <T> TmergeOption(T runtimeValue, T defaultValue) Return the runtime value if not empty, or else the default value.objectToMap(Object source) Converts the given object to a Map.static StringtoJsonString(Object object) Converts the given object to a JSON string.static StringtoJsonStringPrettyPrinter(Object object) Converts the given object to a JSON string.static voidtoUpperCaseTypeValues(com.fasterxml.jackson.databind.node.ObjectNode node) 
- 
Field Details- 
OBJECT_MAPPERpublic static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
 
- 
- 
Constructor Details- 
ModelOptionsUtilspublic ModelOptionsUtils()
 
- 
- 
Method Details- 
jsonToMapConverts the given JSON string to a Map of String and Object using the default ObjectMapper.- Parameters:
- json- the JSON string to convert to a Map.
- Returns:
- the converted Map.
 
- 
jsonToMappublic static Map<String,Object> jsonToMap(String json, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Converts the given JSON string to a Map of String and Object using a custom ObjectMapper.- Parameters:
- json- the JSON string to convert to a Map.
- objectMapper- the ObjectMapper to use for deserialization.
- Returns:
- the converted Map.
 
- 
jsonToObjectConverts the given JSON string to an Object of the given type.- Type Parameters:
- T- the type of the object to return.
- Parameters:
- json- the JSON string to convert to an object.
- type- the type of the object to return.
- Returns:
- Object instance of the given type.
 
- 
toJsonStringConverts the given object to a JSON string.- Parameters:
- object- the object to convert to a JSON string.
- Returns:
- the JSON string.
 
- 
toJsonStringPrettyPrinterConverts the given object to a JSON string.- Parameters:
- object- the object to convert to a JSON string.
- Returns:
- the JSON string.
 
- 
mergepublic static <T> T merge(Object source, Object target, Class<T> clazz, List<String> acceptedFieldNames) Merges the source object into the target object and returns an object represented by the given class. The JSON property names are used to match the fields to merge. The source non-null values override the target values with the same field name. The source null values are ignored. If the acceptedFieldNames is not empty, only the fields with the given names are merged and returned. If the acceptedFieldNames is empty, use the@JsonPropertynames, inferred from the provided clazz.- Type Parameters:
- T- they type of the class to return.
- Parameters:
- source- the source object to merge.
- target- the target object to merge into.
- clazz- the class to return.
- acceptedFieldNames- the list of field names accepted for the target object.
- Returns:
- the merged object represented by the given class.
 
- 
mergeMerges the source object into the target object and returns an object represented by the given class. The JSON property names are used to match the fields to merge. The source non-null values override the target values with the same field name. The source null values are ignored. Returns the only field names that match the@JsonPropertynames, inferred from the provided clazz.- Type Parameters:
- T- they type of the class to return.
- Parameters:
- source- the source object to merge.
- target- the target object to merge into.
- clazz- the class to return.
- Returns:
- the merged object represented by the given class.
 
- 
objectToMapConverts the given object to a Map.- Parameters:
- source- the object to convert to a Map.
- Returns:
- the converted Map.
 
- 
mapToClassConverts the given Map to the given class.- Type Parameters:
- T- the type of the class to return.
- Parameters:
- source- the Map to convert to the given class.
- clazz- the class to convert the Map to.
- Returns:
- the converted class.
 
- 
getJsonPropertyValuesReturns the list of name values of theJsonPropertyannotations.- Parameters:
- clazz- the class that contains fields annotated with- JsonProperty.
- Returns:
- the list of values of the JsonPropertyannotations.
 
- 
copyToTargetpublic static <I,S extends I, T copyToTargetT extends S> (S sourceBean, Class<I> sourceInterfaceClazz, Class<T> targetBeanClazz) Returns a new instance of the targetBeanClazz that copies the bean values from the sourceBean instance.- Type Parameters:
- T- the target class type.
- Parameters:
- sourceBean- the source bean to copy the values from.
- sourceInterfaceClazz- the source interface class. Only the fields with the same name as the interface methods are copied. This allow the source object to be a subclass of the source interface with additional, non-interface fields.
- targetBeanClazz- the target class, a subclass of the ChatOptions, to convert into.
- Returns:
- a new instance of the targetBeanClazz with the values from the sourceBean instance.
 
- 
mergeBeanspublic static <I,S extends I, T mergeBeansT extends S> (S source, T target, Class<I> sourceInterfaceClazz, boolean overrideNonNullTargetValues) Merges the source object into the target object. The source null values are ignored. Only objects with Getter and Setter methods are supported.- Type Parameters:
- T- the type of the source and target object.
- Parameters:
- source- the source object to merge.
- target- the target object to merge into.
- sourceInterfaceClazz- the source interface class. Only the fields with the same name as the interface methods are merged. This allow the source object to be a subclass of the source interface with additional, non-interface fields.
- overrideNonNullTargetValues- if true, the source non-null values override the target values with the same field name. If false, the source non-null values are ignored.
- Returns:
- the merged target object.
 
- 
getJsonSchemaGenerates JSON Schema (version 2020_12) for the given class.- Parameters:
- inputType- the input- Typeto generate JSON Schema from.
- toUpperCaseTypeValues- if true, the type values are converted to upper case.
- Returns:
- the generated JSON Schema as a String.
 
- 
toUpperCaseTypeValuespublic static void toUpperCaseTypeValues(com.fasterxml.jackson.databind.node.ObjectNode node) 
- 
mergeOptionpublic static <T> T mergeOption(T runtimeValue, T defaultValue) Return the runtime value if not empty, or else the default value.
 
-