Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for application/json-patch+json media type #8627

Open
tvallin opened this issue Apr 8, 2024 · 1 comment
Open

Add support for application/json-patch+json media type #8627

tvallin opened this issue Apr 8, 2024 · 1 comment
Assignees
Labels
3.x Issues for 3.x version branch 4.x Version 4.x enhancement New feature or request examples P5

Comments

@tvallin
Copy link
Member

tvallin commented Apr 8, 2024

Environment Details

  • Helidon Version: 3.2.7
  • Helidon SE and Helidon MP
  • JDK version: 17
  • OS: n/a
  • Docker version (if applicable):

Problem Description

Add support for application/json-patch+json media type.

Steps to reproduce

n/a

@tvallin tvallin added the 3.x Issues for 3.x version branch label Apr 8, 2024
@romain-grecourt
Copy link
Contributor

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.

@m0mus m0mus added enhancement New feature or request examples 4.x Version 4.x labels Apr 22, 2024
@m0mus m0mus added the P5 label Apr 22, 2024
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Low priority in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch 4.x Version 4.x enhancement New feature or request examples P5
Projects
Status: Low priority
Development

No branches or pull requests

3 participants