Package org.apache.tika.config
Class ConfigDeserializer
java.lang.Object
org.apache.tika.config.ConfigDeserializer
Utility for deserializing JSON configuration without compile-time dependency on Jackson.
This class uses reflection to call Jackson's ObjectMapper when available on the classpath.
If tika-serialization is available, it uses the configured ObjectMapper from
TikaObjectMapperFactory to ensure consistent behavior with ParseContext
serialization. Otherwise, it falls back to a plain ObjectMapper.
If Jackson is not available and JSON deserialization is attempted, it throws a clear error message.
Usage pattern in parsers, detectors, and other Tika components:
public class MyParser implements Parser {
public static class Config {
public int timeout = 30;
public boolean verbose = false;
}
public MyParser() {
// Default constructor for SPI
}
public MyParser(Config config) {
// Constructor with explicit config object
this.timeout = config.timeout;
this.verbose = config.verbose;
}
public MyParser(JsonConfig jsonConfig) {
this(ConfigDeserializer.buildConfig(jsonConfig, Config.class));
}
}
- Since:
- Apache Tika 4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TbuildConfig(JsonConfig jsonConfig, Class<T> configClass) Deserializes a JSON configuration to a configuration object.static booleanChecks if Jackson ObjectMapper is available on the classpath.
-
Constructor Details
-
ConfigDeserializer
public ConfigDeserializer()
-
-
Method Details
-
buildConfig
Deserializes a JSON configuration to a configuration object. Requires Jackson on the classpath.- Type Parameters:
T- the configuration type- Parameters:
jsonConfig- the JSON configurationconfigClass- the configuration class- Returns:
- the deserialized configuration object
- Throws:
RuntimeException- if Jackson is not on the classpath or deserialization fails
-
isJacksonAvailable
public static boolean isJacksonAvailable()Checks if Jackson ObjectMapper is available on the classpath.- Returns:
- true if Jackson is available for JSON deserialization
-