com.github.fge.jsonpatch.mergepatch
Class JsonMergePatch

java.lang.Object
  extended by com.github.fge.jsonpatch.mergepatch.JsonMergePatch
All Implemented Interfaces:
JsonSerializable

public abstract class JsonMergePatch
extends Object
implements JsonSerializable

Implementation of JSON merge patch

Unlike JSON Patch, JSON Merge Patch only applies to JSON Objects or JSON arrays.


Field Summary
protected static MessageBundle BUNDLE
           
protected static JsonNodeFactory FACTORY
           
protected  JsonNode origPatch
           
 
Constructor Summary
protected JsonMergePatch(JsonNode node)
          Protected constructor
 
Method Summary
abstract  JsonNode apply(JsonNode input)
           
protected static JsonNode clearNulls(JsonNode node)
          Clear "null values" from a JSON value
static JsonMergePatch fromJson(JsonNode input)
           
 void serialize(JsonGenerator jgen, SerializerProvider provider)
           
 void serializeWithType(JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY

protected static final JsonNodeFactory FACTORY

BUNDLE

protected static final MessageBundle BUNDLE

origPatch

protected final JsonNode origPatch
Constructor Detail

JsonMergePatch

protected JsonMergePatch(JsonNode node)
Protected constructor

Only necessary for serialization purposes. The patching process itself never requires the full node to operate.

Parameters:
node - the original patch node
Method Detail

apply

public abstract JsonNode apply(JsonNode input)
                        throws JsonPatchException
Throws:
JsonPatchException

fromJson

public static JsonMergePatch fromJson(JsonNode input)
                               throws JsonPatchException
Throws:
JsonPatchException

clearNulls

protected static JsonNode clearNulls(JsonNode node)
Clear "null values" from a JSON value

Non container values are unchanged. For arrays, null elements are removed. From objects, members whose values are null are removed.

This method is recursive, therefore arrays within objects, or objects within arrays, or arrays within arrays etc are also affected.

Parameters:
node - the original JSON value
Returns:
a JSON value without null values (see description)

serialize

public final void serialize(JsonGenerator jgen,
                            SerializerProvider provider)
                     throws IOException
Specified by:
serialize in interface JsonSerializable
Throws:
IOException

serializeWithType

public final void serializeWithType(JsonGenerator jgen,
                                    SerializerProvider provider,
                                    TypeSerializer typeSer)
                             throws IOException
Specified by:
serializeWithType in interface JsonSerializable
Throws:
IOException