-
Notifications
You must be signed in to change notification settings - Fork 187
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
588 - [FEATURE] serialize requests to JSON #1064
588 - [FEATURE] serialize requests to JSON #1064
Conversation
242f5f9
to
f90ae64
Compare
java-client/src/main/java/org/opensearch/client/json/JsonpSerializable.java
Outdated
Show resolved
Hide resolved
9fd3247
to
a250890
Compare
5c5b114
to
a551a4d
Compare
java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpSerializableTest.java
Outdated
Show resolved
Hide resolved
java-client/src/main/java/org/opensearch/client/json/JsonpSerializable.java
Outdated
Show resolved
Hide resolved
cc69911
to
b2d4982
Compare
java-client/src/main/java/org/opensearch/client/json/JsonpSerializable.java
Outdated
Show resolved
Hide resolved
b2d4982
to
c11fff3
Compare
Signed-off-by: Jai2305 <[email protected]>
c11fff3
to
ce514fc
Compare
Btw, not sure this will work as part of this PR, but we also want serialization of ndjson requests (e.g. bulk). |
There are 2 ways to tackle that (off the top of my head, there are more for sure):
|
public interface JsonSerializable {
void serialize(JsonGenerator generator, JsonpMapper mapper);
} public interface JsonpSerializable extends JsonSerializable {
default String toJsonString() {
try (StringWriter writer = new StringWriter()) {
try (JsonGenerator generator = JsonpUtils.DEFAULT_PROVIDER.createGenerator(writer)) {
serialize(generator, JsonpUtils.DEFAULT_JSONP_MAPPER);
}
return writer.toString();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
} public interface NDJsonSerializable extends JsonSerializable {
....
} |
I think this is what is being suggested (keeping |
Yes , I am suggesting a new parent interface and keep |
I think it circles back to the reasons why not to do that (#1064 (comment)). The goal is to have 2 separate hierarchies, public interface PlainNdJsonSerializable extends JsonpSerializable {
default Collection<String> toJsonStrings() {
}
} |
public interface NdJsonpSerializable {
Iterator<?> _serializables();
} how does this fit in the suggested model. |
Correct, it fits super well I believe, for example:
|
@reta added a separate commit for a new interface
|
Thanks @Jai2305
Expected, thank you!
That could be done on case by case I believe , the one of such is |
@@ -40,4 +40,5 @@ | |||
public interface JsonpSerializable { | |||
|
|||
void serialize(JsonGenerator generator, JsonpMapper mapper); | |||
|
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.
Super nit, could you please revert this change? (so the commit would be clean)
java-client/src/main/java/org/opensearch/client/json/PlainJsonSerializable.java
Show resolved
Hide resolved
java-client/src/main/java/org/opensearch/client/json/PlainJsonSerializable.java
Show resolved
Hide resolved
import org.opensearch.client.opensearch.core.IndexResponse; | ||
import org.opensearch.client.opensearch.core.SearchRequest; | ||
|
||
public class JsonpSerializableTest extends Assert { |
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.
public class JsonpSerializableTest extends Assert { | |
public class PlainJsonSerializableTest extends Assert { |
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.
Fixed according to suggestions , also changed CHANGELOG.md to reflect the addition of new interface, I will have a check on the code, but please let me know , if you find anything out of order.
c2203fd
to
87cbc97
Compare
@dblock could you take a look as well please? thank you! |
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 have some nits on CHANGELOG and errors.
More importantly, can we update https://github.com/opensearch-project/opensearch-java/blob/main/USER_GUIDE.md or one of the guides with this (possibly a new one called json.md)? Even something basic would be great.
CHANGELOG.md
Outdated
@@ -12,6 +12,7 @@ This section is for maintaining a changelog for all breaking changes for the cli | |||
### Added | |||
- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330)) | |||
- Add support for phase_took & search_pipeline request params ([#1036](https://github.com/opensearch-project/opensearch-java/pull/1036)) | |||
- Add an interface PlainJsonSerializable extending JsonpSerializable having default serialize method.([#1064](https://github.com/opensearch-project/opensearch-java/pull/1064)) |
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.
Remove the period and add a space to match other CHANGELOG lines.
I think we should explain the purpose of this Add support for serializing requests and responses to plain JSON and nd-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.
Sorry for the delay, I have made a change on this, tried to keep it short and clear in meaning, please let me know if any work is remaining , and when can we merge this PR and withJson , very much needed .
thanks a lot :)
java-client/src/main/java/org/opensearch/client/json/JsonpUtils.java
Outdated
Show resolved
Hide resolved
...lient/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java
Show resolved
Hide resolved
87cbc97
to
5ff4a6f
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.
I am good with merging this.
There's a build failure with the generator, which I think is legit, and a template needs to be modified, please take a look?
Thank you!
…g imports Signed-off-by: Jai2305 <[email protected]>
5ff4a6f
to
020e497
Compare
|
Ignore it. I think someone was looking into it. |
* 588 - [FEATURE] serialize requests to JSON Signed-off-by: Jai2305 <[email protected]> * 588 - [ENHANCEMENT] New interface PlainJsonSerializable and optimizing imports Signed-off-by: Jai2305 <[email protected]> --------- Signed-off-by: Jai2305 <[email protected]> (cherry picked from commit df46d73) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Merged, thanks. @Jai2305, will you document this in USERS_GUIDE, maybe a new |
* 588 - [FEATURE] serialize requests to JSON * 588 - [ENHANCEMENT] New interface PlainJsonSerializable and optimizing imports --------- (cherry picked from commit df46d73) Signed-off-by: Jai2305 <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Serialize requests to JSON
PlainJsonSerializable
extendingJsonpSerializable
having a default method to streamline serialization process ( get a string representation of instances of all classes implementing PlainJsonSerializable interface ) , which abstracts away the implementation of having to call serialize method with mapper and generator.JsonpSerializable
may now implementPlainJsonSerializable
if they are required to carry the added default method otherwise they may implementJsonpSerializable
Issues Resolved - Issue #588
SignOff -
I understand and agree that this project and the contribution are public and that a record of the contribution (including
all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Please check Developer Certificate of Origin here.