Package org.apache.tika.config.loader
Class JsonMergeUtils
java.lang.Object
org.apache.tika.config.loader.JsonMergeUtils
Utility methods for merging JSON configurations with default values.
Provides a consistent pattern for deserializing JSON while preserving default values for unspecified fields. The original default object is never modified - a deep copy is created first.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tdeserialize(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass) Deserializes JSON to a configuration object without merging.static <T> TmergeWithDefaults(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JsonNode node, Class<T> configClass, T defaultConfig) Deserializes a JsonNode and merges it with a default configuration object.static <T> TmergeWithDefaults(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass, T defaultConfig) Deserializes JSON and merges it with a default configuration object.
-
Method Details
-
mergeWithDefaults
public static <T> T mergeWithDefaults(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass, T defaultConfig) throws IOException Deserializes JSON and merges it with a default configuration object.Creates a deep copy of the default object, then applies the JSON properties on top. Fields not specified in the JSON retain their default values. The original defaultConfig is never modified.
- Type Parameters:
T- the configuration type- Parameters:
mapper- the ObjectMapper to usejson- the JSON string to deserializeconfigClass- the configuration classdefaultConfig- the default configuration (will NOT be modified)- Returns:
- a new object with defaults merged with JSON properties
- Throws:
IOException- if deserialization fails
-
mergeWithDefaults
public static <T> T mergeWithDefaults(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JsonNode node, Class<T> configClass, T defaultConfig) throws IOException Deserializes a JsonNode and merges it with a default configuration object.- Type Parameters:
T- the configuration type- Parameters:
mapper- the ObjectMapper to usenode- the JsonNode to deserializeconfigClass- the configuration classdefaultConfig- the default configuration (will NOT be modified)- Returns:
- a new object with defaults merged with JSON properties
- Throws:
IOException- if deserialization fails
-
deserialize
public static <T> T deserialize(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass) throws IOException Deserializes JSON to a configuration object without merging.- Type Parameters:
T- the configuration type- Parameters:
mapper- the ObjectMapper to usejson- the JSON string to deserializeconfigClass- the configuration class- Returns:
- the deserialized object
- Throws:
IOException- if deserialization fails
-