diff --git a/CHANGELOG.md b/CHANGELOG.md index a776020be91cc..268e47d6f67f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Refactor] core.common to new opensearch-common library ([#5976](https://github.com/opensearch-project/OpenSearch/pull/5976)) - Update API spec for cluster health API ([#6399](https://github.com/opensearch-project/OpenSearch/pull/6399)) - Remove deprecated org.gradle.util.DistributionLocator usage ([#6212](https://github.com/opensearch-project/OpenSearch/pull/6212)) +- Require MediaType in Strings.toString API ([#6009](https://github.com/opensearch-project/OpenSearch/pull/6009)) ### Deprecated diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicy.java b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicy.java index a6e08fc6df018..3c1203760cf9e 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicy.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicy.java @@ -39,6 +39,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Map; @@ -168,6 +169,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicyMetadata.java b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicyMetadata.java index 199805d348fd4..38b04c3df7402 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicyMetadata.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecyclePolicyMetadata.java @@ -39,6 +39,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.snapshots.SnapshotId; import java.io.IOException; @@ -288,7 +289,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecycleStats.java b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecycleStats.java index 74d3d21952499..8e9722aba6400 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecycleStats.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotLifecycleStats.java @@ -40,6 +40,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Collections; @@ -187,7 +188,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } public static class SnapshotPolicyStats implements ToXContentFragment { diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotRetentionConfiguration.java b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotRetentionConfiguration.java index 2f2aa778b6958..157013e70e9c3 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotRetentionConfiguration.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/slm/SnapshotRetentionConfiguration.java @@ -40,6 +40,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -150,6 +151,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/distribution/archives/integ-test-zip/src/test/java/org/opensearch/test/rest/NodeRestUsageIT.java b/distribution/archives/integ-test-zip/src/test/java/org/opensearch/test/rest/NodeRestUsageIT.java index cb2318351086c..d397a1c967ad0 100644 --- a/distribution/archives/integ-test-zip/src/test/java/org/opensearch/test/rest/NodeRestUsageIT.java +++ b/distribution/archives/integ-test-zip/src/test/java/org/opensearch/test/rest/NodeRestUsageIT.java @@ -36,6 +36,7 @@ import org.opensearch.client.Response; import org.opensearch.client.ResponseException; import org.opensearch.common.Strings; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.aggregations.AggregationBuilders; import org.opensearch.search.builder.SearchSourceBuilder; @@ -171,8 +172,8 @@ public void testAggregationUsage() throws IOException { .aggregation(AggregationBuilders.terms("str_terms").field("str.keyword")) .aggregation(AggregationBuilders.terms("num_terms").field("num")) .aggregation(AggregationBuilders.avg("num_avg").field("num")); - searchRequest.setJsonEntity(Strings.toString(searchSource)); - searchRequest.setJsonEntity(Strings.toString(searchSource)); + searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource)); + searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource)); client().performRequest(searchRequest); searchRequest = new Request("GET", "/test/_search"); @@ -181,8 +182,8 @@ public void testAggregationUsage() throws IOException { .aggregation(AggregationBuilders.avg("num1").field("num")) .aggregation(AggregationBuilders.avg("num2").field("num")) .aggregation(AggregationBuilders.terms("foo").field("foo.keyword")); - String r = Strings.toString(searchSource); - searchRequest.setJsonEntity(Strings.toString(searchSource)); + String r = Strings.toString(XContentType.JSON, searchSource); + searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource)); client().performRequest(searchRequest); Response response = client().performRequest(new Request("GET", "_nodes/usage")); diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java index 5cfc52b20bfc5..3fad89152cc45 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java @@ -62,4 +62,6 @@ public interface MediaType { default String typeWithSubtype() { return type() + "/" + subtype(); } + + XContent xContent(); } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java index 1c745f591e38b..32283698beaf8 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java @@ -190,8 +190,6 @@ public String mediaType() { return mediaTypeWithoutParameters(); } - public abstract XContent xContent(); - public abstract String mediaTypeWithoutParameters(); @Override diff --git a/libs/x-content/src/test/java/org/opensearch/common/xcontent/SimpleStruct.java b/libs/x-content/src/test/java/org/opensearch/common/xcontent/SimpleStruct.java index acc6dc4c8aa3c..27cb58569fc3f 100644 --- a/libs/x-content/src/test/java/org/opensearch/common/xcontent/SimpleStruct.java +++ b/libs/x-content/src/test/java/org/opensearch/common/xcontent/SimpleStruct.java @@ -101,6 +101,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java index 1802d03e20942..3f20e3d14c985 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MultiSearchTemplateResponse.java @@ -46,6 +46,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Arrays; @@ -206,6 +207,6 @@ public static MultiSearchTemplateResponse fromXContext(XContentParser parser) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java index 7c4b8956d9e3c..d320a279bbfc5 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/mapper/SearchAsYouTypeFieldMapperTests.java @@ -53,6 +53,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.lucene.search.MultiPhrasePrefixQuery; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexSettings; import org.opensearch.index.analysis.AnalyzerScope; import org.opensearch.index.analysis.IndexAnalyzers; @@ -609,7 +610,7 @@ public void testAnalyzerSerialization() throws IOException { b.field("type", "search_as_you_type"); b.field("analyzer", "simple"); })); - String serialized = Strings.toString(ms.documentMapper()); + String serialized = Strings.toString(XContentType.JSON, ms.documentMapper()); assertEquals( serialized, "{\"_doc\":{\"properties\":{\"field\":" @@ -617,7 +618,7 @@ public void testAnalyzerSerialization() throws IOException { ); merge(ms, mapping(b -> {})); - assertEquals(serialized, Strings.toString(ms.documentMapper())); + assertEquals(serialized, Strings.toString(XContentType.JSON, ms.documentMapper())); } private void documentParsingTestCase(Collection values) throws IOException { diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java index 23b42846458a2..2d0c8ad230b78 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalResponse.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParserUtils; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Collections; @@ -105,7 +106,7 @@ public Map getFailures() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalSpec.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalSpec.java index 8708c94c353e4..501fd68a2b36b 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalSpec.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RankEvalSpec.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParserUtils; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.script.Script; import java.io.IOException; @@ -249,7 +250,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedDocument.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedDocument.java index 5f9a71cd25e7b..76ebe0405daaa 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedDocument.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedDocument.java @@ -41,6 +41,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -128,7 +129,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedRequest.java b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedRequest.java index 5289a3945db52..09830b803f030 100644 --- a/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedRequest.java +++ b/modules/rank-eval/src/main/java/org/opensearch/index/rankeval/RatedRequest.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.rankeval.RatedDocument.DocumentKey; import org.opensearch.search.builder.SearchSourceBuilder; @@ -340,7 +341,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/DiscountedCumulativeGainTests.java b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/DiscountedCumulativeGainTests.java index 2b1c56d9bba3b..2bf229b094245 100644 --- a/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/DiscountedCumulativeGainTests.java +++ b/modules/rank-eval/src/test/java/org/opensearch/index/rankeval/DiscountedCumulativeGainTests.java @@ -323,10 +323,13 @@ public void testMetricDetails() { + ",\"unrated_docs\":" + unratedDocs + "}}", - Strings.toString(detail) + Strings.toString(XContentType.JSON, detail) ); } else { - assertEquals("{\"dcg\":{\"dcg\":" + dcg + ",\"unrated_docs\":" + unratedDocs + "}}", Strings.toString(detail)); + assertEquals( + "{\"dcg\":{\"dcg\":" + dcg + ",\"unrated_docs\":" + unratedDocs + "}}", + Strings.toString(XContentType.JSON, detail) + ); } } diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java index 714d8a252579f..959816f94494e 100644 --- a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java @@ -46,6 +46,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.common.xcontent.support.XContentMapValues; import org.opensearch.index.IndexSettings; @@ -1372,7 +1373,7 @@ public void testResize() throws Exception { if (randomBoolean()) { settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true); } - shrinkRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}"); + shrinkRequest.setJsonEntity("{\"settings\":" + Strings.toString(XContentType.JSON, settings.build()) + "}"); client().performRequest(shrinkRequest); ensureGreenLongWait(target); assertNumHits(target, numDocs + moreDocs, 1); @@ -1384,7 +1385,7 @@ public void testResize() throws Exception { settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true); } Request splitRequest = new Request("PUT", "/" + index + "/_split/" + target); - splitRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}"); + splitRequest.setJsonEntity("{\"settings\":" + Strings.toString(XContentType.JSON, settings.build()) + "}"); client().performRequest(splitRequest); ensureGreenLongWait(target); assertNumHits(target, numDocs + moreDocs, 6); diff --git a/qa/multi-cluster-search/src/test/java/org/opensearch/search/CCSDuelIT.java b/qa/multi-cluster-search/src/test/java/org/opensearch/search/CCSDuelIT.java index 9913e5816e856..ec6789d702743 100644 --- a/qa/multi-cluster-search/src/test/java/org/opensearch/search/CCSDuelIT.java +++ b/qa/multi-cluster-search/src/test/java/org/opensearch/search/CCSDuelIT.java @@ -726,7 +726,7 @@ public void testCompletionSuggester() throws Exception { sourceBuilder.suggest(suggestBuilder); duelSearch(searchRequest, response -> { assertMultiClusterSearchResponse(response); - assertEquals(Strings.toString(response, true, true), 3, response.getSuggest().size()); + assertEquals(Strings.toString(XContentType.JSON, response, true, true), 3, response.getSuggest().size()); assertThat(response.getSuggest().getSuggestion("python").getEntries().size(), greaterThan(0)); assertThat(response.getSuggest().getSuggestion("java").getEntries().size(), greaterThan(0)); assertThat(response.getSuggest().getSuggestion("ruby").getEntries().size(), greaterThan(0)); diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/MappingTypeRemovalIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/MappingTypeRemovalIT.java index 39e1b36ff8d58..89bb0f9bcf7b0 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/MappingTypeRemovalIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/MappingTypeRemovalIT.java @@ -19,6 +19,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -203,7 +204,7 @@ private void bulk(String index, String valueSuffix, int count) throws IOExceptio private void createIndexWithDocMappings(String index, Settings settings, String mapping) throws IOException { Request createIndexWithMappingsRequest = new Request(HttpPut.METHOD_NAME, "/" + index); - String entity = "{\"settings\": " + Strings.toString(settings); + String entity = "{\"settings\": " + Strings.toString(XContentType.JSON, settings); if (mapping != null) { entity += ",\"mappings\" : {" + mapping + "}"; } diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java index cbf91fa9d71e7..962b9d9726ae2 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java @@ -45,6 +45,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.AbstractRunnable; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.support.XContentMapValues; import org.opensearch.index.IndexSettings; import org.opensearch.rest.RestStatus; @@ -800,7 +801,7 @@ public void testSoftDeletesDisabledWarning() throws Exception { settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), softDeletesEnabled); } Request request = new Request("PUT", "/" + indexName); - request.setJsonEntity("{\"settings\": " + Strings.toString(settings.build()) + "}"); + request.setJsonEntity("{\"settings\": " + Strings.toString(XContentType.JSON, settings.build()) + "}"); if (softDeletesEnabled == false) { expectSoftDeletesWarning(request, indexName); } diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java index 5c48ddf7ca7a0..63f4e2187e571 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java @@ -98,7 +98,7 @@ public void testAutomaticCancellationDuringQueryPhase() throws Exception { Request searchRequest = new Request("GET", "/test/_search"); SearchSourceBuilder searchSource = new SearchSourceBuilder().query(scriptQuery( new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.SCRIPT_NAME, Collections.emptyMap()))); - searchRequest.setJsonEntity(Strings.toString(searchSource)); + searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource)); verifyCancellationDuringQueryPhase(SearchAction.NAME, searchRequest); } @@ -147,7 +147,7 @@ public void testAutomaticCancellationDuringFetchPhase() throws Exception { Request searchRequest = new Request("GET", "/test/_search"); SearchSourceBuilder searchSource = new SearchSourceBuilder().scriptField("test_field", new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.SCRIPT_NAME, Collections.emptyMap())); - searchRequest.setJsonEntity(Strings.toString(searchSource)); + searchRequest.setJsonEntity(Strings.toString(XContentType.JSON, searchSource)); verifyCancellationDuringFetchPhase(SearchAction.NAME, searchRequest); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java index 6311ac6876192..4cf3f3564c8eb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java @@ -741,13 +741,17 @@ public void testNoopUpdate() { final BulkItemResponse noopUpdate = bulkResponse.getItems()[0]; assertThat(noopUpdate.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP)); - assertThat(Strings.toString(noopUpdate), noopUpdate.getResponse().getShardInfo().getSuccessful(), equalTo(2)); + assertThat(Strings.toString(XContentType.JSON, noopUpdate), noopUpdate.getResponse().getShardInfo().getSuccessful(), equalTo(2)); final BulkItemResponse notFoundUpdate = bulkResponse.getItems()[1]; assertNotNull(notFoundUpdate.getFailure()); final BulkItemResponse notFoundDelete = bulkResponse.getItems()[2]; assertThat(notFoundDelete.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOT_FOUND)); - assertThat(Strings.toString(notFoundDelete), notFoundDelete.getResponse().getShardInfo().getSuccessful(), equalTo(2)); + assertThat( + Strings.toString(XContentType.JSON, notFoundDelete), + notFoundDelete.getResponse().getShardInfo().getSuccessful(), + equalTo(2) + ); } } diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java index 0dbdf57e34269..d2cce1318772a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java @@ -51,6 +51,7 @@ import org.opensearch.common.collect.ImmutableOpenIntMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.set.Sets; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.gateway.GatewayAllocator; import org.opensearch.index.IndexNotFoundException; import org.opensearch.index.engine.Engine; @@ -136,7 +137,7 @@ public void testBulkWeirdScenario() throws Exception { assertThat(bulkResponse.hasFailures(), equalTo(false)); assertThat(bulkResponse.getItems().length, equalTo(2)); - logger.info(Strings.toString(bulkResponse, true, true)); + logger.info(Strings.toString(XContentType.JSON, bulkResponse, true, true)); internalCluster().assertSeqNos(); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java index cc2536fcf00e4..020985cc9668c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java @@ -430,7 +430,7 @@ public void testMaybeFlush() throws Exception { final FlushStats flushStats = shard.flushStats(); logger.info( "--> translog stats [{}] gen [{}] commit_stats [{}] flush_stats [{}/{}]", - Strings.toString(translogStats), + Strings.toString(XContentType.JSON, translogStats), translog.getGeneration().translogFileGeneration, commitStats.getUserData(), flushStats.getPeriodic(), diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java index a7ab1dc7c7d39..ad4789981fa42 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java @@ -1589,7 +1589,10 @@ public void testRecoverLocallyUpToGlobalCheckpoint() throws Exception { .getShard(0) .getRetentionLeases(); throw new AssertionError( - "expect an operation-based recovery:" + "retention leases" + Strings.toString(retentionLeases) + "]" + "expect an operation-based recovery:" + + "retention leases" + + Strings.toString(XContentType.JSON, retentionLeases) + + "]" ); } connection.sendRequest(requestId, action, request, options); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java b/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java index 7f500b4e25cea..9db0ac4590efa 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java @@ -51,6 +51,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; import org.opensearch.plugins.PluginsService; import org.opensearch.script.MockScriptPlugin; @@ -228,7 +229,7 @@ public void testCancellationDuringQueryPhase() throws Exception { awaitForBlock(plugins); cancelSearch(SearchAction.NAME); disableBlocks(plugins); - logger.info("Segments {}", Strings.toString(client().admin().indices().prepareSegments("test").get())); + logger.info("Segments {}", Strings.toString(XContentType.JSON, client().admin().indices().prepareSegments("test").get())); ensureSearchWasCancelled(searchResponse); } @@ -282,7 +283,7 @@ public void testCancellationDuringFetchPhase() throws Exception { awaitForBlock(plugins); cancelSearch(SearchAction.NAME); disableBlocks(plugins); - logger.info("Segments {}", Strings.toString(client().admin().indices().prepareSegments("test").get())); + logger.info("Segments {}", Strings.toString(XContentType.JSON, client().admin().indices().prepareSegments("test").get())); ensureSearchWasCancelled(searchResponse); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponse.java index b2b6c26c596b6..055179afad826 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -50,6 +50,7 @@ import org.opensearch.common.xcontent.StatusToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -420,7 +421,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/cancel/CancelTasksResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/cancel/CancelTasksResponse.java index 78aea59bcd10e..5ff903bb70df0 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/cancel/CancelTasksResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/cancel/CancelTasksResponse.java @@ -40,6 +40,7 @@ import org.opensearch.common.xcontent.ConstructingObjectParser; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.tasks.TaskInfo; import java.io.IOException; @@ -80,6 +81,6 @@ public static CancelTasksResponse fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/get/GetTaskResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/get/GetTaskResponse.java index 1097831113971..a493dd4aa5027 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/get/GetTaskResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/get/GetTaskResponse.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.tasks.TaskResult; import java.io.IOException; @@ -84,6 +85,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java index 8d2ad55df1a8c..1d901c9914f87 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java @@ -47,6 +47,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.tasks.TaskId; import org.opensearch.tasks.TaskInfo; @@ -261,6 +262,6 @@ public static ListTasksResponse fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java index a77477f24aa9f..30d8e161e8adb 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java @@ -16,6 +16,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -178,6 +179,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java index 7562bec6fec42..579a8c5ac274c 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Arrays; @@ -195,7 +196,7 @@ public static VerifyRepositoryResponse fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java index 93d921c7b0f3a..dfa56cef5acb5 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.action.admin.cluster.state.ClusterStateResponse; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -175,7 +176,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequest.java index 5ece7ac6f1c40..48e6d4945a28e 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequest.java @@ -41,6 +41,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; @@ -186,6 +187,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java index 4d0daf6b67e45..e167265f64377 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.snapshots.SnapshotInfo; import java.io.IOException; @@ -127,6 +128,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java index 5fd83244f3dea..cf78b9002e170 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java @@ -704,6 +704,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStats.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStats.java index f649bc4694fca..62d5bf53bc972 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStats.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStats.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParserUtils; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; @@ -356,7 +357,7 @@ void add(SnapshotStats stats, boolean updateTimestamps) { time = endTime - startTime; } assert time >= 0 : "Update with [" - + Strings.toString(stats) + + Strings.toString(XContentType.JSON, stats) + "][" + updateTimestamps + "] resulted in negative total time [" diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStatus.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStatus.java index 8fd1ed22a0d14..26cb6053e097a 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStatus.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotStatus.java @@ -46,6 +46,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.snapshots.Snapshot; import org.opensearch.snapshots.SnapshotId; @@ -215,7 +216,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this, true, false); + return Strings.toString(XContentType.JSON, this, true, false); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/stats/AnalysisStats.java b/server/src/main/java/org/opensearch/action/admin/cluster/stats/AnalysisStats.java index 1f1920d8d675d..1ecef9eec70d6 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/stats/AnalysisStats.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/stats/AnalysisStats.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -346,6 +347,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/stats/MappingStats.java b/server/src/main/java/org/opensearch/action/admin/cluster/stats/MappingStats.java index 71e183e6158dc..17f3e8ab0970c 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/stats/MappingStats.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/stats/MappingStats.java @@ -41,6 +41,7 @@ import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -130,7 +131,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/alias/Alias.java b/server/src/main/java/org/opensearch/action/admin/indices/alias/Alias.java index f9a785d1759d8..5dbff70a01606 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/alias/Alias.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/alias/Alias.java @@ -312,7 +312,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/analyze/AnalyzeAction.java b/server/src/main/java/org/opensearch/action/admin/indices/analyze/AnalyzeAction.java index e1d890025fdeb..53f717cd6d074 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/analyze/AnalyzeAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/analyze/AnalyzeAction.java @@ -47,6 +47,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.analysis.NameOrDefinition; import java.io.IOException; @@ -409,7 +410,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java index 1fc9017359a8c..34e487f403394 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java @@ -43,6 +43,7 @@ import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.Index; import java.io.IOException; @@ -102,7 +103,7 @@ protected void addCustomFields(final XContentBuilder builder, final Params param @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** @@ -201,7 +202,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } @@ -260,7 +261,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** @@ -306,7 +307,7 @@ public XContentBuilder innerToXContent(final XContentBuilder builder, final Para @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } static Failure readFailure(final StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java index e93fbe86e4ece..1cf6db07b9e18 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java @@ -45,6 +45,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.MapperService; import java.io.IOException; @@ -332,7 +333,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java index 643ed719b5e2a..af47ab55dea30 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -43,6 +43,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.MapperService; import java.io.IOException; @@ -130,7 +131,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java index 6a07a645f9315..6ce11ca915f96 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java @@ -42,6 +42,7 @@ import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.Index; import java.io.IOException; @@ -92,7 +93,7 @@ protected void addCustomFields(final XContentBuilder builder, final Params param @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** @@ -191,7 +192,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } @@ -251,7 +252,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** @@ -297,7 +298,7 @@ public XContentBuilder innerToXContent(final XContentBuilder builder, final Para @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } static Failure readFailure(final StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/recovery/RecoveryResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/recovery/RecoveryResponse.java index e95110c732d79..e9e077a1907c2 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/recovery/RecoveryResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/recovery/RecoveryResponse.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.indices.recovery.RecoveryState; import java.io.IOException; @@ -119,6 +120,6 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/replication/SegmentReplicationStatsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/replication/SegmentReplicationStatsResponse.java index 2f999c3bad62b..2f72d7dd3e544 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/replication/SegmentReplicationStatsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/replication/SegmentReplicationStatsResponse.java @@ -14,6 +14,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.indices.replication.SegmentReplicationState; import java.io.IOException; @@ -94,6 +95,6 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverInfo.java b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverInfo.java index 801238f213b6b..5bdd97c72be15 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverInfo.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverInfo.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.List; @@ -148,6 +149,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index cab5f6bc58863..821787cd99baa 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -221,7 +221,7 @@ public UpdateSettingsRequest fromXContent(XContentParser parser) throws IOExcept @Override public String toString() { - return "indices : " + Arrays.toString(indices) + "," + Strings.toString(this); + return "indices : " + Arrays.toString(indices) + "," + Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java index 5b3fe22df4d6e..63d0d357abb39 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java @@ -40,6 +40,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.Index; import java.io.IOException; @@ -225,6 +226,6 @@ static final class Fields { @Override public String toString() { - return Strings.toString(this, true, false); + return Strings.toString(XContentType.JSON, this, true, false); } } diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkItemRequest.java b/server/src/main/java/org/opensearch/action/bulk/BulkItemRequest.java index f39ba589a3019..1661110beefa3 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemRequest.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemRequest.java @@ -40,6 +40,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.shard.ShardId; import java.io.IOException; @@ -114,7 +115,7 @@ public void abort(String index, Exception cause) { setPrimaryResponse(new BulkItemResponse(id, request.opType(), failure)); } else { assert primaryResponse.isFailed() && primaryResponse.getFailure().isAborted() : "response [" - + Strings.toString(primaryResponse) + + Strings.toString(XContentType.JSON, primaryResponse) + "]; cause [" + cause + "]"; diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java index 346e394bbb35e..7f9cb7afef514 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java @@ -52,6 +52,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; @@ -374,7 +375,7 @@ public static Failure fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.java b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.java index 4fdf8d551af61..390ee5cccb43d 100644 --- a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.java +++ b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -295,7 +296,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.java b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.java index e5f644987182c..8ce2475867f86 100644 --- a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.java +++ b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParserUtils; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Arrays; @@ -219,6 +220,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/get/GetResponse.java b/server/src/main/java/org/opensearch/action/get/GetResponse.java index 1118c3bb64f95..5c88134df723e 100644 --- a/server/src/main/java/org/opensearch/action/get/GetResponse.java +++ b/server/src/main/java/org/opensearch/action/get/GetResponse.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.get.GetResult; import java.io.IOException; @@ -237,6 +238,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java b/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java index 00df8657736ae..2177a60270a8f 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java @@ -54,6 +54,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParser.Token; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.VersionType; import org.opensearch.index.mapper.MapperService; import org.opensearch.search.fetch.subphase.FetchSourceContext; @@ -267,7 +268,7 @@ public int hashCode() { } public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/index/IndexResponse.java b/server/src/main/java/org/opensearch/action/index/IndexResponse.java index 40811f2ae6583..09f307fa5669b 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexResponse.java +++ b/server/src/main/java/org/opensearch/action/index/IndexResponse.java @@ -36,6 +36,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.shard.ShardId; import org.opensearch.rest.RestStatus; @@ -89,7 +90,7 @@ public String toString() { builder.append(",result=").append(getResult().getLowercase()); builder.append(",seqNo=").append(getSeqNo()); builder.append(",primaryTerm=").append(getPrimaryTerm()); - builder.append(",shards=").append(Strings.toString(getShardInfo())); + builder.append(",shards=").append(Strings.toString(XContentType.JSON, getShardInfo())); return builder.append("]").toString(); } diff --git a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java index 9e1895fc01857..b53f3c6799a57 100644 --- a/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java +++ b/server/src/main/java/org/opensearch/action/ingest/GetPipelineResponse.java @@ -41,6 +41,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParser.Token; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.ingest.PipelineConfiguration; import org.opensearch.rest.RestStatus; @@ -166,7 +167,7 @@ public boolean equals(Object other) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java index 6c25a16a65c75..0c00b120a4a3f 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java @@ -48,6 +48,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParser.Token; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Arrays; @@ -261,6 +262,6 @@ static final class Fields { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/action/search/SearchResponse.java b/server/src/main/java/org/opensearch/action/search/SearchResponse.java index 06ac642a0547f..057e7a6ba83e6 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/SearchResponse.java @@ -47,6 +47,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParser.Token; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestStatus; import org.opensearch.rest.action.RestActions; import org.opensearch.search.SearchHit; @@ -469,7 +470,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/action/support/replication/ReplicationTask.java b/server/src/main/java/org/opensearch/action/support/replication/ReplicationTask.java index b599dc405b8ab..6ef1aded11288 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/ReplicationTask.java +++ b/server/src/main/java/org/opensearch/action/support/replication/ReplicationTask.java @@ -36,6 +36,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.tasks.Task; import org.opensearch.tasks.TaskId; @@ -113,7 +114,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } // Implements equals and hashcode for testing diff --git a/server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java b/server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java index 2cf9d66fee2bd..8eb97f3cf7eff 100644 --- a/server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/RepositoryCleanupInProgress.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.repositories.RepositoryOperation; import java.io.IOException; @@ -109,7 +110,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java index 0ff373b6116de..0478e90b2860b 100644 --- a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java @@ -47,6 +47,7 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.shard.ShardId; import org.opensearch.repositories.IndexId; import org.opensearch.repositories.RepositoryOperation; @@ -683,7 +684,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributeValueHealth.java b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributeValueHealth.java index 83262ebdf6048..02accb76642c3 100644 --- a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributeValueHealth.java +++ b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributeValueHealth.java @@ -21,6 +21,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.List; @@ -292,7 +293,7 @@ private void setWeightInfo(ClusterState clusterState) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java index 50775791b3548..9528527b057c5 100644 --- a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java +++ b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java @@ -19,6 +19,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -279,7 +280,7 @@ public static ClusterAwarenessAttributesHealth fromXContent(XContentParser parse @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java index 4240a3bfed44a..1ce0f9d4901fe 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java @@ -74,6 +74,7 @@ import org.opensearch.common.util.concurrent.OpenSearchExecutors; import org.opensearch.common.util.concurrent.ListenableFuture; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.discovery.Discovery; import org.opensearch.discovery.DiscoveryModule; @@ -1319,16 +1320,22 @@ assert getLocalNode().equals(clusterState.getNodes().get(getLocalNode().getId()) // deserialized from the resulting JSON private boolean assertPreviousStateConsistency(ClusterChangedEvent event) { assert event.previousState() == coordinationState.get().getLastAcceptedState() - || XContentHelper.convertToMap(JsonXContent.jsonXContent, Strings.toString(event.previousState()), false) + || XContentHelper.convertToMap(JsonXContent.jsonXContent, Strings.toString(XContentType.JSON, event.previousState()), false) .equals( XContentHelper.convertToMap( JsonXContent.jsonXContent, - Strings.toString(clusterStateWithNoClusterManagerBlock(coordinationState.get().getLastAcceptedState())), + Strings.toString( + XContentType.JSON, + clusterStateWithNoClusterManagerBlock(coordinationState.get().getLastAcceptedState()) + ), false ) - ) : Strings.toString(event.previousState()) + ) : Strings.toString(XContentType.JSON, event.previousState()) + " vs " - + Strings.toString(clusterStateWithNoClusterManagerBlock(coordinationState.get().getLastAcceptedState())); + + Strings.toString( + XContentType.JSON, + clusterStateWithNoClusterManagerBlock(coordinationState.get().getLastAcceptedState()) + ); return true; } diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionAttributeMetadata.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionAttributeMetadata.java index 30ef361b0c13e..5861468700022 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionAttributeMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionAttributeMetadata.java @@ -20,6 +20,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.EnumSet; @@ -281,6 +282,6 @@ public static void toXContent( @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java b/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java index ba6035abbb42f..7ee09edeb6bea 100644 --- a/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java +++ b/server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java @@ -46,6 +46,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Locale; @@ -274,7 +275,7 @@ public static ClusterShardHealth fromXContent(XContentParser parser) throws IOEx @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java index dc22af42ac801..afee792213cc9 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java @@ -49,6 +49,7 @@ import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Collections; @@ -267,7 +268,7 @@ public static Diff readDiffFrom(StreamInput in) throws IOExceptio @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplate.java b/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplate.java index dccd01eb7b95f..f527026fa7ba7 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplate.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplate.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Map; @@ -151,7 +152,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java index 9607eb181d5e7..4b30601bb4450 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.ConstructingObjectParser; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.EnumSet; @@ -153,7 +154,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java index 33c50c938c3db..33200b46a5e98 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java @@ -47,6 +47,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.DataStreamFieldMapper; import org.opensearch.index.mapper.MapperService; @@ -286,7 +287,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java index a9b8f99b0a568..e58ace311df4a 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.ConstructingObjectParser; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.EnumSet; @@ -154,7 +155,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java index 181ddcb21cb3b..e7116633e6d50 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.ConstructingObjectParser; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.EnumSet; @@ -158,7 +159,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/cluster/metadata/RepositoriesMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/RepositoriesMetadata.java index 2dc3015376a72..a5416b27afaf6 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/RepositoriesMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/RepositoriesMetadata.java @@ -45,6 +45,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.repositories.RepositoryData; import java.io.IOException; @@ -291,6 +292,6 @@ public static void toXContent(RepositoryMetadata repository, XContentBuilder bui @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/Template.java b/server/src/main/java/org/opensearch/cluster/metadata/Template.java index 0b134cad7b8b2..80818287dae19 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/Template.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/Template.java @@ -176,7 +176,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java index c7136785606f6..de02447b602d3 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/WeightedRoutingMetadata.java @@ -21,6 +21,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.EnumSet; @@ -191,6 +192,6 @@ public static void toXContent(WeightedRouting weightedRouting, XContentBuilder b @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/command/AllocationCommands.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/command/AllocationCommands.java index c90e9c0b61741..b9628d83d92ef 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/command/AllocationCommands.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/command/AllocationCommands.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -216,6 +217,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/common/Strings.java b/server/src/main/java/org/opensearch/common/Strings.java index cbf12f264ee30..e6fa015899561 100644 --- a/server/src/main/java/org/opensearch/common/Strings.java +++ b/server/src/main/java/org/opensearch/common/Strings.java @@ -37,9 +37,9 @@ import org.opensearch.ExceptionsHelper; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.util.CollectionUtils; +import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.common.xcontent.json.JsonXContent; import java.io.BufferedReader; import java.io.IOException; @@ -773,8 +773,8 @@ public static boolean isAllOrWildcard(String data) { * Wraps the output into an anonymous object if needed. The content is not pretty-printed * nor human readable. */ - public static String toString(ToXContent toXContent) { - return toString(toXContent, false, false); + public static String toString(MediaType mediaType, ToXContent toXContent) { + return toString(mediaType, toXContent, false, false); } /** @@ -783,8 +783,8 @@ public static String toString(ToXContent toXContent) { * Allows to configure the params. * The content is not pretty-printed nor human readable. */ - public static String toString(ToXContent toXContent, ToXContent.Params params) { - return toString(toXContent, params, false, false); + public static String toString(MediaType mediaType, ToXContent toXContent, ToXContent.Params params) { + return toString(mediaType, toXContent, params, false, false); } /** @@ -801,8 +801,8 @@ public static String toString(XContentBuilder xContentBuilder) { * json needs to be pretty printed and human readable. * */ - public static String toString(ToXContent toXContent, boolean pretty, boolean human) { - return toString(toXContent, ToXContent.EMPTY_PARAMS, pretty, human); + public static String toString(MediaType mediaType, ToXContent toXContent, boolean pretty, boolean human) { + return toString(mediaType, toXContent, ToXContent.EMPTY_PARAMS, pretty, human); } /** @@ -811,9 +811,9 @@ public static String toString(ToXContent toXContent, boolean pretty, boolean hum * Allows to configure the params. * Allows to control whether the outputted json needs to be pretty printed and human readable. */ - private static String toString(ToXContent toXContent, ToXContent.Params params, boolean pretty, boolean human) { + private static String toString(MediaType mediaType, ToXContent toXContent, ToXContent.Params params, boolean pretty, boolean human) { try { - XContentBuilder builder = createBuilder(pretty, human); + XContentBuilder builder = createBuilder(mediaType, pretty, human); if (toXContent.isFragment()) { builder.startObject(); } @@ -824,7 +824,7 @@ private static String toString(ToXContent toXContent, ToXContent.Params params, return toString(builder); } catch (IOException e) { try { - XContentBuilder builder = createBuilder(pretty, human); + XContentBuilder builder = createBuilder(mediaType, pretty, human); builder.startObject(); builder.field("error", "error building toString out of XContent: " + e.getMessage()); builder.field("stack_trace", ExceptionsHelper.stackTrace(e)); @@ -836,8 +836,8 @@ private static String toString(ToXContent toXContent, ToXContent.Params params, } } - private static XContentBuilder createBuilder(boolean pretty, boolean human) throws IOException { - XContentBuilder builder = JsonXContent.contentBuilder(); + private static XContentBuilder createBuilder(MediaType mediaType, boolean pretty, boolean human) throws IOException { + XContentBuilder builder = XContentBuilder.builder(mediaType.xContent()); if (pretty) { builder.prettyPrint(); } diff --git a/server/src/main/java/org/opensearch/common/geo/builders/ShapeBuilder.java b/server/src/main/java/org/opensearch/common/geo/builders/ShapeBuilder.java index 92681ce4c4700..26b04d2ee4da2 100644 --- a/server/src/main/java/org/opensearch/common/geo/builders/ShapeBuilder.java +++ b/server/src/main/java/org/opensearch/common/geo/builders/ShapeBuilder.java @@ -51,6 +51,7 @@ import org.locationtech.spatial4j.exception.InvalidShapeException; import org.locationtech.spatial4j.shape.Shape; import org.locationtech.spatial4j.shape.jts.JtsGeometry; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.ArrayList; @@ -520,6 +521,6 @@ public String getWriteableName() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/common/settings/Setting.java b/server/src/main/java/org/opensearch/common/settings/Setting.java index aaea633caaf60..9e57f321cbca4 100644 --- a/server/src/main/java/org/opensearch/common/settings/Setting.java +++ b/server/src/main/java/org/opensearch/common/settings/Setting.java @@ -596,7 +596,7 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params) @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } /** diff --git a/server/src/main/java/org/opensearch/index/get/GetResult.java b/server/src/main/java/org/opensearch/index/get/GetResult.java index e2f23353f250e..62029cf889f85 100644 --- a/server/src/main/java/org/opensearch/index/get/GetResult.java +++ b/server/src/main/java/org/opensearch/index/get/GetResult.java @@ -46,6 +46,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.IgnoredFieldMapper; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.SourceFieldMapper; @@ -493,6 +494,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/index/mapper/MapperService.java b/server/src/main/java/org/opensearch/index/mapper/MapperService.java index f0d0b77396b0e..6d1d3d84bbecc 100644 --- a/server/src/main/java/org/opensearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/opensearch/index/mapper/MapperService.java @@ -350,7 +350,7 @@ private void assertMappingVersion( + "to be the same as new mapping [" + newSource + "]"; - final CompressedXContent mapperSource = new CompressedXContent(Strings.toString(mapper)); + final CompressedXContent mapperSource = new CompressedXContent(Strings.toString(XContentType.JSON, mapper)); assert currentSource.equals(mapperSource) : "expected current mapping [" + currentSource + "] for type [" diff --git a/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java b/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java index 7a76a9b4c18a9..193dec9d6df16 100644 --- a/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java @@ -41,6 +41,7 @@ import org.opensearch.common.time.DateFormatter; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.DynamicTemplate.XContentFieldType; import org.opensearch.index.mapper.MapperService.MergeReason; @@ -460,7 +461,7 @@ private static void validateDynamicTemplate(Mapper.TypeParser.ParserContext pars Locale.ROOT, "dynamic template [%s] has invalid content [%s]", dynamicTemplate.getName(), - Strings.toString(dynamicTemplate) + Strings.toString(XContentType.JSON, dynamicTemplate) ); final String deprecationMessage; diff --git a/server/src/main/java/org/opensearch/index/query/AbstractQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/AbstractQueryBuilder.java index 0265084462f6d..0d314584da3e7 100644 --- a/server/src/main/java/org/opensearch/index/query/AbstractQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/AbstractQueryBuilder.java @@ -48,6 +48,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentLocation; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.math.BigInteger; @@ -394,6 +395,6 @@ protected static void declareStandardFields(AbstractObjectParser readDiffFrom(StreamInput in) throws IO @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/persistent/PersistentTasksCustomMetadata.java b/server/src/main/java/org/opensearch/persistent/PersistentTasksCustomMetadata.java index 19d75355c8d04..13c0aee2a8180 100644 --- a/server/src/main/java/org/opensearch/persistent/PersistentTasksCustomMetadata.java +++ b/server/src/main/java/org/opensearch/persistent/PersistentTasksCustomMetadata.java @@ -52,6 +52,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Collection; @@ -210,7 +211,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } public long getNumberOfTasksOnNode(String nodeId, String taskName) { @@ -428,7 +429,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } public String getId() { diff --git a/server/src/main/java/org/opensearch/persistent/PersistentTasksNodeService.java b/server/src/main/java/org/opensearch/persistent/PersistentTasksNodeService.java index 34fe90ef58d36..259a2186187ac 100644 --- a/server/src/main/java/org/opensearch/persistent/PersistentTasksNodeService.java +++ b/server/src/main/java/org/opensearch/persistent/PersistentTasksNodeService.java @@ -42,6 +42,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.gateway.GatewayService; import org.opensearch.persistent.PersistentTasksCustomMetadata.PersistentTask; import org.opensearch.tasks.Task; @@ -363,7 +364,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } @Override diff --git a/server/src/main/java/org/opensearch/repositories/RepositoryCleanupResult.java b/server/src/main/java/org/opensearch/repositories/RepositoryCleanupResult.java index 5bed6fb1766b7..f01fab679131a 100644 --- a/server/src/main/java/org/opensearch/repositories/RepositoryCleanupResult.java +++ b/server/src/main/java/org/opensearch/repositories/RepositoryCleanupResult.java @@ -40,6 +40,7 @@ import org.opensearch.common.xcontent.ObjectParser; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; @@ -104,6 +105,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/repositories/RepositoryInfo.java b/server/src/main/java/org/opensearch/repositories/RepositoryInfo.java index e65e328bd8cfd..ae0826f3b783d 100644 --- a/server/src/main/java/org/opensearch/repositories/RepositoryInfo.java +++ b/server/src/main/java/org/opensearch/repositories/RepositoryInfo.java @@ -39,6 +39,7 @@ import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Map; @@ -143,6 +144,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/repositories/RepositoryStatsSnapshot.java b/server/src/main/java/org/opensearch/repositories/RepositoryStatsSnapshot.java index e37ec0cba6512..9eb13f36add45 100644 --- a/server/src/main/java/org/opensearch/repositories/RepositoryStatsSnapshot.java +++ b/server/src/main/java/org/opensearch/repositories/RepositoryStatsSnapshot.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -124,6 +125,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/search/SearchHit.java b/server/src/main/java/org/opensearch/search/SearchHit.java index 89eeddb07ce5d..b72157943172a 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -57,6 +57,7 @@ import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParser.Token; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.IgnoredFieldMapper; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.SourceFieldMapper; @@ -1124,6 +1125,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/AggregationBuilder.java b/server/src/main/java/org/opensearch/search/aggregations/AggregationBuilder.java index f5f11834b4484..914c48bfbc3df 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/AggregationBuilder.java +++ b/server/src/main/java/org/opensearch/search/aggregations/AggregationBuilder.java @@ -36,6 +36,7 @@ import org.opensearch.common.io.stream.NamedWriteable; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.Rewriteable; @@ -192,6 +193,6 @@ public static final class CommonFields extends ParseField.CommonFields { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/AggregatorFactories.java b/server/src/main/java/org/opensearch/search/aggregations/AggregatorFactories.java index 75e887fbe0d0a..78cc655ead7af 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/AggregatorFactories.java +++ b/server/src/main/java/org/opensearch/search/aggregations/AggregatorFactories.java @@ -43,6 +43,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentLocation; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.Rewriteable; @@ -556,7 +557,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } @Override diff --git a/server/src/main/java/org/opensearch/search/aggregations/BucketOrder.java b/server/src/main/java/org/opensearch/search/aggregations/BucketOrder.java index 6dc8c9a61d864..319f6f0832473 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/BucketOrder.java +++ b/server/src/main/java/org/opensearch/search/aggregations/BucketOrder.java @@ -35,6 +35,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.ToXContentObject; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; import org.opensearch.search.aggregations.support.AggregationPath; @@ -171,6 +172,6 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java b/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java index 6ccd429388873..e8e59abf983a9 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java +++ b/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.util.BigArrays; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.action.search.RestSearchAction; import org.opensearch.script.ScriptService; import org.opensearch.search.aggregations.pipeline.PipelineAggregator; @@ -408,7 +409,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/search/aggregations/PipelineAggregationBuilder.java b/server/src/main/java/org/opensearch/search/aggregations/PipelineAggregationBuilder.java index dea7455c2e975..0bbb56f2fc258 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/PipelineAggregationBuilder.java +++ b/server/src/main/java/org/opensearch/search/aggregations/PipelineAggregationBuilder.java @@ -36,6 +36,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.io.stream.NamedWriteable; import org.opensearch.common.xcontent.ToXContentFragment; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.Rewriteable; import org.opensearch.search.aggregations.AggregatorFactories.Builder; @@ -287,7 +288,7 @@ public PipelineAggregationBuilder subAggregations(Builder subFactories) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } /** diff --git a/server/src/main/java/org/opensearch/search/aggregations/support/BaseMultiValuesSourceFieldConfig.java b/server/src/main/java/org/opensearch/search/aggregations/support/BaseMultiValuesSourceFieldConfig.java index b7e157b6050fc..dba145b48caa7 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/support/BaseMultiValuesSourceFieldConfig.java +++ b/server/src/main/java/org/opensearch/search/aggregations/support/BaseMultiValuesSourceFieldConfig.java @@ -20,6 +20,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.script.Script; import java.io.IOException; @@ -164,7 +165,7 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } abstract void doXContentBody(XContentBuilder builder, Params params) throws IOException; diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/AbstractHighlighterBuilder.java b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/AbstractHighlighterBuilder.java index 94533a5e3dae6..92cc84ab9bd03 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/AbstractHighlighterBuilder.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/AbstractHighlighterBuilder.java @@ -45,6 +45,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.Rewriteable; import org.opensearch.search.fetch.subphase.highlight.HighlightBuilder.BoundaryScannerType; @@ -772,6 +773,6 @@ public final boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/rescore/RescorerBuilder.java b/server/src/main/java/org/opensearch/search/rescore/RescorerBuilder.java index 1c29e9ee60477..daad8c60310c4 100644 --- a/server/src/main/java/org/opensearch/search/rescore/RescorerBuilder.java +++ b/server/src/main/java/org/opensearch/search/rescore/RescorerBuilder.java @@ -41,6 +41,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.Rewriteable; @@ -169,6 +170,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java b/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java index 21e8a5646b9a5..665e20624948c 100644 --- a/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java +++ b/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java @@ -52,6 +52,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.fielddata.IndexFieldData; import org.opensearch.index.fielddata.IndexNumericFieldData; import org.opensearch.index.mapper.IdFieldMapper; @@ -337,6 +338,6 @@ private GroupShardsIterator buildShardIterator(ClusterService clu @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/sort/SortBuilder.java b/server/src/main/java/org/opensearch/search/sort/SortBuilder.java index a8ade60b5b64f..4611022d8528d 100644 --- a/server/src/main/java/org/opensearch/search/sort/SortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/SortBuilder.java @@ -44,6 +44,7 @@ import org.opensearch.common.xcontent.NamedObjectNotFoundException; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.opensearch.index.mapper.ObjectMapper; import org.opensearch.index.query.QueryBuilder; @@ -285,6 +286,6 @@ protected static QueryBuilder parseNestedFilter(XContentParser parser) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/suggest/Suggest.java b/server/src/main/java/org/opensearch/search/suggest/Suggest.java index 4324f34a5c66d..ea5dc0d9173d0 100644 --- a/server/src/main/java/org/opensearch/search/suggest/Suggest.java +++ b/server/src/main/java/org/opensearch/search/suggest/Suggest.java @@ -48,6 +48,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentParserUtils; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.action.search.RestSearchAction; import org.opensearch.search.aggregations.Aggregation; import org.opensearch.search.suggest.Suggest.Suggestion.Entry; @@ -790,6 +791,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/search/suggest/SuggestBuilder.java b/server/src/main/java/org/opensearch/search/suggest/SuggestBuilder.java index 3f77ce29dd2bd..836964774c631 100644 --- a/server/src/main/java/org/opensearch/search/suggest/SuggestBuilder.java +++ b/server/src/main/java/org/opensearch/search/suggest/SuggestBuilder.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.query.QueryShardContext; import org.opensearch.search.suggest.SuggestionSearchContext.SuggestionContext; @@ -217,6 +218,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } } diff --git a/server/src/main/java/org/opensearch/snapshots/RestoreInfo.java b/server/src/main/java/org/opensearch/snapshots/RestoreInfo.java index b8ee09ff53fea..895e9193011e1 100644 --- a/server/src/main/java/org/opensearch/snapshots/RestoreInfo.java +++ b/server/src/main/java/org/opensearch/snapshots/RestoreInfo.java @@ -40,6 +40,7 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -214,6 +215,6 @@ public int hashCode() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } } diff --git a/server/src/main/java/org/opensearch/tasks/RawTaskStatus.java b/server/src/main/java/org/opensearch/tasks/RawTaskStatus.java index 6ec91b1741f37..f6bd191aa9744 100644 --- a/server/src/main/java/org/opensearch/tasks/RawTaskStatus.java +++ b/server/src/main/java/org/opensearch/tasks/RawTaskStatus.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.io.InputStream; @@ -86,7 +87,7 @@ public String getWriteableName() { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** diff --git a/server/src/main/java/org/opensearch/tasks/TaskInfo.java b/server/src/main/java/org/opensearch/tasks/TaskInfo.java index fc6280cc643c0..92019449cc936 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskInfo.java +++ b/server/src/main/java/org/opensearch/tasks/TaskInfo.java @@ -45,6 +45,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Collections; @@ -344,7 +345,7 @@ public static TaskInfo fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } // Implements equals and hashCode for testing diff --git a/server/src/main/java/org/opensearch/tasks/TaskResourceStats.java b/server/src/main/java/org/opensearch/tasks/TaskResourceStats.java index 64fe4d73d498a..31439472c77e5 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskResourceStats.java +++ b/server/src/main/java/org/opensearch/tasks/TaskResourceStats.java @@ -15,6 +15,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.HashMap; @@ -88,7 +89,7 @@ public static TaskResourceStats fromXContent(XContentParser parser) throws IOExc @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } // Implements equals and hashcode for testing diff --git a/server/src/main/java/org/opensearch/tasks/TaskResourceUsage.java b/server/src/main/java/org/opensearch/tasks/TaskResourceUsage.java index 2786f7ca59c05..88c79be3dfdc5 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskResourceUsage.java +++ b/server/src/main/java/org/opensearch/tasks/TaskResourceUsage.java @@ -17,6 +17,7 @@ import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -87,7 +88,7 @@ public static TaskResourceUsage fromXContent(XContentParser parser) { @Override public String toString() { - return Strings.toString(this, true, true); + return Strings.toString(XContentType.JSON, this, true, true); } // Implements equals and hashcode for testing diff --git a/server/src/main/java/org/opensearch/tasks/TaskResult.java b/server/src/main/java/org/opensearch/tasks/TaskResult.java index 247cc645ef8a3..44ff945f708cb 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskResult.java +++ b/server/src/main/java/org/opensearch/tasks/TaskResult.java @@ -47,6 +47,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Map; @@ -207,7 +208,7 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } // Implements equals and hashcode for testing diff --git a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java index 022ed3607cce4..015bf1427f214 100644 --- a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java @@ -77,6 +77,7 @@ import org.opensearch.common.util.CancellableThreadsTests; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentLocation; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.discovery.MasterNotDiscoveredException; import org.opensearch.env.ShardLockObtainFailedException; import org.opensearch.index.Index; @@ -535,9 +536,15 @@ public void testClusterBlockException() throws IOException { public void testNotSerializableExceptionWrapper() throws IOException { NotSerializableExceptionWrapper ex = serialize(new NotSerializableExceptionWrapper(new NullPointerException())); - assertEquals("{\"type\":\"null_pointer_exception\",\"reason\":\"null_pointer_exception: null\"}", Strings.toString(ex)); + assertEquals( + "{\"type\":\"null_pointer_exception\",\"reason\":\"null_pointer_exception: null\"}", + Strings.toString(XContentType.JSON, ex) + ); ex = serialize(new NotSerializableExceptionWrapper(new IllegalArgumentException("nono!"))); - assertEquals("{\"type\":\"illegal_argument_exception\",\"reason\":\"illegal_argument_exception: nono!\"}", Strings.toString(ex)); + assertEquals( + "{\"type\":\"illegal_argument_exception\",\"reason\":\"illegal_argument_exception: nono!\"}", + Strings.toString(XContentType.JSON, ex) + ); class UnknownException extends Exception { UnknownException(final String message) { diff --git a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java index 6ceb1d6f12e3b..6e328ccef517a 100644 --- a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java +++ b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java @@ -449,8 +449,8 @@ public void testGenerateThrowableToXContent() throws IOException { { // test equivalence OpenSearchException ex = new RemoteTransportException("foobar", new FileNotFoundException("foo not found")); - String toXContentString = Strings.toString(ex); - String throwableString = Strings.toString((builder, params) -> { + String toXContentString = Strings.toString(XContentType.JSON, ex); + String throwableString = Strings.toString(XContentType.JSON, (builder, params) -> { OpenSearchException.generateThrowableXContent(builder, params, ex); return builder; }); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 7590bf88eeca0..afa0b8f91762d 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -343,7 +343,7 @@ public void onFailure(Exception e) { "local tasks [{}]", localTasks.values() .stream() - .map(t -> Strings.toString(t.taskInfo(testNodes[0].getNodeId(), true))) + .map(t -> Strings.toString(XContentType.JSON, t.taskInfo(testNodes[0].getNodeId(), true))) .collect(Collectors.joining(",")) ); assertEquals(2, localTasks.size()); // all node tasks + 1 coordinating task diff --git a/server/src/test/java/org/opensearch/action/admin/indices/close/CloseIndexResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/close/CloseIndexResponseTests.java index 22de537942cde..f26c4ba12befd 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/close/CloseIndexResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/close/CloseIndexResponseTests.java @@ -151,7 +151,7 @@ public void testToXContent() throws IOException { CloseIndexResponse closeIndexResponse = new CloseIndexResponse(true, true, Collections.singletonList(indexResult)); assertEquals( "{\"acknowledged\":true,\"shards_acknowledged\":true,\"indices\":{\"test\":{\"closed\":true}}}", - Strings.toString(closeIndexResponse) + Strings.toString(XContentType.JSON, closeIndexResponse) ); CloseIndexResponse.ShardResult[] shards = new CloseIndexResponse.ShardResult[1]; @@ -168,7 +168,7 @@ public void testToXContent() throws IOException { + "\"failures\":[{\"node\":\"nodeId\",\"shard\":0,\"index\":\"test\",\"status\":\"INTERNAL_SERVER_ERROR\"," + "\"reason\":{\"type\":\"action_not_found_transport_exception\"," + "\"reason\":\"No handler for action [test]\"}}]}}}}}", - Strings.toString(closeIndexResponse) + Strings.toString(XContentType.JSON, closeIndexResponse) ); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexResponseTests.java index a51b256d32010..5dd735e49efba 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexResponseTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.test.AbstractSerializingTestCase; @@ -83,13 +84,13 @@ protected CreateIndexResponse doParseInstance(XContentParser parser) { public void testToXContent() { CreateIndexResponse response = new CreateIndexResponse(true, false, "index_name"); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals("{\"acknowledged\":true,\"shards_acknowledged\":false,\"index\":\"index_name\"}", output); } public void testToAndFromXContentIndexNull() throws IOException { CreateIndexResponse response = new CreateIndexResponse(true, false, null); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals("{\"acknowledged\":true,\"shards_acknowledged\":false,\"index\":null}", output); try (XContentParser parser = createParser(JsonXContent.jsonXContent, output)) { CreateIndexResponse parsedResponse = CreateIndexResponse.fromXContent(parser); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java index 512e21cc28469..5ea5575c3cfc4 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponseTests.java @@ -38,6 +38,7 @@ import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.AbstractWireSerializingTestCase; import java.io.IOException; @@ -68,7 +69,7 @@ public void testNullFieldMappingToXContent() { Map> mappings = new HashMap<>(); mappings.put("index", Collections.emptyMap()); GetFieldMappingsResponse response = new GetFieldMappingsResponse(mappings); - assertEquals("{\"index\":{\"mappings\":{}}}", Strings.toString(response)); + assertEquals("{\"index\":{\"mappings\":{}}}", Strings.toString(XContentType.JSON, response)); } @Override diff --git a/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index d8178769ba7b1..e6eba34987a44 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -113,7 +113,7 @@ public void testToXContent() throws IOException { mapping.endObject(); request.source(mapping); - String actualRequestBody = Strings.toString(request); + String actualRequestBody = Strings.toString(XContentType.JSON, request); String expectedRequestBody = "{\"properties\":{\"email\":{\"type\":\"text\"}}}"; assertEquals(expectedRequestBody, actualRequestBody); } @@ -121,7 +121,7 @@ public void testToXContent() throws IOException { public void testToXContentWithEmptySource() throws IOException { PutMappingRequest request = new PutMappingRequest("foo"); - String actualRequestBody = Strings.toString(request); + String actualRequestBody = Strings.toString(XContentType.JSON, request); String expectedRequestBody = "{}"; assertEquals(expectedRequestBody, actualRequestBody); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeRequestTests.java index b4c211b34c644..8001094e4cfe4 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeRequestTests.java @@ -76,7 +76,7 @@ private void runTestCopySettingsValidation(final Boolean copySettings, final Con public void testToXContent() throws IOException { { ResizeRequest request = new ResizeRequest("target", "source"); - String actualRequestBody = Strings.toString(request); + String actualRequestBody = Strings.toString(XContentType.JSON, request); assertEquals("{\"settings\":{},\"aliases\":{}}", actualRequestBody); } { @@ -91,7 +91,7 @@ public void testToXContent() throws IOException { settings.put(SETTING_NUMBER_OF_SHARDS, 10); target.settings(settings); request.setTargetIndex(target); - String actualRequestBody = Strings.toString(request); + String actualRequestBody = Strings.toString(XContentType.JSON, request); String expectedRequestBody = "{\"settings\":{\"index\":{\"number_of_shards\":\"10\"}}," + "\"aliases\":{\"test_alias\":{\"filter\":{\"term\":{\"year\":2016}},\"routing\":\"1\",\"is_write_index\":true}}}"; assertEquals(expectedRequestBody, actualRequestBody); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeResponseTests.java index fe60d3652ae1b..add2df5dde02b 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shrink/ResizeResponseTests.java @@ -35,13 +35,14 @@ import org.opensearch.common.Strings; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.AbstractSerializingTestCase; public class ResizeResponseTests extends AbstractSerializingTestCase { public void testToXContent() { ResizeResponse response = new ResizeResponse(true, false, "index_name"); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals("{\"acknowledged\":true,\"shards_acknowledged\":false,\"index\":\"index_name\"}", output); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java b/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java index 171639083be58..469f2e0a8e3c2 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java @@ -40,6 +40,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexModule; import org.opensearch.index.engine.CommitStats; import org.opensearch.index.engine.SegmentsStats; @@ -146,7 +147,7 @@ public void testRefreshListeners() throws Exception { } if (end - System.nanoTime() < 0) { logger.info("timed out"); - fail("didn't get a refresh listener in time: " + Strings.toString(common)); + fail("didn't get a refresh listener in time: " + Strings.toString(XContentType.JSON, common)); } } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/validate/query/ValidateQueryResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/validate/query/ValidateQueryResponseTests.java index 1da1cc28d50ed..97ca0c1ea1c23 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/validate/query/ValidateQueryResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/validate/query/ValidateQueryResponseTests.java @@ -36,6 +36,7 @@ import org.opensearch.action.support.DefaultShardOperationFailedException; import org.opensearch.common.Strings; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.AbstractBroadcastResponseTestCase; import java.io.IOException; @@ -114,7 +115,7 @@ protected ValidateQueryResponse createTestInstance( @Override public void testToXContent() { ValidateQueryResponse response = createTestInstance(10, 10, 0, new ArrayList<>()); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals("{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0},\"valid\":true}", output); } } diff --git a/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java b/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java index e6c80b8ebdb61..6b9fdf45f7035 100644 --- a/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java @@ -56,7 +56,7 @@ public class DeleteResponseTests extends OpenSearchTestCase { public void testToXContent() { { DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "id", 3, 17, 5, true); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":5,\"result\":\"deleted\"," + "\"_shards\":null,\"_seq_no\":3,\"_primary_term\":17}", @@ -67,7 +67,7 @@ public void testToXContent() { DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "id", -1, 0, 7, true); response.setForcedRefresh(true); response.setShardInfo(new ReplicationResponse.ShardInfo(10, 5)); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":7,\"result\":\"deleted\"," + "\"forced_refresh\":true,\"_shards\":{\"total\":10,\"successful\":5,\"failed\":0}}", diff --git a/server/src/test/java/org/opensearch/action/get/GetResponseTests.java b/server/src/test/java/org/opensearch/action/get/GetResponseTests.java index 39b330fa10a7b..945bdab7d693f 100644 --- a/server/src/test/java/org/opensearch/action/get/GetResponseTests.java +++ b/server/src/test/java/org/opensearch/action/get/GetResponseTests.java @@ -118,7 +118,7 @@ public void testToXContent() { null ) ); - String output = Strings.toString(getResponse); + String output = Strings.toString(XContentType.JSON, getResponse); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":1,\"_seq_no\":0,\"_primary_term\":1," + "\"found\":true,\"_source\":{ \"field1\" : \"value1\", \"field2\":\"value2\"},\"fields\":{\"field1\":[\"value1\"]}}", @@ -127,7 +127,7 @@ public void testToXContent() { } { GetResponse getResponse = new GetResponse(new GetResult("index", "id", UNASSIGNED_SEQ_NO, 0, 1, false, null, null, null)); - String output = Strings.toString(getResponse); + String output = Strings.toString(XContentType.JSON, getResponse); assertEquals("{\"_index\":\"index\",\"_id\":\"id\",\"found\":false}", output); } } diff --git a/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java b/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java index 25d6a60299848..d3b2fbefed984 100644 --- a/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java +++ b/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java @@ -57,7 +57,7 @@ public class IndexResponseTests extends OpenSearchTestCase { public void testToXContent() { { IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "id", 3, 17, 5, true); - String output = Strings.toString(indexResponse); + String output = Strings.toString(XContentType.JSON, indexResponse); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":5,\"result\":\"created\",\"_shards\":null," + "\"_seq_no\":3,\"_primary_term\":17}", @@ -68,7 +68,7 @@ public void testToXContent() { IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "id", -1, 17, 7, true); indexResponse.setForcedRefresh(true); indexResponse.setShardInfo(new ReplicationResponse.ShardInfo(10, 5)); - String output = Strings.toString(indexResponse); + String output = Strings.toString(XContentType.JSON, indexResponse); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":7,\"result\":\"created\"," + "\"forced_refresh\":true,\"_shards\":{\"total\":10,\"successful\":5,\"failed\":0}}", diff --git a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java index de80ea22071e8..ea21a769bf7bd 100644 --- a/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java +++ b/server/src/test/java/org/opensearch/action/search/MultiSearchRequestTests.java @@ -301,7 +301,7 @@ public void testResponseErrorToXContent() { + "\"type\":\"illegal_state_exception\",\"reason\":\"baaaaaazzzz\"},\"status\":500" + "}" + "]}", - Strings.toString(response) + Strings.toString(XContentType.JSON, response) ); } diff --git a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java index de17688903d2a..7731e2d8ede45 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java @@ -111,7 +111,7 @@ public void testToXContent() throws IOException { + " ]" + "}" ); - assertEquals(expectedJson, Strings.toString(exception)); + assertEquals(expectedJson, Strings.toString(XContentType.JSON, exception)); } public void testToAndFromXContent() throws IOException { diff --git a/server/src/test/java/org/opensearch/action/search/SearchResponseTests.java b/server/src/test/java/org/opensearch/action/search/SearchResponseTests.java index 4a68503b6c3f8..f3f8ee9cde799 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchResponseTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchResponseTests.java @@ -282,7 +282,7 @@ public void testToXContent() { } } expectedString.append("}"); - assertEquals(expectedString.toString(), Strings.toString(response)); + assertEquals(expectedString.toString(), Strings.toString(XContentType.JSON, response)); } { SearchResponse response = new SearchResponse( @@ -329,7 +329,7 @@ public void testToXContent() { } } expectedString.append("}"); - assertEquals(expectedString.toString(), Strings.toString(response)); + assertEquals(expectedString.toString(), Strings.toString(XContentType.JSON, response)); } } diff --git a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java index 40a5b05b1dbc6..7cb7619909dd3 100644 --- a/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/support/DefaultShardOperationFailedExceptionTests.java @@ -92,7 +92,7 @@ public void testToXContent() throws IOException { assertEquals( "{\"shard\":-1,\"index\":null,\"status\":\"INTERNAL_SERVER_ERROR\"," + "\"reason\":{\"type\":\"exception\",\"reason\":\"foo\"}}", - Strings.toString(exception) + Strings.toString(XContentType.JSON, exception) ); } { @@ -102,7 +102,7 @@ public void testToXContent() throws IOException { assertEquals( "{\"shard\":-1,\"index\":null,\"status\":\"INTERNAL_SERVER_ERROR\",\"reason\":{\"type\":\"exception\"," + "\"reason\":\"foo\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"bar\"}}}", - Strings.toString(exception) + Strings.toString(XContentType.JSON, exception) ); } { @@ -112,7 +112,7 @@ public void testToXContent() throws IOException { assertEquals( "{\"shard\":2,\"index\":\"test\",\"status\":\"INTERNAL_SERVER_ERROR\"," + "\"reason\":{\"type\":\"illegal_state_exception\",\"reason\":\"bar\"}}", - Strings.toString(exception) + Strings.toString(XContentType.JSON, exception) ); } { @@ -124,7 +124,7 @@ public void testToXContent() throws IOException { assertEquals( "{\"shard\":1,\"index\":\"test\",\"status\":\"BAD_REQUEST\"," + "\"reason\":{\"type\":\"illegal_argument_exception\",\"reason\":\"foo\"}}", - Strings.toString(exception) + Strings.toString(XContentType.JSON, exception) ); } } diff --git a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java index 89d0dfe36ca0f..e925c17536d6c 100644 --- a/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java +++ b/server/src/test/java/org/opensearch/action/support/replication/ReplicationResponseTests.java @@ -66,7 +66,7 @@ public void testShardInfoToString() { public void testShardInfoToXContent() throws IOException { { ShardInfo shardInfo = new ShardInfo(5, 3); - String output = Strings.toString(shardInfo); + String output = Strings.toString(XContentType.JSON, shardInfo); assertEquals("{\"total\":5,\"successful\":3,\"failed\":0}", output); } { @@ -88,7 +88,7 @@ public void testShardInfoToXContent() throws IOException { true ) ); - String output = Strings.toString(shardInfo); + String output = Strings.toString(XContentType.JSON, shardInfo); assertEquals( "{\"total\":6,\"successful\":4,\"failed\":2,\"failures\":[{\"_index\":\"index\",\"_shard\":3," + "\"_node\":\"_node_id\",\"reason\":{\"type\":\"illegal_argument_exception\",\"reason\":\"Wrong\"}," diff --git a/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java b/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java index ba0abd6c8e349..8aa26bb8957d5 100644 --- a/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java +++ b/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java @@ -69,7 +69,7 @@ public class UpdateResponseTests extends OpenSearchTestCase { public void testToXContent() throws IOException { { UpdateResponse updateResponse = new UpdateResponse(new ShardId("index", "index_uuid", 0), "id", -2, 0, 0, NOT_FOUND); - String output = Strings.toString(updateResponse); + String output = Strings.toString(XContentType.JSON, updateResponse); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":0,\"result\":\"not_found\"," + "\"_shards\":{\"total\":0,\"successful\":0,\"failed\":0}}", @@ -86,7 +86,7 @@ public void testToXContent() throws IOException { 1, DELETED ); - String output = Strings.toString(updateResponse); + String output = Strings.toString(XContentType.JSON, updateResponse); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":1,\"result\":\"deleted\"," + "\"_shards\":{\"total\":10,\"successful\":6,\"failed\":0},\"_seq_no\":3,\"_primary_term\":17}", @@ -110,7 +110,7 @@ public void testToXContent() throws IOException { ); updateResponse.setGetResult(new GetResult("books", "1", 0, 1, 2, true, source, fields, null)); - String output = Strings.toString(updateResponse); + String output = Strings.toString(XContentType.JSON, updateResponse); assertEquals( "{\"_index\":\"books\",\"_id\":\"1\",\"_version\":2,\"result\":\"updated\"," + "\"_shards\":{\"total\":3,\"successful\":2,\"failed\":0},\"_seq_no\":7,\"_primary_term\":17,\"get\":{" diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java index c27f803ab8980..a2f0c5e335607 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexGraveyardTests.java @@ -41,6 +41,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentOpenSearchExtension; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.Index; import org.opensearch.test.OpenSearchTestCase; @@ -86,7 +87,7 @@ public void testXContent() throws IOException { if (graveyard.getTombstones().size() > 0) { // check that date properly printed assertThat( - Strings.toString(graveyard, false, true), + Strings.toString(XContentType.JSON, graveyard, false, true), containsString( XContentOpenSearchExtension.DEFAULT_DATE_PRINTER.print(graveyard.getTombstones().get(0).getDeleteDateInMillis()) ) diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java index 87860b8c536ef..f1ecaac0c7912 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java @@ -50,6 +50,7 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.shard.ShardId; import org.opensearch.indices.IndicesModule; @@ -128,7 +129,10 @@ public void testIndexMetadataSerialization() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder)); final IndexMetadata fromXContentMeta = IndexMetadata.fromXContent(parser); assertEquals( - "expected: " + Strings.toString(metadata) + "\nactual : " + Strings.toString(fromXContentMeta), + "expected: " + + Strings.toString(XContentType.JSON, metadata) + + "\nactual : " + + Strings.toString(XContentType.JSON, fromXContentMeta), metadata, fromXContentMeta ); diff --git a/server/src/test/java/org/opensearch/cluster/serialization/ClusterStateToStringTests.java b/server/src/test/java/org/opensearch/cluster/serialization/ClusterStateToStringTests.java index f16a1eda2f34d..e44964e713710 100644 --- a/server/src/test/java/org/opensearch/cluster/serialization/ClusterStateToStringTests.java +++ b/server/src/test/java/org/opensearch/cluster/serialization/ClusterStateToStringTests.java @@ -44,6 +44,7 @@ import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; +import org.opensearch.common.xcontent.XContentType; import java.util.Arrays; @@ -79,7 +80,7 @@ public void testClusterStateSerialization() throws Exception { AllocationService strategy = createAllocationService(); clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build(); - String clusterStateString = Strings.toString(clusterState); + String clusterStateString = Strings.toString(XContentType.JSON, clusterState); assertNotNull(clusterStateString); assertThat(clusterStateString, containsString("test_idx")); diff --git a/server/src/test/java/org/opensearch/common/StringsTests.java b/server/src/test/java/org/opensearch/common/StringsTests.java index 7d87fc33c12e7..03c0a61d896e1 100644 --- a/server/src/test/java/org/opensearch/common/StringsTests.java +++ b/server/src/test/java/org/opensearch/common/StringsTests.java @@ -35,6 +35,7 @@ import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.ToXContentObject; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.test.OpenSearchTestCase; import java.util.Collections; @@ -104,7 +105,7 @@ public void testToStringToXContent() { } } - String toString = Strings.toString(toXContent); + String toString = Strings.toString(XContentType.JSON, toXContent); if (error) { assertThat(toString, containsString("\"error\":\"error building toString out of XContent:")); assertThat(toString, containsString("\"stack_trace\":")); @@ -117,10 +118,10 @@ public void testToStringToXContent() { public void testToStringToXContentWithOrWithoutParams() { ToXContent toXContent = (builder, params) -> builder.field("color_from_param", params.param("color", "red")); // Rely on the default value of "color" param when params are not passed - assertThat(Strings.toString(toXContent), containsString("\"color_from_param\":\"red\"")); + assertThat(Strings.toString(XContentType.JSON, toXContent), containsString("\"color_from_param\":\"red\"")); // Pass "color" param explicitly assertThat( - Strings.toString(toXContent, new ToXContent.MapParams(Collections.singletonMap("color", "blue"))), + Strings.toString(XContentType.JSON, toXContent, new ToXContent.MapParams(Collections.singletonMap("color", "blue"))), containsString("\"color_from_param\":\"blue\"") ); } diff --git a/server/src/test/java/org/opensearch/index/get/DocumentFieldTests.java b/server/src/test/java/org/opensearch/index/get/DocumentFieldTests.java index ed80e736ae5f9..a2cf04c072892 100644 --- a/server/src/test/java/org/opensearch/index/get/DocumentFieldTests.java +++ b/server/src/test/java/org/opensearch/index/get/DocumentFieldTests.java @@ -60,7 +60,7 @@ public class DocumentFieldTests extends OpenSearchTestCase { public void testToXContent() { DocumentField documentField = new DocumentField("field", Arrays.asList("value1", "value2")); - String output = Strings.toString(documentField); + String output = Strings.toString(XContentType.JSON, documentField); assertEquals("{\"field\":[\"value1\",\"value2\"]}", output); } diff --git a/server/src/test/java/org/opensearch/index/get/GetResultTests.java b/server/src/test/java/org/opensearch/index/get/GetResultTests.java index 03621f83e8af2..dc40c44686c13 100644 --- a/server/src/test/java/org/opensearch/index/get/GetResultTests.java +++ b/server/src/test/java/org/opensearch/index/get/GetResultTests.java @@ -105,7 +105,7 @@ public void testToXContent() throws IOException { singletonMap("field1", new DocumentField("field1", singletonList("value1"))), singletonMap("field1", new DocumentField("metafield", singletonList("metavalue"))) ); - String output = Strings.toString(getResult); + String output = Strings.toString(XContentType.JSON, getResult); assertEquals( "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":1,\"_seq_no\":0,\"_primary_term\":1," + "\"metafield\":\"metavalue\",\"found\":true,\"_source\":{ \"field1\" : \"value1\", \"field2\":\"value2\"}," @@ -115,7 +115,7 @@ public void testToXContent() throws IOException { } { GetResult getResult = new GetResult("index", "id", UNASSIGNED_SEQ_NO, 0, 1, false, null, null, null); - String output = Strings.toString(getResult); + String output = Strings.toString(XContentType.JSON, getResult); assertEquals("{\"_index\":\"index\",\"_id\":\"id\",\"found\":false}", output); } } diff --git a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java index b116cff8bb8f3..919a758bce665 100644 --- a/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/CompletionFieldMapperTests.java @@ -51,6 +51,7 @@ import org.opensearch.common.unit.Fuzziness; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.IndexSettings; import org.opensearch.index.analysis.AnalyzerScope; @@ -186,7 +187,7 @@ public void testCompletionAnalyzerSettings() throws Exception { assertEquals( "{\"field\":{\"type\":\"completion\",\"analyzer\":\"simple\",\"search_analyzer\":\"standard\"," + "\"preserve_separators\":false,\"preserve_position_increments\":true,\"max_input_length\":50}}", - Strings.toString(fieldMapper) + Strings.toString(XContentType.JSON, fieldMapper) ); } diff --git a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java index dee5db4e31253..ad98df0198122 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DynamicMappingTests.java @@ -36,6 +36,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.time.Instant; @@ -183,7 +184,7 @@ public void testField() throws Exception { assertEquals( "{\"_doc\":{\"properties\":{\"foo\":{\"type\":\"text\",\"fields\":" + "{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}}}}", - Strings.toString(doc.dynamicMappingsUpdate()) + Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()) ); } @@ -199,9 +200,9 @@ public void testIncremental() throws Exception { })); assertNotNull(doc.dynamicMappingsUpdate()); - assertThat(Strings.toString(doc.dynamicMappingsUpdate()), containsString("{\"bar\":")); + assertThat(Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("{\"bar\":")); // field is NOT in the update - assertThat(Strings.toString(doc.dynamicMappingsUpdate()), not(containsString("{\"field\":"))); + assertThat(Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), not(containsString("{\"field\":"))); } public void testIntroduceTwoFields() throws Exception { @@ -213,8 +214,8 @@ public void testIntroduceTwoFields() throws Exception { })); assertNotNull(doc.dynamicMappingsUpdate()); - assertThat(Strings.toString(doc.dynamicMappingsUpdate()), containsString("\"foo\":{")); - assertThat(Strings.toString(doc.dynamicMappingsUpdate()), containsString("\"bar\":{")); + assertThat(Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("\"foo\":{")); + assertThat(Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("\"bar\":{")); } public void testObject() throws Exception { @@ -229,7 +230,7 @@ public void testObject() throws Exception { assertNotNull(doc.dynamicMappingsUpdate()); assertThat( - Strings.toString(doc.dynamicMappingsUpdate()), + Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("{\"foo\":{\"properties\":{\"bar\":{\"properties\":{\"baz\":{\"type\":\"text\"") ); } @@ -240,7 +241,7 @@ public void testArray() throws Exception { ParsedDocument doc = mapper.parse(source(b -> b.startArray("foo").value("bar").value("baz").endArray())); assertNotNull(doc.dynamicMappingsUpdate()); - assertThat(Strings.toString(doc.dynamicMappingsUpdate()), containsString("{\"foo\":{\"type\":\"text\"")); + assertThat(Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("{\"foo\":{\"type\":\"text\"")); } public void testInnerDynamicMapping() throws Exception { @@ -256,7 +257,7 @@ public void testInnerDynamicMapping() throws Exception { assertNotNull(doc.dynamicMappingsUpdate()); assertThat( - Strings.toString(doc.dynamicMappingsUpdate()), + Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()), containsString("{\"field\":{\"properties\":{\"bar\":{\"properties\":{\"baz\":{\"type\":\"text\"") ); } @@ -276,7 +277,7 @@ public void testComplexArray() throws Exception { assertEquals( "{\"_doc\":{\"properties\":{\"foo\":{\"properties\":{\"bar\":{\"type\":\"text\",\"fields\":{" + "\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}},\"baz\":{\"type\":\"long\"}}}}}}", - Strings.toString(doc.dynamicMappingsUpdate()) + Strings.toString(XContentType.JSON, doc.dynamicMappingsUpdate()) ); } diff --git a/server/src/test/java/org/opensearch/index/mapper/GeoShapeFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/GeoShapeFieldMapperTests.java index 187f17cbfd6ff..6e3216e934b07 100644 --- a/server/src/test/java/org/opensearch/index/mapper/GeoShapeFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/GeoShapeFieldMapperTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.geo.builders.ShapeBuilder; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; import org.opensearch.test.TestGeoShapeFieldMapperPlugin; import org.junit.Before; @@ -228,6 +229,7 @@ public void testSerializeDefaults() throws Exception { DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping)); assertThat( Strings.toString( + XContentType.JSON, mapper.mappers().getMapper("field"), new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")) ), diff --git a/server/src/test/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapperTests.java index 30f9f283d9208..b43b7c51df1c7 100644 --- a/server/src/test/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapperTests.java @@ -46,6 +46,7 @@ import org.opensearch.common.geo.builders.ShapeBuilder; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.geometry.Point; import org.opensearch.index.query.QueryShardContext; import org.opensearch.plugins.Plugin; @@ -538,13 +539,13 @@ public void testSerializeDefaults() throws Exception { ToXContent.Params includeDefaults = new ToXContent.MapParams(singletonMap("include_defaults", "true")); { DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_shape").field("tree", "quadtree"))); - String serialized = Strings.toString(mapper.mappers().getMapper("field"), includeDefaults); + String serialized = Strings.toString(XContentType.JSON, mapper.mappers().getMapper("field"), includeDefaults); assertTrue(serialized, serialized.contains("\"precision\":\"50.0m\"")); assertTrue(serialized, serialized.contains("\"tree_levels\":21")); } { DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_shape").field("tree", "geohash"))); - String serialized = Strings.toString(mapper.mappers().getMapper("field"), includeDefaults); + String serialized = Strings.toString(XContentType.JSON, mapper.mappers().getMapper("field"), includeDefaults); assertTrue(serialized, serialized.contains("\"precision\":\"50.0m\"")); assertTrue(serialized, serialized.contains("\"tree_levels\":9")); } @@ -552,7 +553,7 @@ public void testSerializeDefaults() throws Exception { DocumentMapper mapper = createDocumentMapper( fieldMapping(b -> b.field("type", "geo_shape").field("tree", "quadtree").field("tree_levels", "6")) ); - String serialized = Strings.toString(mapper.mappers().getMapper("field"), includeDefaults); + String serialized = Strings.toString(XContentType.JSON, mapper.mappers().getMapper("field"), includeDefaults); assertFalse(serialized, serialized.contains("\"precision\":")); assertTrue(serialized, serialized.contains("\"tree_levels\":6")); } @@ -560,7 +561,7 @@ public void testSerializeDefaults() throws Exception { DocumentMapper mapper = createDocumentMapper( fieldMapping(b -> b.field("type", "geo_shape").field("tree", "quadtree").field("precision", "6")) ); - String serialized = Strings.toString(mapper.mappers().getMapper("field"), includeDefaults); + String serialized = Strings.toString(XContentType.JSON, mapper.mappers().getMapper("field"), includeDefaults); assertTrue(serialized, serialized.contains("\"precision\":\"6.0m\"")); assertFalse(serialized, serialized.contains("\"tree_levels\":")); } @@ -568,7 +569,7 @@ public void testSerializeDefaults() throws Exception { DocumentMapper mapper = createDocumentMapper( fieldMapping(b -> b.field("type", "geo_shape").field("tree", "quadtree").field("precision", "6m").field("tree_levels", "5")) ); - String serialized = Strings.toString(mapper.mappers().getMapper("field"), includeDefaults); + String serialized = Strings.toString(XContentType.JSON, mapper.mappers().getMapper("field"), includeDefaults); assertTrue(serialized, serialized.contains("\"precision\":\"6.0m\"")); assertTrue(serialized, serialized.contains("\"tree_levels\":5")); } @@ -590,7 +591,7 @@ public void testPointsOnlyDefaultsWithTermStrategy() throws IOException { assertThat(strategy.getGrid().getMaxLevels(), equalTo(23)); assertThat(strategy.isPointsOnly(), equalTo(true)); // term strategy changes the default for points_only, check that we handle it correctly - assertThat(Strings.toString(geoShapeFieldMapper), not(containsString("points_only"))); + assertThat(Strings.toString(XContentType.JSON, geoShapeFieldMapper), not(containsString("points_only"))); assertFieldWarnings("tree", "precision", "strategy"); } diff --git a/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java index f6489d264a6d3..3cd6df601089a 100644 --- a/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java @@ -42,6 +42,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.index.analysis.AnalyzerScope; import org.opensearch.index.analysis.IndexAnalyzers; @@ -265,7 +266,7 @@ public void testDefaults() throws IOException { assertTrue(mapper.fixed); assertEquals("default", mapper.variable); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); assertEquals( "{\"field\":{\"type\":\"test_mapper\",\"fixed\":true," + "\"fixed2\":false,\"variable\":\"default\",\"index\":true," @@ -279,7 +280,7 @@ public void testDefaults() throws IOException { public void testMerging() { String mapping = "{\"type\":\"test_mapper\",\"fixed\":false,\"required\":\"value\"}"; TestMapper mapper = fromMapping(mapping); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); TestMapper badMerge = fromMapping("{\"type\":\"test_mapper\",\"fixed\":true,\"fixed2\":true,\"required\":\"value\"}"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> mapper.merge(badMerge)); @@ -288,16 +289,16 @@ public void testMerging() { + "\tCannot update parameter [fixed2] from [false] to [true]"; assertEquals(expectedError, e.getMessage()); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); // original mapping is unaffected + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); // original mapping is unaffected // TODO: should we have to include 'fixed' here? Or should updates take as 'defaults' the existing values? TestMapper goodMerge = fromMapping("{\"type\":\"test_mapper\",\"fixed\":false,\"variable\":\"updated\",\"required\":\"value\"}"); TestMapper merged = (TestMapper) mapper.merge(goodMerge); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); // original mapping is unaffected + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); // original mapping is unaffected assertEquals( "{\"field\":{\"type\":\"test_mapper\",\"fixed\":false,\"variable\":\"updated\",\"required\":\"value\"}}", - Strings.toString(merged) + Strings.toString(XContentType.JSON, merged) ); } @@ -306,7 +307,7 @@ public void testMultifields() { String mapping = "{\"type\":\"test_mapper\",\"variable\":\"foo\",\"required\":\"value\"," + "\"fields\":{\"sub\":{\"type\":\"keyword\"}}}"; TestMapper mapper = fromMapping(mapping); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); String addSubField = "{\"type\":\"test_mapper\",\"variable\":\"foo\",\"required\":\"value\"" + ",\"fields\":{\"sub2\":{\"type\":\"keyword\"}}}"; @@ -315,7 +316,7 @@ public void testMultifields() { assertEquals( "{\"field\":{\"type\":\"test_mapper\",\"variable\":\"foo\",\"required\":\"value\"," + "\"fields\":{\"sub\":{\"type\":\"keyword\"},\"sub2\":{\"type\":\"keyword\"}}}}", - Strings.toString(merged) + Strings.toString(XContentType.JSON, merged) ); String badSubField = "{\"type\":\"test_mapper\",\"variable\":\"foo\",\"required\":\"value\"," @@ -329,7 +330,7 @@ public void testMultifields() { public void testCopyTo() { String mapping = "{\"type\":\"test_mapper\",\"variable\":\"foo\",\"required\":\"value\",\"copy_to\":[\"other\"]}"; TestMapper mapper = fromMapping(mapping); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); // On update, copy_to is completely replaced @@ -339,12 +340,15 @@ public void testCopyTo() { TestMapper merged = (TestMapper) mapper.merge(toMerge); assertEquals( "{\"field\":{\"type\":\"test_mapper\",\"variable\":\"updated\",\"required\":\"value\"," + "\"copy_to\":[\"foo\",\"bar\"]}}", - Strings.toString(merged) + Strings.toString(XContentType.JSON, merged) ); TestMapper removeCopyTo = fromMapping("{\"type\":\"test_mapper\",\"variable\":\"updated\",\"required\":\"value\"}"); TestMapper noCopyTo = (TestMapper) merged.merge(removeCopyTo); - assertEquals("{\"field\":{\"type\":\"test_mapper\",\"variable\":\"updated\",\"required\":\"value\"}}", Strings.toString(noCopyTo)); + assertEquals( + "{\"field\":{\"type\":\"test_mapper\",\"variable\":\"updated\",\"required\":\"value\"}}", + Strings.toString(XContentType.JSON, noCopyTo) + ); } public void testNullables() { @@ -354,7 +358,7 @@ public void testNullables() { String fine = "{\"type\":\"test_mapper\",\"variable\":null,\"required\":\"value\"}"; TestMapper mapper = fromMapping(fine); - assertEquals("{\"field\":" + fine + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + fine + "}", Strings.toString(XContentType.JSON, mapper)); } public void testObjectSerialization() throws IOException { @@ -369,10 +373,10 @@ public void testObjectSerialization() throws IOException { + "\"is_interim\":{\"type\":\"boolean\"}}}}}}"; MapperService mapperService = createMapperService("_doc", mapping); - assertEquals(mapping, Strings.toString(mapperService.documentMapper())); + assertEquals(mapping, Strings.toString(XContentType.JSON, mapperService.documentMapper())); mapperService.merge("_doc", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); - assertEquals(mapping, Strings.toString(mapperService.documentMapper())); + assertEquals(mapping, Strings.toString(XContentType.JSON, mapperService.documentMapper())); } // test custom serializer @@ -380,7 +384,7 @@ public void testCustomSerialization() { String mapping = "{\"type\":\"test_mapper\",\"wrapper\":\"wrapped value\",\"required\":\"value\"}"; TestMapper mapper = fromMapping(mapping); assertEquals("wrapped value", mapper.wrapper.name); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); String conflict = "{\"type\":\"test_mapper\",\"wrapper\":\"new value\",\"required\":\"value\"}"; TestMapper toMerge = fromMapping(conflict); @@ -397,7 +401,7 @@ public void testParameterValidation() { String mapping = "{\"type\":\"test_mapper\",\"int_value\":10,\"required\":\"value\"}"; TestMapper mapper = fromMapping(mapping); assertEquals(10, mapper.intValue); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); IllegalArgumentException e = expectThrows( IllegalArgumentException.class, @@ -412,20 +416,23 @@ public void testDeprecatedParameterName() { TestMapper mapper = fromMapping(mapping); assertTrue(mapper.fixed2); assertWarnings("Parameter [fixed2_old] on mapper [field] is deprecated, use [fixed2]"); - assertEquals("{\"field\":{\"type\":\"test_mapper\",\"fixed2\":true,\"required\":\"value\"}}", Strings.toString(mapper)); + assertEquals( + "{\"field\":{\"type\":\"test_mapper\",\"fixed2\":true,\"required\":\"value\"}}", + Strings.toString(XContentType.JSON, mapper) + ); } public void testAnalyzers() { String mapping = "{\"type\":\"test_mapper\",\"analyzer\":\"_standard\",\"required\":\"value\"}"; TestMapper mapper = fromMapping(mapping); assertEquals(mapper.analyzer, Lucene.STANDARD_ANALYZER); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); String withDef = "{\"type\":\"test_mapper\",\"analyzer\":\"default\",\"required\":\"value\"}"; mapper = fromMapping(withDef); assertEquals(mapper.analyzer.name(), "default"); assertThat(mapper.analyzer.analyzer(), instanceOf(StandardAnalyzer.class)); - assertEquals("{\"field\":" + withDef + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + withDef + "}", Strings.toString(XContentType.JSON, mapper)); String badAnalyzer = "{\"type\":\"test_mapper\",\"analyzer\":\"wibble\",\"required\":\"value\"}"; IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> fromMapping(badAnalyzer)); @@ -446,7 +453,10 @@ public void testDeprecatedParameters() { TestMapper mapper = fromMapping(mapping, LegacyESVersion.V_7_8_0); assertWarnings("Parameter [store] has no effect on type [test_mapper] and will be removed in future"); assertFalse(mapper.index); - assertEquals("{\"field\":{\"type\":\"test_mapper\",\"index\":false,\"required\":\"value\"}}", Strings.toString(mapper)); + assertEquals( + "{\"field\":{\"type\":\"test_mapper\",\"index\":false,\"required\":\"value\"}}", + Strings.toString(XContentType.JSON, mapper) + ); } public void testLinkedAnalyzers() throws IOException { @@ -454,20 +464,20 @@ public void testLinkedAnalyzers() throws IOException { TestMapper mapper = fromMapping(mapping); assertEquals("_standard", mapper.analyzer.name()); assertEquals("_standard", mapper.searchAnalyzer.name()); - assertEquals("{\"field\":" + mapping + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mapping + "}", Strings.toString(XContentType.JSON, mapper)); String mappingWithSA = "{\"type\":\"test_mapper\",\"search_analyzer\":\"_standard\",\"required\":\"value\"}"; mapper = fromMapping(mappingWithSA); assertEquals("_keyword", mapper.analyzer.name()); assertEquals("_standard", mapper.searchAnalyzer.name()); - assertEquals("{\"field\":" + mappingWithSA + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mappingWithSA + "}", Strings.toString(XContentType.JSON, mapper)); String mappingWithBoth = "{\"type\":\"test_mapper\",\"analyzer\":\"default\"," + "\"search_analyzer\":\"_standard\",\"required\":\"value\"}"; mapper = fromMapping(mappingWithBoth); assertEquals("default", mapper.analyzer.name()); assertEquals("_standard", mapper.searchAnalyzer.name()); - assertEquals("{\"field\":" + mappingWithBoth + "}", Strings.toString(mapper)); + assertEquals("{\"field\":" + mappingWithBoth + "}", Strings.toString(XContentType.JSON, mapper)); // we've configured things so that search_analyzer is only output when different from // analyzer, no matter what the value of `include_defaults` is @@ -476,7 +486,10 @@ public void testLinkedAnalyzers() throws IOException { mapper = fromMapping(mappingWithSame); assertEquals("default", mapper.analyzer.name()); assertEquals("default", mapper.searchAnalyzer.name()); - assertEquals("{\"field\":{\"type\":\"test_mapper\",\"analyzer\":\"default\",\"required\":\"value\"}}", Strings.toString(mapper)); + assertEquals( + "{\"field\":{\"type\":\"test_mapper\",\"analyzer\":\"default\",\"required\":\"value\"}}", + Strings.toString(XContentType.JSON, mapper) + ); assertEquals( "{\"field\":{\"type\":\"test_mapper\",\"fixed\":true," diff --git a/server/src/test/java/org/opensearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/TextFieldMapperTests.java index 8a5a0e8864d3e..a56ab2713d498 100644 --- a/server/src/test/java/org/opensearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/TextFieldMapperTests.java @@ -68,6 +68,7 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.IndexSettings; import org.opensearch.index.analysis.AnalyzerScope; import org.opensearch.index.analysis.CharFilterFactory; @@ -284,7 +285,7 @@ public void testBWCSerialization() throws IOException { assertEquals( "{\"_doc\":{\"properties\":{\"field\":{\"type\":\"text\",\"fields\":{\"subfield\":{\"type\":\"long\"}},\"fielddata\":true}}}}", - Strings.toString(mapperService.documentMapper()) + Strings.toString(XContentType.JSON, mapperService.documentMapper()) ); } @@ -325,7 +326,7 @@ public void testIndexOptions() throws IOException { mapping.endObject().endObject().endObject(); DocumentMapper mapper = createDocumentMapper(mapping); - String serialized = Strings.toString(mapper); + String serialized = Strings.toString(XContentType.JSON, mapper); assertThat(serialized, containsString("\"offsets\":{\"type\":\"text\",\"index_options\":\"offsets\"}")); assertThat(serialized, containsString("\"freqs\":{\"type\":\"text\",\"index_options\":\"freqs\"}")); assertThat(serialized, containsString("\"docs\":{\"type\":\"text\",\"index_options\":\"docs\"}")); diff --git a/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java b/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java index 977f5ebb7a80f..d50da77664ba9 100644 --- a/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java +++ b/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java @@ -65,6 +65,7 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.persistent.PersistentTasksCustomMetadata.Assignment; import org.opensearch.persistent.PersistentTasksCustomMetadata.PersistentTask; import org.opensearch.plugins.ActionPlugin; @@ -299,7 +300,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } // Implements equals and hashcode for testing diff --git a/server/src/test/java/org/opensearch/script/ScriptTests.java b/server/src/test/java/org/opensearch/script/ScriptTests.java index 9bbc744301ce4..d49eb4fd67ce1 100644 --- a/server/src/test/java/org/opensearch/script/ScriptTests.java +++ b/server/src/test/java/org/opensearch/script/ScriptTests.java @@ -166,7 +166,11 @@ public void testParseFromObjectFromScript() { options.put("option" + i, Integer.toString(i)); } Script script = new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "doc['field']", options, params); - Map scriptObject = XContentHelper.convertToMap(XContentType.JSON.xContent(), Strings.toString(script), false); + Map scriptObject = XContentHelper.convertToMap( + XContentType.JSON.xContent(), + Strings.toString(XContentType.JSON, script), + false + ); Script parsedScript = Script.parse(scriptObject); assertEquals(script, parsedScript); } diff --git a/server/src/test/java/org/opensearch/search/sort/SortValueTests.java b/server/src/test/java/org/opensearch/search/sort/SortValueTests.java index 08d6952db47fd..146d6e62e1339 100644 --- a/server/src/test/java/org/opensearch/search/sort/SortValueTests.java +++ b/server/src/test/java/org/opensearch/search/sort/SortValueTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.time.DateFormatter; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.DateFieldMapper; import org.opensearch.search.DocValueFormat; import org.opensearch.test.AbstractNamedWriteableTestCase; @@ -119,7 +120,7 @@ public void testCompareLongs() { } public String toXContent(SortValue sortValue, DocValueFormat format) { - return Strings.toString(new ToXContentFragment() { + return Strings.toString(XContentType.JSON, new ToXContentFragment() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("test"); diff --git a/test/framework/src/main/java/org/opensearch/search/aggregations/BaseAggregationTestCase.java b/test/framework/src/main/java/org/opensearch/search/aggregations/BaseAggregationTestCase.java index 4237d52acaf6f..d94e51c94b9c7 100644 --- a/test/framework/src/main/java/org/opensearch/search/aggregations/BaseAggregationTestCase.java +++ b/test/framework/src/main/java/org/opensearch/search/aggregations/BaseAggregationTestCase.java @@ -138,7 +138,7 @@ public void testSerializationMulti() throws IOException { */ public void testToString() throws IOException { AB testAgg = createTestAggregatorBuilder(); - String toString = randomBoolean() ? Strings.toString(testAgg) : testAgg.toString(); + String toString = randomBoolean() ? Strings.toString(XContentType.JSON, testAgg) : testAgg.toString(); XContentParser parser = createParser(XContentType.JSON.xContent(), toString); AggregationBuilder newAgg = parse(parser); assertNotSame(newAgg, testAgg); diff --git a/test/framework/src/main/java/org/opensearch/test/AbstractBroadcastResponseTestCase.java b/test/framework/src/main/java/org/opensearch/test/AbstractBroadcastResponseTestCase.java index d43ae76da97df..d8099793bb61a 100644 --- a/test/framework/src/main/java/org/opensearch/test/AbstractBroadcastResponseTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/AbstractBroadcastResponseTestCase.java @@ -150,7 +150,7 @@ public void testFailuresDeduplication() throws IOException { public void testToXContent() { T response = createTestInstance(10, 10, 0, null); - String output = Strings.toString(response); + String output = Strings.toString(XContentType.JSON, response); assertEquals("{\"_shards\":{\"total\":10,\"successful\":10,\"failed\":0}}", output); } } diff --git a/test/framework/src/main/java/org/opensearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/opensearch/test/AbstractQueryTestCase.java index 7ce7903296a5a..ac493bdd68d71 100644 --- a/test/framework/src/main/java/org/opensearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/AbstractQueryTestCase.java @@ -634,7 +634,7 @@ public void testValidOutput() throws IOException { for (int runs = 0; runs < NUMBER_OF_TESTQUERIES; runs++) { QB testQuery = createTestQueryBuilder(); XContentType xContentType = XContentType.JSON; - String toString = Strings.toString(testQuery); + String toString = Strings.toString(XContentType.JSON, testQuery); assertParsedQuery(createParser(xContentType.xContent(), toString), testQuery); BytesReference bytes = XContentHelper.toXContent(testQuery, xContentType, false); assertParsedQuery(createParser(xContentType.xContent(), bytes), testQuery); diff --git a/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java b/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java index 05b086f93fb4d..3d74b0df5f283 100644 --- a/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java @@ -966,7 +966,7 @@ protected static void createIndex(String name, Settings settings, String mapping protected static void createIndex(String name, Settings settings, String mapping, String aliases) throws IOException { Request request = new Request("PUT", "/" + name); - String entity = "{\"settings\": " + Strings.toString(settings); + String entity = "{\"settings\": " + Strings.toString(XContentType.JSON, settings); if (mapping != null) { entity += ",\"mappings\" : {" + mapping + "}"; } @@ -992,7 +992,7 @@ protected static void updateIndexSettings(String index, Settings.Builder setting private static void updateIndexSettings(String index, Settings settings) throws IOException { Request request = new Request("PUT", "/" + index + "/_settings"); - request.setJsonEntity(Strings.toString(settings)); + request.setJsonEntity(Strings.toString(XContentType.JSON, settings)); client().performRequest(request); } @@ -1102,7 +1102,7 @@ protected static Map responseAsMap(Response response) throws IOE protected static void registerRepository(String repository, String type, boolean verify, Settings settings) throws IOException { final Request request = new Request(HttpPut.METHOD_NAME, "_snapshot/" + repository); request.addParameter("verify", Boolean.toString(verify)); - request.setJsonEntity(Strings.toString(new PutRepositoryRequest(repository).type(type).settings(settings))); + request.setJsonEntity(Strings.toString(XContentType.JSON, new PutRepositoryRequest(repository).type(type).settings(settings))); final Response response = client().performRequest(request); assertAcked("Failed to create repository [" + repository + "] of type [" + type + "]: " + response, response); diff --git a/test/framework/src/main/java/org/opensearch/test/rest/yaml/OpenSearchClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/opensearch/test/rest/yaml/OpenSearchClientYamlSuiteTestCase.java index f228c87186afd..fa484de4c5595 100644 --- a/test/framework/src/main/java/org/opensearch/test/rest/yaml/OpenSearchClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/rest/yaml/OpenSearchClientYamlSuiteTestCase.java @@ -49,6 +49,7 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.PathUtils; import org.opensearch.common.xcontent.NamedXContentRegistry; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.internal.io.IOUtils; import org.opensearch.test.rest.OpenSearchRestTestCase; import org.opensearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi; @@ -449,7 +450,7 @@ private void executeSection(ExecutableSection executableSection) { // Dump the stash on failure. Instead of dumping it in true json we escape `\n`s so stack traces are easier to read logger.info( "Stash dump on test failure [{}]", - Strings.toString(restTestExecutionContext.stash(), true, true) + Strings.toString(XContentType.JSON, restTestExecutionContext.stash(), true, true) .replace("\\n", "\n") .replace("\\r", "\r") .replace("\\t", "\t")