Class ConfigLoader
This class handles ParseContext components and configuration POJOs that are loaded into a ParseContext for use during parsing. All configurations loaded via ConfigLoader must be placed under the "parse-context" top-level node in the JSON.
For official Tika components and configurations (parsers, detectors, async, server, etc.),
use the specific methods on TikaLoader or load directly from TikaJsonConfig.
Usage:
TikaLoader loader = TikaLoader.load(configPath);
// Load by explicit key
MyConfig config = loader.configs().load("my-config", MyConfig.class);
// Load by class name (auto-converts to kebab-case)
MyConfig config = loader.configs().load(MyConfig.class);
JSON configuration example:
{
// Official Tika configs at root level (NOT loaded via configs())
"parsers": [...],
"detectors": [...],
"pipes": {...},
"server": {...},
// ParseContext configs in "parse-context" (loaded via configs())
"parse-context": {
"embedded-limits": {
"maxDepth": 10,
"maxCount": 1000
},
"output-limits": {
"writeLimit": 100000
},
"commons-digester-factory": {
"algorithms": ["MD5", "SHA-256"]
}
}
}
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if a configuration key exists in the JSON config.<T> TLoads a configuration object using the class name converted to kebab-case.<T> TLoads a configuration object using the class name, with a default value.<T> TLoads a configuration object from the specified JSON key.<T> TLoads a configuration object from the specified JSON key, with a default value.<T> TloadWithDefaults(Class<T> clazz, T defaultValue) Loads a configuration object by class name with defaults, merging JSON properties.<T> TloadWithDefaults(String key, Class<T> clazz, T defaultValue) Loads a configuration object by merging JSON properties into a copy of the default instance.
-
Method Details
-
load
Loads a configuration object using the class name converted to kebab-case.For example,
MyAppConfig.classwill look for key "my-app-config". Class name suffixes like "Config", "Configuration", "Settings" are stripped first.For interfaces, the JSON must specify the implementation (see
load(String, Class)).- Type Parameters:
T- The type to load- Parameters:
clazz- The class to deserialize into (can be interface, abstract, or concrete)- Returns:
- the deserialized object, or null if key not found in config
- Throws:
TikaConfigException- if loading fails or class is not instantiable
-
load
Loads a configuration object using the class name, with a default value.- Type Parameters:
T- The type to load- Parameters:
clazz- The class to deserialize intodefaultValue- The value to return if key not found in config- Returns:
- the deserialized object, or defaultValue if not present
- Throws:
TikaConfigException- if loading fails or class is not instantiable
-
load
Loads a configuration object from the specified JSON key.Supports two formats:
- String value: treated as fully qualified class name to instantiate
- Object: deserialized directly into the target class
For tier-1 polymorphic types (Parser, Detector, MetadataFilter), use the wrapper object format with friendly names:
{"pdf-parser": {...}}- Type Parameters:
T- The type to load- Parameters:
key- The JSON key to load fromclazz- The class to deserialize into (can be interface, abstract, or concrete)- Returns:
- the deserialized object, or null if key not found
- Throws:
TikaConfigException- if loading fails or class cannot be instantiated
-
load
Loads a configuration object from the specified JSON key, with a default value.- Type Parameters:
T- The type to load- Parameters:
key- The JSON key to load fromclazz- The class to deserialize intodefaultValue- The value to return if key not found in config- Returns:
- the deserialized object, or defaultValue if not present
- Throws:
TikaConfigException- if loading fails or class is not instantiable
-
loadWithDefaults
public <T> T loadWithDefaults(String key, Class<T> clazz, T defaultValue) throws TikaConfigException Loads a configuration object by merging JSON properties into a copy of the default instance.This allows partial configuration where only some properties are specified in JSON, and the rest retain their default values. The original defaultValue object is NOT modified.
Example:
MyConfig defaults = new MyConfig(); defaults.setTimeout(30000); defaults.setRetries(2); defaults.setEnabled(false); // JSON: { "enabled": true } // Result: timeout=30000, retries=2, enabled=true (merged!) // Note: 'defaults' object remains unchanged MyConfig config = loader.configs().loadWithDefaults("my-config", MyConfig.class, defaults);- Type Parameters:
T- The type to load- Parameters:
key- The JSON key to load fromclazz- The class type (not used for deserialization, but for type safety)defaultValue- The object with default values (will NOT be modified)- Returns:
- a new object with defaults merged with JSON properties, or the original default if key not found
- Throws:
TikaConfigException- if loading fails
-
loadWithDefaults
Loads a configuration object by class name with defaults, merging JSON properties.- Type Parameters:
T- The type to load- Parameters:
clazz- The class to deserialize intodefaultValue- The object with default values to merge into- Returns:
- the default object updated with JSON properties, or the original default if key not found
- Throws:
TikaConfigException- if loading fails
-
hasKey
Checks if a configuration key exists in the JSON config.- Parameters:
key- The JSON key to check- Returns:
- true if the key exists and is not null
-