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

Getting deeper nested JSON objects as String #2938

Closed
dmaier-redislabs opened this issue Mar 9, 2022 · 8 comments · Fixed by #3005
Closed

Getting deeper nested JSON objects as String #2938

dmaier-redislabs opened this issue Mar 9, 2022 · 8 comments · Fixed by #3005
Labels
Milestone

Comments

@dmaier-redislabs
Copy link
Contributor

This is also not a bug, but more a potential usability improvement.

I would like to be able to get the result of client.getJson as a String in order to use a customer deserialization method.

A related question Why does client.getJson(key, Path.ROOT_PATH) return a Gson LinkedTreeMap, but client.getJson(key, Path2.ROOT_PATH) returns an org.json.JSONArray? It seems that we use two different libraries for Json representations here. Is this by intention? Can I influence the result deserialization somehow by plugging my own deserializer in?

@dmaier-redislabs dmaier-redislabs changed the title Getting JSON either as String Getting JSON as String Mar 9, 2022
@sazzad16
Copy link
Collaborator

@dmaier-redislabs Let's check our test suit:

client.jsonSet("str", ROOT_PATH, "strong");
assertEquals("strong", client.jsonGet("str"));

When we set a plain String using jsonSet, we are getting a plain String using plain jsonGet. Again I am really confused what are you missing and/or asking for.

@sazzad16
Copy link
Collaborator

@dmaier-redislabs For the second part of your question:

org.json is found out to be simple but the best solution to support RedisJSON V2.

As for Gson, the idea was brought from JRedisJSON where the approach to support RedisJSON V1 was decided several years ago.

@dmaier-redislabs
Copy link
Contributor Author

  1. Sure if I just set a JSONElement that is a String, then I get a String. If I got it corrctly this because my JSON contains then no nesting, but a JSONElement that is that String. So this doesn't address my problem. The ask is to set a JSON object that is deeper nested, but then return the object in its String representation. Why? Simply because I think that I am not the only one who would prefer to use a custom JSON deserializer.

  2. OK, so GSon is legacy? So Path2 refers to v2 of RedisJSON v2? I would expect that both Gson and org.json are fully JSON compliant (https://www.json.org/json-en.html). I found it just confusing to deal with two JSON libraries when using the client library.

@dmaier-redislabs dmaier-redislabs changed the title Getting JSON as String Getting deeper nested JSON objects as String Mar 11, 2022
@sazzad16
Copy link
Collaborator

Consider

  • <T> T executeCommand(CommandObject<T> commandObject) method - where you can provide your deserializer as Builder<T>.
  • Object executeCommand(CommandArguments args) method - where you receive just the response from server and you can apply your deserializer on it.

@dmaier-redislabs
Copy link
Contributor Author

Yeah, but it's not really good usability to refer to a very general low-level method. Is your solution applicable to getJson(...)?

@sazzad16
Copy link
Collaborator

it's not really good usability to refer to a very general low-level method.

Aren't you looking for something low-level anyway? I get that it's even lower than your expectation but you won't always get what you want. There would trade offs.

Is your solution applicable to getJson(...)?

I don't understand your question. What/Where is getJson(...)?

@dmaier-redislabs
Copy link
Contributor Author

It's fine. I am getting that there is no way to pass the builder to the high-level method. Usability-wise it would be enough to retrieve the result a JSON string (stringified JSON, not a String property). This seems to be the case with Path2. Again, this is all about usability. It was just not totally obvious to me when/why to use Path2 vs. Path. I didn't associate it to the version. So is it expected that developers use from now on (with the new RedisJSON version) always Path2, and Path will no longer be used in the future?

@sazzad16
Copy link
Collaborator

It entirely depends on the RedisJSON.

@sazzad16 sazzad16 linked a pull request May 28, 2022 that will close this issue
@sazzad16 sazzad16 added this to the 4.3.0 milestone May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants