Open tvallin opened 5 months ago
This is do-able with JSON-P.
@Path("/patch")
public class JsonPatchResource {
private static final JsonProvider JSON_PROVIDER = JsonProvider.provider();
private JsonObject jsonObject = JsonValue.EMPTY_JSON_OBJECT;
@GET
public JsonObject get() {
return jsonObject;
}
@PUT
public void put(JsonObject jsonObject) {
this.jsonObject = jsonObject;
}
@Consumes("application/json-patch+json")
@POST
public void patch(JsonArray operations) {
JsonPatch patch = JSON_PROVIDER.createPatch(operations);
this.jsonObject = patch.apply(jsonObject);
}
}
# verify the empty initial state
curl http://localhost:8080/patch
{}
# set the object
curl -X PUT -H "Content-Type: application/json" http://localhost:8080/patch -d '{"foo": "bar"}'
# verify the object
curl http://localhost:8080/patch
{"foo":"bar"}
# patch the object
curl -X POST -H "Content-Type: application/json-patch+json" http://localhost:8080/patch -d '[ {"op":"replace","path":"/foo","value": "123"} ]'
# verify the result
curl http://localhost:8080/patch
{"foo":"123"}
We should double-check if this also works with Helidon SE. If this works, we should create examples for both.
Environment Details
Problem Description
Add support for
application/json-patch+json
media type.Steps to reproduce
n/a