Interface XContentHelper.CustomMerge

Enclosing class:
XContentHelper
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface XContentHelper.CustomMerge
A FunctionalInterface that can be used in order to customize map merges.
  • Method Summary

    Modifier and Type
    Method
    Description
    merge(String parent, String key, Object oldValue, Object newValue)
    Based on the provided arguments, compute a value to use for the given key as a merge result.
  • Method Details

    • merge

      @Nullable Object merge(String parent, String key, Object oldValue, Object newValue)
      Based on the provided arguments, compute a value to use for the given key as a merge result. If this method returns a non-null value, then the merge result will replace the original value of the provided key in the base map. If this method returns null, then:
      • if the values are of map type, the old and new values will be merged recursively
      • otherwise, the original value will be maintained
      This method doesn't throw a checked exception, but it is expected that illegal merges will result in a RuntimeException.
      Parameters:
      parent - merged field's parent
      key - merged field's name
      oldValue - original value of the provided key
      newValue - the new value of the provided key which is to be merged with the original
      Returns:
      the merged value to use for the given key, or null if there is no custom merge result for it. If null is returned, the algorithm will live the original value as is, unless it is a map, in which case the new map will be merged into the old map recursively.