Class JsonMergePatch

  • All Implemented Interfaces:
    com.fasterxml.jackson.databind.JsonSerializable
    Direct Known Subclasses:
    NonObjectMergePatch, ObjectMergePatch

    @ParametersAreNonnullByDefault
    public abstract class JsonMergePatch
    extends Object
    implements com.fasterxml.jackson.databind.JsonSerializable
    Implementation of JSON Merge Patch (RFC 7386)

    JSON Merge Patch is a "toned down" version of JSON Patch. However, it covers a very large number of use cases for JSON value modifications; its focus is mostly on patching JSON Objects, which are by far the most common type of JSON texts exchanged on the Internet.

    Applying a JSON Merge Patch is defined by a single, pseudo code function as follows (quoted from the RFC; indentation fixed):

         define MergePatch(Target, Patch):
             if Patch is an Object:
                 if Target is not an Object:
                     Target = {} # Ignore the contents and set it to an empty Object
                 for each Name/Value pair in Patch:
                     if Value is null:
                         if Name exists in Target:
                             remove the Name/Value pair from Target
                     else:
                         Target[Name] = MergePatch(Target[Name], Value)
                 return Target
             else:
                 return Patch
     
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable

        com.fasterxml.jackson.databind.JsonSerializable.Base
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static com.github.fge.msgsimple.bundle.MessageBundle BUNDLE  
      protected static com.fasterxml.jackson.databind.ObjectMapper MAPPER  
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonMergePatch()  
    • Field Detail

      • MAPPER

        protected static final com.fasterxml.jackson.databind.ObjectMapper MAPPER
      • BUNDLE

        protected static final com.github.fge.msgsimple.bundle.MessageBundle BUNDLE
    • Constructor Detail

      • JsonMergePatch

        public JsonMergePatch()
    • Method Detail

      • apply

        public abstract com.fasterxml.jackson.databind.JsonNode apply​(com.fasterxml.jackson.databind.JsonNode input)
                                                               throws JsonPatchException
        Apply the patch to a given JSON value
        Parameters:
        input - the value to patch
        Returns:
        the patched value
        Throws:
        JsonPatchException - never thrown; only for consistency with JsonPatch
        NullPointerException - value is null