Skip to content

Commit

Permalink
fix build failure
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed Feb 7, 2023
1 parent ada16d2 commit 986a83d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon
* Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided
* {@link XContentType}. Wraps the output into a new anonymous object according to the value returned
* by the {@link ToXContent#isFragment()} method returns.
*
* @deprecated use {@link #toXContent(ToXContent, MediaType, Params, boolean)} instead
*/
@Deprecated
public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, Params params, boolean humanReadable)
throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
Expand All @@ -513,6 +516,26 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon
}
}

/**
* Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided
* {@link XContentType}. Wraps the output into a new anonymous object according to the value returned
* by the {@link ToXContent#isFragment()} method returns.
*/
public static BytesReference toXContent(ToXContent toXContent, MediaType mediaType, Params params, boolean humanReadable)
throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(mediaType.xContent())) {
builder.humanReadable(humanReadable);
if (toXContent.isFragment()) {
builder.startObject();
}
toXContent.toXContent(builder, params);
if (toXContent.isFragment()) {
builder.endObject();
}
return BytesReference.bytes(builder);
}
}

/**
* Guesses the content type based on the provided bytes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.util.set.Sets;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.MediaType;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.XContent;
Expand Down Expand Up @@ -1237,7 +1238,10 @@ public GeohashGenerator() {
* Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided
* {@link XContentType}. Wraps the output into a new anonymous object according to the value returned
* by the {@link ToXContent#isFragment()} method returns. Shuffles the keys to make sure that parsing never relies on keys ordering.
*
* @deprecated use {@link #toShuffledXContent(ToXContent, MediaType, ToXContent.Params, boolean, String...)} instead
*/
@Deprecated
protected final BytesReference toShuffledXContent(
ToXContent toXContent,
XContentType xContentType,
Expand All @@ -1253,6 +1257,26 @@ protected final BytesReference toShuffledXContent(
}
}

/**
* Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided
* {@link XContentType}. Wraps the output into a new anonymous object according to the value returned
* by the {@link ToXContent#isFragment()} method returns. Shuffles the keys to make sure that parsing never relies on keys ordering.
*/
protected final BytesReference toShuffledXContent(
ToXContent toXContent,
MediaType mediaType,
ToXContent.Params params,
boolean humanReadable,
String... exceptFieldNames
) throws IOException {
BytesReference bytes = XContentHelper.toXContent(toXContent, mediaType, params, humanReadable);
try (XContentParser parser = createParser(mediaType.xContent(), bytes)) {
try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) {
return BytesReference.bytes(builder);
}
}
}

/**
* Randomly shuffles the fields inside objects in the {@link XContentBuilder} passed in.
* Recursively goes through inner objects and also shuffles them. Exceptions for this
Expand Down

0 comments on commit 986a83d

Please sign in to comment.