11/*
22 * Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
3+ * Copyright (c) 2016, Alexander Patrikalakis (amcp@me.com)
4+ * Copyright (c) 2015, Daisuke Miyamoto (dai.0304@gmail.com)
35 *
46 * This software is dual-licensed under:
57 *
1921
2022package com .github .fge .jsonpatch ;
2123
24+ import com .amazonaws .services .dynamodbv2 .xspec .ExpressionSpecBuilder ;
2225import com .fasterxml .jackson .annotation .JsonCreator ;
2326import com .fasterxml .jackson .core .JsonGenerator ;
2427import com .fasterxml .jackson .databind .JsonNode ;
3235
3336import java .io .IOException ;
3437import java .util .List ;
38+ import java .util .function .Supplier ;
3539
3640/**
3741 * Implementation of JSON Patch
8993 * <p><b>IMPORTANT NOTE:</b> the JSON Patch is supposed to be VALID when the
9094 * constructor for this class ({@link JsonPatch#fromJson(JsonNode)} is used.</p>
9195 */
92- public final class JsonPatch
93- implements JsonSerializable
96+ public class JsonPatch
97+ implements JsonSerializable , Supplier < ExpressionSpecBuilder >
9498{
9599 private static final MessageBundle BUNDLE
96100 = MessageBundles .getBundle (JsonPatchMessages .class );
97101
98102 /**
99103 * List of operations
100104 */
101- private final List <JsonPatchOperation > operations ;
105+ protected final List <JsonPatchOperation > operations ;
102106
103107 /**
104108 * Constructor
@@ -126,7 +130,7 @@ public static JsonPatch fromJson(final JsonNode node)
126130 throws IOException
127131 {
128132 BUNDLE .checkNotNull (node , "jsonPatch.nullInput" );
129- return JacksonUtils .getReader ().withType (JsonPatch .class )
133+ return JacksonUtils .getReader ().forType (JsonPatch .class )
130134 .readValue (node );
131135 }
132136
@@ -148,6 +152,19 @@ public JsonNode apply(final JsonNode node)
148152
149153 return ret ;
150154 }
155+
156+ /**
157+ * Converts this JsonPatch into an ExpressionSpecBuilder
158+ * @return an expression spec builder that contains the updates contained in this
159+ * patch
160+ */
161+ public ExpressionSpecBuilder get () {
162+ ExpressionSpecBuilder builder = new ExpressionSpecBuilder ();
163+ for (JsonPatchOperation operation : operations ) {
164+ operation .applyToBuilder (builder );
165+ }
166+ return builder ;
167+ }
151168
152169 @ Override
153170 public String toString ()
0 commit comments