Repository navigation
Conversation
242f5f9 to
f90ae64
Compare
9fd3247 to
a250890
Compare
5c5b114 to
a551a4d
Compare
cc69911 to
b2d4982
Compare
b2d4982 to
c11fff3
Compare
Signed-off-by: Jai2305 <jainjai2305@gmail.com>
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 |
| public interface JsonpSerializable { | ||
|
|
||
| void serialize(JsonGenerator generator, JsonpMapper mapper); | ||
|
|
There was a problem hiding this comment.
Super nit, could you please revert this change? (so the commit would be clean)
| 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.
| public class JsonpSerializableTest extends Assert { | |
| public class PlainJsonSerializableTest extends Assert { |
There was a problem hiding this comment.
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! |
dblock
left a comment
There was a problem hiding this comment.
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.
| ### 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.
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.
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 :)
87cbc97 to
5ff4a6f
Compare
dblock
left a comment
There was a problem hiding this comment.
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 <jainjai2305@gmail.com>
5ff4a6f to
020e497
Compare
|
Ignore it. I think someone was looking into it. |
* 588 - [FEATURE] serialize requests to JSON Signed-off-by: Jai2305 <jainjai2305@gmail.com> * 588 - [ENHANCEMENT] New interface PlainJsonSerializable and optimizing imports Signed-off-by: Jai2305 <jainjai2305@gmail.com> --------- Signed-off-by: Jai2305 <jainjai2305@gmail.com> (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 <jainjai2305@gmail.com> 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
PlainJsonSerializableextendingJsonpSerializablehaving 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.JsonpSerializablemay now implementPlainJsonSerializableif they are required to carry the added default method otherwise they may implementJsonpSerializableIssues 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.