@@ -87,7 +87,7 @@ static Change<String> ofTextUpsert(String path, String text) {
8787 */
8888 static Change <JsonNode > ofJsonUpsert (String path , String jsonText ) {
8989 requireNonNull (jsonText , "jsonText" );
90- return new JsonChange (path , ChangeType .UPSERT_JSON , jsonText );
90+ return new StructuredChange (path , ChangeType .UPSERT_JSON , jsonText );
9191 }
9292
9393 /**
@@ -98,7 +98,18 @@ static Change<JsonNode> ofJsonUpsert(String path, String jsonText) {
9898 */
9999 static Change <JsonNode > ofJsonUpsert (String path , JsonNode jsonNode ) {
100100 requireNonNull (jsonNode , "jsonNode" );
101- return new JsonChange (path , ChangeType .UPSERT_JSON , jsonNode );
101+ return new StructuredChange (path , ChangeType .UPSERT_JSON , jsonNode );
102+ }
103+
104+ /**
105+ * Returns a newly-created {@link Change} whose type is {@link ChangeType#UPSERT_YAML}.
106+ *
107+ * @param path the path of the file
108+ * @param yamlText the content of the file
109+ */
110+ static Change <JsonNode > ofYamlUpsert (String path , String yamlText ) {
111+ requireNonNull (yamlText , "yamlText" );
112+ return new StructuredChange (path , ChangeType .UPSERT_YAML , yamlText );
102113 }
103114
104115 /**
@@ -192,14 +203,15 @@ static Change<JsonNode> ofJsonPatch(String path, @Nullable String oldJsonText, S
192203 final JsonNode newJsonNode ;
193204 try {
194205 oldJsonNode = oldJsonText == null ? Jackson .nullNode
195- : Jackson .readTree (oldJsonText );
196- newJsonNode = Jackson .readTree (newJsonText );
206+ : Jackson .readTree (path , oldJsonText );
207+ newJsonNode = Jackson .readTree (path , newJsonText );
197208 } catch (IOException e ) {
198209 throw new ChangeFormatException ("failed to read a value as a JSON tree" , e );
199210 }
200211
201- return new JsonChange (path , ChangeType .APPLY_JSON_PATCH ,
202- JsonPatch .generate (oldJsonNode , newJsonNode , ReplaceMode .SAFE ).toJson ());
212+ return new StructuredChange (path , ChangeType .APPLY_JSON_PATCH ,
213+ JsonPatch .generate (oldJsonNode , newJsonNode , ReplaceMode .SAFE )
214+ .toJson ());
203215 }
204216
205217 /**
@@ -216,24 +228,33 @@ static Change<JsonNode> ofJsonPatch(String path, @Nullable JsonNode oldJsonNode,
216228 oldJsonNode = Jackson .nullNode ;
217229 }
218230
219- return new JsonChange (path , ChangeType .APPLY_JSON_PATCH ,
220- JsonPatch .generate (oldJsonNode , newJsonNode , ReplaceMode .SAFE ).toJson ());
231+ return new StructuredChange (path , ChangeType .APPLY_JSON_PATCH ,
232+ JsonPatch .generate (oldJsonNode , newJsonNode , ReplaceMode .SAFE )
233+ .toJson ());
221234 }
222235
223236 /**
224237 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
238+ * The JSON patch operation can be applied to JSON, JSON5, YAML files.
239+ *
240+ * <p>Note that the JSON patch operation normalizes the original data before applying the patch,
241+ * so contextual information such as comments cannot be retained when the patch is applied.
225242 *
226243 * @param path the path of the file
227244 * @param jsonPatch the patch in <a href="https://datatracker.ietf.org/doc/html/rfc6902">JSON patch format</a>
228245 */
229246 static Change <JsonNode > ofJsonPatch (String path , JsonPatchOperation jsonPatch ) {
230247 requireNonNull (path , "path" );
231248 requireNonNull (jsonPatch , "jsonPatch" );
232- return new JsonChange (path , ChangeType .APPLY_JSON_PATCH , jsonPatch .toJsonNode ());
249+ return new StructuredChange (path , ChangeType .APPLY_JSON_PATCH , jsonPatch .toJsonNode ());
233250 }
234251
235252 /**
236253 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
254+ * The JSON patch operation can be applied to JSON, JSON5, YAML files.
255+ *
256+ * <p>Note that the JSON patch operation normalizes the original data before applying the patch,
257+ * so contextual information such as comments cannot be retained when the patch is applied.
237258 *
238259 * @param path the path of the file
239260 * @param jsonPatches the list of patches in <a href="https://datatracker.ietf.org/doc/html/rfc6902">JSON patch format</a>
@@ -245,6 +266,10 @@ static Change<JsonNode> ofJsonPatch(String path, JsonPatchOperation... jsonPatch
245266
246267 /**
247268 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
269+ * The JSON patch operation can be applied to JSON, JSON5, YAML files.
270+ *
271+ * <p>Note that the JSON patch operation normalizes the original data before applying the patch,
272+ * so contextual information such as comments cannot be retained when the patch is applied.
248273 *
249274 * @param path the path of the file
250275 * @param jsonPatches the list of patches in <a href="https://datatracker.ietf.org/doc/html/rfc6902">JSON patch format</a>
@@ -253,12 +278,16 @@ static Change<JsonNode> ofJsonPatch(String path, Iterable<? extends JsonPatchOpe
253278 requireNonNull (path , "path" );
254279 requireNonNull (jsonPatches , "jsonPatches" );
255280 checkArgument (!Iterables .isEmpty (jsonPatches ), "jsonPatches cannot be empty" );
256- return new JsonChange (path , ChangeType .APPLY_JSON_PATCH ,
257- JsonPatchOperation .asJsonArray (jsonPatches ));
281+ return new StructuredChange (path , ChangeType .APPLY_JSON_PATCH ,
282+ JsonPatchOperation .asJsonArray (jsonPatches ));
258283 }
259284
260285 /**
261286 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
287+ * The JSON patch operation can be applied to JSON, JSON5, YAML files.
288+ *
289+ * <p>Note that the JSON patch operation normalizes the original data before applying the patch,
290+ * so contextual information such as comments cannot be retained when the patch is applied.
262291 *
263292 * @param path the path of the file
264293 * @param jsonPatchText the patch in <a href="https://datatracker.ietf.org/doc/html/rfc6902">JSON patch format</a>
@@ -280,14 +309,18 @@ static Change<JsonNode> ofJsonPatch(String path, String jsonPatchText) {
280309
281310 /**
282311 * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
312+ * The JSON patch operation can be applied to JSON, JSON5, YAML files.
313+ *
314+ * <p>Note that the JSON patch operation normalizes the original data before applying the patch,
315+ * so contextual information such as comments cannot be retained when the patch is applied.
283316 *
284317 * @param path the path of the file
285318 * @param jsonPatchNode the patch in <a href="https://datatracker.ietf.org/doc/html/rfc6902">JSON patch format</a>
286319 */
287320 static Change <JsonNode > ofJsonPatch (String path , JsonNode jsonPatchNode ) {
288321 requireNonNull (jsonPatchNode , "jsonPatchNode" );
289322
290- return new JsonChange (path , ChangeType .APPLY_JSON_PATCH , jsonPatchNode );
323+ return new StructuredChange (path , ChangeType .APPLY_JSON_PATCH , jsonPatchNode );
291324 }
292325
293326 /**
0 commit comments