-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update JSON Patch Functionality (#15430)
* Release azure-core-experimental 1.0.0-beta.5 * Changed value to Object instead of JSON string, added getter for JSON Patch operations contained in the document * Fix linting issues * Update JsonPatchDocument to accept JsonSerializer during construction, added support for null in add, replace, and test operations * Additional changes for JSON Patch support * Fix possible exception in toString and suppress Checkstyles for having external dependencies in public API
- Loading branch information
1 parent
378d920
commit 27fdfd6
Showing
10 changed files
with
370 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ntal/src/main/java/com/azure/core/experimental/jsonpatch/JsonPatchDocumentSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.experimental.jsonpatch; | ||
|
||
import com.azure.core.util.CoreUtils; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Handles serialization of a {@link JsonPatchDocument}. | ||
*/ | ||
public class JsonPatchDocumentSerializer extends JsonSerializer<JsonPatchDocument> { | ||
private static final Module MODULE; | ||
|
||
static { | ||
MODULE = new SimpleModule().addSerializer(JsonPatchDocument.class, new JsonPatchDocumentSerializer()); | ||
} | ||
|
||
/** | ||
* Gets the module for this serializer that can be added into an {@link ObjectMapper}. | ||
* | ||
* @return The module for this serializer. | ||
*/ | ||
public static Module getModule() { | ||
return MODULE; | ||
} | ||
|
||
@Override | ||
public void serialize(JsonPatchDocument value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
if (CoreUtils.isNullOrEmpty(value.getJsonPatchOperations())) { | ||
return; | ||
} | ||
|
||
gen.writeStartArray(value.getJsonPatchOperations().size()); | ||
|
||
for (JsonPatchOperation operation : value.getJsonPatchOperations()) { | ||
gen.writeObject(operation); | ||
} | ||
|
||
gen.writeEndArray(); | ||
} | ||
} |
Oops, something went wrong.