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

Missing a JSON-B to JSON processing bridge, or missing support for JSON PATCH #67

Open
jansupol opened this issue Jan 15, 2018 · 4 comments

Comments

@jansupol
Copy link
Owner

I've posted the complete use case to SO:
https://stackoverflow.com/questions/48194222/missing-bridge-between-json-b-and-json-apis

In short:
In order to implement HTTP PATCH restful method, I'm using JSON processing to apply a JSON PATCH to a DTO annotated with JSON-B. The problem is quite simple: JSON-B converts an object from / to a JSON representation which is serialized / deserialized in a String, resulting in the following strategy to apply a patch:

  1. Use JSON-B to convert the DTO into a JSON representation (String)
  2. Use JSON processing to convert the JSON representation into a JsonObject
  3. Apply the JSON patch
  4. Use JSON processing to convert the result into a JSON representation (String)
  5. Use JSON-B to convert the JSON representation into the original DTO form.

A bridge between both libraries would be great, or if such dependencies are not desired, implementing JSON patch + bean validation to JSON-B would be great.

@jansupol
Copy link
Owner Author

@bravehorsie Commented
If Jsonb would have such an utility brigdge method, it would operate in the same way it is listed in the description. Problem is that JsonPatch operates over JSON object tree model, while Jsonb uses "writer like" JsonGenerator to produce JSON document. In order to integrate native support for JsonPatch into Jsonb, Jsonb would have to understand and support JsonObject tree model, for example to be able to serialize POJO into JsonObject natively without using JSON document as an intermediate layer.

@jansupol
Copy link
Owner Author

@steappe Commented
Most of the examples that explain the usage of jsonb adapters are using JSON processing objects (JsonValue, JsonObject, etc...). It's clear that behind the scene, JSON-B can use these objects, at least for the adapters. So what would be the problem of adding an official bridge between JSON-B and JSON processing for more than just the adapters? IMHO, both should work together.

For instance why not adding in the API of JSON-B:
JsonObject toJsonObject(object);

(that's more or less what JSON-B adapters can do).

@jansupol
Copy link
Owner Author

@bravehorsie Commented

It's clear that behind the scene, JSON-B can use these objects, at least for the adapters.

Behind the scene JSON-B can use any type it has dependency to.

So what would be the problem of adding an official bridge between JSON-B and JSON processing for more than just the adapters?

What official bridge exactly? I don't think bridging all JSONP api would be of much help.

For instance why not adding in the API of JSON-B:
JsonObject toJsonObject(object);

Suggestion 1:
This would mean instead of calling javax.json.stream.JsonGenerator API we would have to call javax.json.JsonObjectBuilder during serialization process. Not that trivial to add support for but possible.

Suggestion 2:
Adding a special method in JSONB API which prints json stream with javax.json.stream.JsonGenerator first and than parses it in JsonStructure with javax.json.JsonReader. Similar to bridging all JSONP api this would not be much of help to users.

@jansupol
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant