Class JsonMergeUtils

java.lang.Object
org.apache.tika.config.loader.JsonMergeUtils

public final class JsonMergeUtils extends Object
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 Type
    Method
    Description
    static <T> T
    deserialize(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass)
    Deserializes JSON to a configuration object without merging.
    static <T> T
    mergeWithDefaults(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> T
    mergeWithDefaults(com.fasterxml.jackson.databind.ObjectMapper mapper, String json, Class<T> configClass, T defaultConfig)
    Deserializes JSON and merges it with a default configuration object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 use
      json - the JSON string to deserialize
      configClass - the configuration class
      defaultConfig - 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 use
      node - the JsonNode to deserialize
      configClass - the configuration class
      defaultConfig - 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 use
      json - the JSON string to deserialize
      configClass - the configuration class
      Returns:
      the deserialized object
      Throws:
      IOException - if deserialization fails