-
Notifications
You must be signed in to change notification settings - Fork 183
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
support for withJson-618 #1148
support for withJson-618 #1148
Conversation
Hi, I am converting this PR into a draft , I wanted to share the general approach , i.e for all the classes annotated with Once you are aligned on this approach without any concerns , then changes for all the classes will be implemented in this PR |
I like it! Iterate to green/add some documentation and maybe a sample? |
Can you also please clarify -
|
@dblock any thoughts on above ? |
I think users want it everywhere - are there any arguments to limit it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks alright to me, but as you point out I think we want it at a lower level. Basically any builder that accepts a body should also accept withJson
, shouldn't it?
import org.opensearch.client.json.ObjectBuilderDeserializer; | ||
import org.opensearch.client.json.ObjectDeserializer; | ||
import org.opensearch.client.json.PlainJsonSerializable; | ||
import org.opensearch.client.json.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised this doesn't get trapped by spotless, let's expand these like in all other places (and check spotless configuration please).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that would be my ide auto import :) , I will fix these.
My only concern iswith the classes in which Builders are protected, that means the original intent was to never pass these builders around; for those classes, we will not (or should not ?) be able to implement the withJson method. |
|
@Jai2305 some builders will need to serialize JSON but others ND-JSON (bulk), and some both that may be implemented differently (you can make nd-json from json). So I think (2) doesn't work, no? |
You are right. There can be a work around to add new Abstract classes for NdJson cases, but, this is in general a pretty clunky solution, lets rule it out then. |
@dblock @Jai2305 I have concerns regarding this approach:
(what is the values of
|
@reta Thanks so much for the review ,
PutIndexTemplateRequest indexTemplateRequest = new PutIndexTemplateRequest.Builder().name("My index 2")
.indexPatterns("index_pattern3")
.withJson(inputStream)
.name("name")
.build();
|
Thanks @Jai2305, so what is the behaviour for properties that have not been specified? Will be replaced by I also don't see a clear use case for full fledged builders serde, we do offer the generic client which could be used to manipulate the APIs in JSON only way. |
// setting name using name field on builder
String stringTemplate =
"{\"composed_of\":[\"component1\",\"component2\"],\"index_patterns\":[\"index_pattern1\"]}";
InputStream inputStream = new ByteArrayInputStream(stringTemplate.getBytes(StandardCharsets.UTF_8));
PutIndexTemplateRequest indexTemplateRequest = new PutIndexTemplateRequest.Builder().name("My index 2")...
.withJson(inputStream)
.build(); Or // setting name using withJson
String stringTemplate =
"{\"name\":\"My index\",\"composed_of\":[\"component1\",\"component2\"],\"index_patterns\":[\"index_pattern1\"]}";
InputStream inputStream = new ByteArrayInputStream(stringTemplate.getBytes(StandardCharsets.UTF_8));
PutIndexTemplateRequest indexTemplateRequest = new PutIndexTemplateRequest.Builder()
.withJson(inputStream)
.build(); I think it is perfect that way no? |
Thanks @Jai2305, but than how to set specific value to @dblock do you have any thoughts on this feature in general? |
I was 100% in agreement with @Jai2305's comment in #1148 (comment). A builder's The other option is to only have
By specifying
Right, and the result is the modified builder with whatever you set via |
@Jai2305 WDYT? Thanks so much for hanging in here with us! |
Thank you for your insights @dblock and @reta, |
Thanks @Jai2305
Here is the examples I had in mind:
|
So basically we only implement |
I don't think we have a list but adding is never a problem, it's removing that breaks backwards compat. So I'd add an interface, implement it for the couple of cases we know and then find the missing ones incrementally as people need them. Of course you can comb through https://github.com/opensearch-project/opensearch-api-specification but ... it's a lot of APIs :) |
0411145
to
c101485
Compare
Signed-off-by: Jai2305 <[email protected]>
8bb2517
to
474438b
Compare
I have worked on implementing PlainDeserializable for certain free-form fields within our application. To ensure expected behaviors, I have also added test cases. I've identified these fields as potential candidates based on initial analysis, but I'm also reviewing various request-response cycles to identify additional fields that might benefit from this implementation. I'd appreciate any insights or suggestions you may have regarding other fields that could be suitable for the withJson feature. |
I like this better, start small. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this, @reta?
Let's add some working examples in https://github.com/opensearch-project/opensearch-java/tree/main/samples please?
java-client/src/test/java/org/opensearch/client/opensearch/json/PlainDeserializableTest.java
Outdated
Show resolved
Hide resolved
java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java
Outdated
Show resolved
Hide resolved
java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java
Outdated
Show resolved
Hide resolved
eb87705
to
8bb1177
Compare
I have also added a working sample and an explanation in docs directory for user's reference. |
8bb1177
to
c6cb38a
Compare
java-client/src/main/java/org/opensearch/client/json/JsonpUtils.java
Outdated
Show resolved
Hide resolved
java-client/src/test/java/org/opensearch/client/opensearch/json/PlainJsonSerializableTest.java
Show resolved
Hide resolved
Signed-off-by: Jai2305 <[email protected]>
c6cb38a
to
8d2b565
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, thanks!
@Jai2305 will you please help backport this to 2.x manually? looks like the automatic workflow failed |
Description
Added PlainDeserializable interface with methods for streamlining deserialization process .
Issues Resolved
Closes #618
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.