Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Jakarta JSON-P support. #56

Merged
merged 3 commits into from
Sep 17, 2019
Merged

Jakarta JSON-P support. #56

merged 3 commits into from
Sep 17, 2019

Conversation

paulogaspar7
Copy link
Contributor

Add new JmesPath module to support Jakarta JSON-P 1.1.6.

It passes all tests.

@iconara
Copy link
Collaborator

iconara commented Sep 13, 2019

Thank you for the contribution. I will look it through as soon as I can. Could you tell me more about your use case in the meantime? It's interesting to hear what people are using this library for.

@paulogaspar7
Copy link
Contributor Author

A solution I am working on stores and serves JSON documents. I am playing with JMESPath for JSON transformation functionalities, both for document import / export as for creating alternate / partial document views. I think it can be composed with something like JSON Patch.

Copy link
Collaborator

@iconara iconara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some inline comments about two methods that should be removed, but otherwise this looks good.

I have a small nitpick too, do with it as you want: the rest of the code in this repo does casts like this ((String) value) but this PR does ((String)value) (i.e. space between the type and variable).

Good job overall, it's very nice to see how it's possible to support another library with this little effort.

return Json.createValue(n);
}

private JsonValue useJsonNull(JsonValue value) { return (value == null) ? JsonValue.NULL : value; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this and nodeOrNullNode? They look identical to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't believe I did this!

}
}

private String textOnStringOrNull(JsonValue value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name confuses me, specifically the "on" part. Could it be called stringOrNull or textOrNull?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked at the places where this method is used, and I think it's in fact not needed. The callers (createObject and getProperty) don't need to call this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it by the toString(key) call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Still being a bit paranoid here.)

public JsonValue createObject(Map<JsonValue, JsonValue> obj) {
JsonObjectBuilder builder = Json.createObjectBuilder();
for (Map.Entry<JsonValue, JsonValue> entry : obj.entrySet()) {
String key = textOnStringOrNull(entry.getKey());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can key really be null here? That's as far as I know not allowed in JSON, and the docs for the createObject method in Adapter says "The map keys must all be string values."

The Jackson adapter does not check for null in its implementation of this method so it's safe to skip the check.

@Override
public JsonValue getProperty(JsonValue value, JsonValue name) {
if (value.getValueType() == OBJECT) {
return nodeOrNullNode(((JsonObject)value).get(textOnStringOrNull(name)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come the call to textOnStringOrNull here? The object can't have a null key. I think name.getString() should be sufficient here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's very nice to see how it's possible to support another library with this little effort.

Indeed! It just took some hours (part of a day) and most of the effort was spent figuring out the right semantics of this API.

... and I do not benefit from that much experience with JSON, which kind of shows on the glitches you pointed out.

The test battery helps a lot!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations. This library is a really easy both to use and to code for!
:)

@paulogaspar7
Copy link
Contributor Author

Suggested changes applied. Please check if it is ok now.

Copy link
Collaborator

@iconara iconara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll merge and push a release as soon as I can. Sorry if things are taking some time.

Good work.

@iconara iconara merged commit 5646461 into burtcorp:master Sep 17, 2019
@iconara
Copy link
Collaborator

iconara commented Sep 17, 2019

I went ahead and merged. I'll post here when I've done the release, it be a day or two, sorry.

@paulogaspar7
Copy link
Contributor Author

Thank you Theo, that is just fine.

@iconara
Copy link
Collaborator

iconara commented Sep 23, 2019

Released as v0.5.0. Sorry for the delay, and thanks again for the contribution!

@paulogaspar7
Copy link
Contributor Author

No problem. It was short enough for me. :)
Thank you for your really nice and very useful work.

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

Successfully merging this pull request may close these issues.

2 participants