Package javax.json

Interface JsonMergePatch


  • public interface JsonMergePatch
    This interface represents an implementation of a JSON Merge Patch as defined by RFC 7396.

    This is a near-exact copy of the same-titled Java EE 8 Class: javax.json.JsonMergePatch
    Commenting has been slightly modified to accompany HiLiting the Code Examples.
    Java Source Code remains identical to the Sun-Oracle & 'GlassFish' Released Distributions.

    Read included License: HERE, and the CDDL+GPL-1.1
    All javax.json.* Code Obtained From: GitHub JavaEE jsonp  Public Archive.


    A JsonMergePatch can be instantiated with Json.createMergePatch(JsonValue) by specifying the patch operations in a JSON Merge Patch or using Json.createMergeDiff(JsonValue, JsonValue) to create a JSON Merge Patch based on the difference between two JsonValues.

    The following illustrates both approaches.

    1. Construct a JsonMergePatch with an existing JSON Merge Patch.

     JsonValue        contacts    = ... ;     // The target to be patched
     JsonValue        patch       = ...  ;    // JSON Merge Patch
     JsonMergePatch   mergePatch  = Json.createMergePatch(patch);
     JsonValue        result      = mergePatch.apply(contacts);
    


    2. Construct a JsonMergePatch from a difference between two JsonValues.

     JsonValue      source      = ... ; // The source object
     JsonValue      target      = ... ; // The modified object
     JsonMergePatch mergePatch  = Json.createMergeDiff(source, target);
      // The diff between source and target in a Json Merge Patch format
    
    Since:
    1.1
    See Also:
    RFC 7396


    • Method Detail

      • apply

        🡇     🗕  🗗  🗖
        JsonValue apply​(JsonValue target)
        Applies the JSON Merge Patch to the specified target. The target is not modified by the patch.
        Parameters:
        target - the target to apply the merge patch
        Returns:
        the transformed target after the patch