From 9a48c7df7c7a11107dfecc8b4537011158dc1ceb Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 25 Jan 2023 10:51:40 -0600 Subject: [PATCH] Require MediaType in Strings.toString API String.toString is tightly coupled to XContentType.JSON which blocks modularizing foundation classes from the server module to the core library. This change refactors the String.toString API to accept a generic MediaType such that the toString implementation detail is encapsulated to the :server module. Signed-off-by: Nicholas Walter Knize --- .../client/slm/SnapshotLifecyclePolicy.java | 3 +- .../slm/SnapshotLifecyclePolicyMetadata.java | 3 +- .../client/slm/SnapshotLifecycleStats.java | 3 +- .../slm/SnapshotRetentionConfiguration.java | 3 +- .../opensearch/test/rest/NodeRestUsageIT.java | 9 +-- .../opensearch/common/xcontent/MediaType.java | 4 ++ .../common/xcontent/XContentType.java | 21 +++++++ .../common/xcontent/SimpleStruct.java | 2 +- .../mustache/MultiSearchTemplateResponse.java | 3 +- .../SearchAsYouTypeFieldMapperTests.java | 5 +- .../index/rankeval/RankEvalResponse.java | 3 +- .../index/rankeval/RankEvalSpec.java | 3 +- .../index/rankeval/RatedDocument.java | 3 +- .../index/rankeval/RatedRequest.java | 3 +- .../DiscountedCumulativeGainTests.java | 7 ++- .../upgrades/FullClusterRestartIT.java | 5 +- .../java/org/opensearch/search/CCSDuelIT.java | 2 +- .../org/opensearch/upgrades/RecoveryIT.java | 5 +- .../http/SearchRestCancellationIT.java | 4 +- .../action/bulk/BulkWithUpdatesIT.java | 8 ++- .../cluster/routing/PrimaryAllocationIT.java | 3 +- .../opensearch/index/shard/IndexShardIT.java | 2 +- .../indices/recovery/IndexRecoveryIT.java | 5 +- .../search/SearchCancellationIT.java | 5 +- .../cluster/health/ClusterHealthResponse.java | 3 +- .../tasks/cancel/CancelTasksResponse.java | 3 +- .../node/tasks/get/GetTaskResponse.java | 3 +- .../node/tasks/list/ListTasksResponse.java | 3 +- .../restore/RestoreRemoteStoreRequest.java | 3 +- .../verify/VerifyRepositoryResponse.java | 3 +- .../settings/ClusterGetSettingsResponse.java | 3 +- .../snapshots/clone/CloneSnapshotRequest.java | 3 +- .../snapshots/get/GetSnapshotsResponse.java | 3 +- .../restore/RestoreSnapshotRequest.java | 2 +- .../snapshots/status/SnapshotStats.java | 3 +- .../snapshots/status/SnapshotStatus.java | 3 +- .../admin/cluster/stats/AnalysisStats.java | 3 +- .../admin/cluster/stats/MappingStats.java | 3 +- .../action/admin/indices/alias/Alias.java | 2 +- .../admin/indices/analyze/AnalyzeAction.java | 3 +- .../indices/close/CloseIndexResponse.java | 9 +-- .../admin/indices/get/GetIndexResponse.java | 3 +- .../mapping/get/GetMappingsResponse.java | 3 +- .../readonly/AddIndexBlockResponse.java | 9 +-- .../indices/recovery/RecoveryResponse.java | 3 +- .../admin/indices/rollover/RolloverInfo.java | 3 +- .../settings/put/UpdateSettingsRequest.java | 2 +- .../indices/stats/IndicesStatsResponse.java | 3 +- .../action/bulk/BulkItemRequest.java | 3 +- .../action/bulk/BulkItemResponse.java | 3 +- .../action/fieldcaps/FieldCapabilities.java | 3 +- .../fieldcaps/FieldCapabilitiesResponse.java | 3 +- .../opensearch/action/get/GetResponse.java | 3 +- .../action/get/MultiGetRequest.java | 3 +- .../action/index/IndexResponse.java | 3 +- .../action/ingest/GetPipelineResponse.java | 3 +- .../action/search/MultiSearchResponse.java | 3 +- .../action/search/SearchResponse.java | 3 +- .../support/replication/ReplicationTask.java | 3 +- .../cluster/RepositoryCleanupInProgress.java | 3 +- .../cluster/SnapshotsInProgress.java | 3 +- .../ClusterAwarenessAttributeValueHealth.java | 3 +- .../ClusterAwarenessAttributesHealth.java | 3 +- .../cluster/coordination/Coordinator.java | 15 +++-- .../DecommissionAttributeMetadata.java | 3 +- .../cluster/health/ClusterShardHealth.java | 3 +- .../cluster/metadata/AliasMetadata.java | 3 +- .../cluster/metadata/ComponentTemplate.java | 3 +- .../metadata/ComponentTemplateMetadata.java | 3 +- .../metadata/ComposableIndexTemplate.java | 3 +- .../ComposableIndexTemplateMetadata.java | 3 +- .../cluster/metadata/DataStreamMetadata.java | 3 +- .../metadata/RepositoriesMetadata.java | 3 +- .../opensearch/cluster/metadata/Template.java | 2 +- .../metadata/WeightedRoutingMetadata.java | 3 +- .../command/AllocationCommands.java | 3 +- .../java/org/opensearch/common/Strings.java | 24 ++++---- .../common/geo/builders/ShapeBuilder.java | 3 +- .../opensearch/common/settings/Setting.java | 2 +- .../org/opensearch/index/get/GetResult.java | 3 +- .../index/mapper/MapperService.java | 2 +- .../index/mapper/RootObjectMapper.java | 3 +- .../index/query/AbstractQueryBuilder.java | 3 +- .../index/query/InnerHitBuilder.java | 3 +- .../index/query/SpanNearQueryBuilder.java | 3 +- .../index/reindex/BulkByScrollTask.java | 5 +- .../index/reindex/ScrollableHitSource.java | 2 +- .../index/search/stats/SearchStats.java | 3 +- .../index/shard/PrimaryReplicaSyncer.java | 3 +- .../RemoveCorruptedShardDataCommand.java | 3 +- .../index/translog/TranslogStats.java | 3 +- .../ingest/PipelineConfiguration.java | 2 +- .../PersistentTasksCustomMetadata.java | 5 +- .../PersistentTasksNodeService.java | 3 +- .../repositories/RepositoryCleanupResult.java | 3 +- .../repositories/RepositoryInfo.java | 3 +- .../repositories/RepositoryStatsSnapshot.java | 3 +- .../java/org/opensearch/search/SearchHit.java | 3 +- .../aggregations/AggregationBuilder.java | 3 +- .../aggregations/AggregatorFactories.java | 3 +- .../search/aggregations/BucketOrder.java | 3 +- .../aggregations/InternalAggregation.java | 3 +- .../PipelineAggregationBuilder.java | 3 +- .../BaseMultiValuesSourceFieldConfig.java | 3 +- .../highlight/AbstractHighlighterBuilder.java | 3 +- .../search/rescore/RescorerBuilder.java | 3 +- .../opensearch/search/slice/SliceBuilder.java | 3 +- .../opensearch/search/sort/SortBuilder.java | 3 +- .../opensearch/search/suggest/Suggest.java | 3 +- .../search/suggest/SuggestBuilder.java | 3 +- .../org/opensearch/snapshots/RestoreInfo.java | 3 +- .../org/opensearch/tasks/RawTaskStatus.java | 3 +- .../java/org/opensearch/tasks/TaskInfo.java | 3 +- .../opensearch/tasks/TaskResourceStats.java | 3 +- .../opensearch/tasks/TaskResourceUsage.java | 3 +- .../java/org/opensearch/tasks/TaskResult.java | 3 +- .../ExceptionSerializationTests.java | 11 +++- .../opensearch/OpenSearchExceptionTests.java | 4 +- .../node/tasks/TransportTasksActionTests.java | 2 +- .../close/CloseIndexResponseTests.java | 4 +- .../create/CreateIndexResponseTests.java | 5 +- .../get/GetFieldMappingsResponseTests.java | 3 +- .../mapping/put/PutMappingRequestTests.java | 4 +- .../indices/shrink/ResizeRequestTests.java | 4 +- .../indices/shrink/ResizeResponseTests.java | 3 +- .../indices/stats/IndicesStatsTests.java | 3 +- .../query/ValidateQueryResponseTests.java | 3 +- .../action/delete/DeleteResponseTests.java | 4 +- .../action/get/GetResponseTests.java | 4 +- .../action/index/IndexResponseTests.java | 4 +- .../search/MultiSearchRequestTests.java | 2 +- .../SearchPhaseExecutionExceptionTests.java | 2 +- .../action/search/SearchResponseTests.java | 4 +- ...ultShardOperationFailedExceptionTests.java | 8 +-- .../replication/ReplicationResponseTests.java | 4 +- .../action/update/UpdateResponseTests.java | 6 +- .../cluster/metadata/IndexGraveyardTests.java | 3 +- .../cluster/metadata/IndexMetadataTests.java | 6 +- .../ClusterStateToStringTests.java | 3 +- .../org/opensearch/common/StringsTests.java | 7 ++- .../index/get/DocumentFieldTests.java | 2 +- .../opensearch/index/get/GetResultTests.java | 4 +- .../mapper/CompletionFieldMapperTests.java | 3 +- .../index/mapper/DynamicMappingTests.java | 19 +++--- .../mapper/GeoShapeFieldMapperTests.java | 2 + .../LegacyGeoShapeFieldMapperTests.java | 13 ++-- .../index/mapper/ParametrizedMapperTests.java | 59 +++++++++++-------- .../index/mapper/TextFieldMapperTests.java | 5 +- .../persistent/TestPersistentTasksPlugin.java | 3 +- .../org/opensearch/script/ScriptTests.java | 6 +- .../search/sort/SortValueTests.java | 3 +- .../aggregations/BaseAggregationTestCase.java | 2 +- .../AbstractBroadcastResponseTestCase.java | 2 +- .../test/AbstractQueryTestCase.java | 2 +- .../test/rest/OpenSearchRestTestCase.java | 6 +- .../OpenSearchClientYamlSuiteTestCase.java | 3 +- 156 files changed, 425 insertions(+), 243 deletions(-) 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..f2442f9bbf61e 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 @@ -32,6 +32,8 @@ package org.opensearch.common.xcontent; +import java.io.IOException; + /** * Abstracts a Media Type and a format parameter. * Media types are used as values on Content-Type and Accept headers @@ -62,4 +64,6 @@ public interface MediaType { default String typeWithSubtype() { return type() + "/" + subtype(); } + + XContentBuilder contentBuilder() throws IOException; } 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..1339bf032208e 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 @@ -37,6 +37,7 @@ import org.opensearch.common.xcontent.smile.SmileXContent; import org.opensearch.common.xcontent.yaml.YamlXContent; +import java.io.IOException; import java.util.Locale; import java.util.Map; @@ -68,6 +69,11 @@ public String subtype() { public XContent xContent() { return JsonXContent.jsonXContent; } + + @Override + public XContentBuilder contentBuilder() throws IOException { + return JsonXContent.contentBuilder(); + } }, /** * The jackson based smile binary format. Fast and compact binary format. @@ -87,6 +93,11 @@ public String subtype() { public XContent xContent() { return SmileXContent.smileXContent; } + + @Override + public XContentBuilder contentBuilder() throws IOException { + return SmileXContent.contentBuilder(); + } }, /** * A YAML based content type. @@ -106,6 +117,11 @@ public String subtype() { public XContent xContent() { return YamlXContent.yamlXContent; } + + @Override + public XContentBuilder contentBuilder() throws IOException { + return YamlXContent.contentBuilder(); + } }, /** * A CBOR based content type. @@ -125,6 +141,11 @@ public String subtype() { public XContent xContent() { return CborXContent.cborXContent; } + + @Override + public XContentBuilder contentBuilder() throws IOException { + return CborXContent.contentBuilder(); + } }; /** a parser of media types */ 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 7c2c403fdd487..1b195f0148348 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 @@ -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 java.io.IOException; import java.util.Arrays; @@ -199,6 +200,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 6ab2293620893..28f99b07f3bfe 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 48b2460f61ff8..944deb4f18592 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 @@ -44,6 +44,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; @@ -1364,7 +1365,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); @@ -1376,7 +1377,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/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java index 8c303eb5d0b55..0902f735b6448 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 @@ -31,7 +31,6 @@ package org.opensearch.upgrades; -import org.opensearch.LegacyESVersion; import org.opensearch.Version; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.client.Request; @@ -44,13 +43,13 @@ 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.index.mapper.MapperService; import org.opensearch.rest.RestStatus; import org.opensearch.test.rest.yaml.ObjectPath; import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.hamcrest.Matcher; import org.hamcrest.Matchers; import java.io.IOException; @@ -734,7 +733,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 c15678a3f2f38..9692ff895b062 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 d8476e6284d98..9cdac985310bd 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java @@ -453,7 +453,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 1735827d259db..4b3e43ed005d4 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 b019bc9eff476..b66ee644349ef 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 @@ -689,6 +689,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 5fa908a039887..e1291042a2056 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 @@ -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.snapshots.Snapshot; import org.opensearch.snapshots.SnapshotId; @@ -205,7 +206,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 3f78d99d49423..0c7c8960e0fe7 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 @@ -305,7 +305,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 dd16266a4e863..60f7e8d5616c9 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 @@ -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.index.analysis.NameOrDefinition; import java.io.IOException; @@ -385,7 +386,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 0388ea47bfc69..283f705c7903f 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 @@ -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); } } @@ -250,7 +251,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa @Override public String toString() { - return Strings.toString(this); + return Strings.toString(XContentType.JSON, this); } /** @@ -296,7 +297,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 9de7dbadaa7df..8c24d570d4d4d 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 @@ -44,6 +44,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; @@ -327,7 +328,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/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 9845413fe8af8..4a40d277b5c17 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; @@ -113,7 +114,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 364952dff82f1..75259d0931ae8 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkItemResponse.java @@ -51,6 +51,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; @@ -367,7 +368,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 4afce67f98297..fa8677b4bbee9 100644 --- a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.java +++ b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilities.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.ArrayList; @@ -288,7 +289,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 847cca25ceb35..453b2a6c9f6bb 100644 --- a/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.java +++ b/server/src/main/java/org/opensearch/action/fieldcaps/FieldCapabilitiesResponse.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; import java.util.Arrays; @@ -212,6 +213,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 87881071d4ec8..8e2a87410b79a 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetRequest.java @@ -53,6 +53,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; @@ -260,7 +261,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 c4ba3becbc151..5ffc7ec1ddf2f 100644 --- a/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/MultiSearchResponse.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 java.io.IOException; import java.util.Arrays; @@ -254,6 +255,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 3f01b92263b17..523b30ae247ac 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/SearchResponse.java @@ -46,6 +46,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; @@ -462,7 +463,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 291aa88a3fb3e..d9acca8e7c08e 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 f77b3e3b2a904..7980607c6cfae 100644 --- a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java @@ -46,6 +46,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; @@ -654,7 +655,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 eb069dc1f7698..b4c9380a76b10 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java @@ -73,6 +73,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; @@ -1318,16 +1319,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 f6ab59c7efbbe..2e409e614548f 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/AliasMetadata.java @@ -48,6 +48,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; @@ -258,7 +259,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 b06908c1a4019..17eb6ee21fbf9 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComponentTemplateMetadata.java @@ -43,6 +43,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/ComposableIndexTemplate.java b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java index d350f4deb3077..70b7a6d653b4d 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplate.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.mapper.DataStreamFieldMapper; import org.opensearch.index.mapper.MapperService; @@ -278,7 +279,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 72e086f2cde59..a75e428c97416 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ComposableIndexTemplateMetadata.java @@ -43,6 +43,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; @@ -155,7 +156,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 5381847853b25..4de68de3085ee 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/DataStreamMetadata.java @@ -43,6 +43,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; @@ -159,7 +160,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 7ec053522c5a6..08b1bec157c5b 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; @@ -712,8 +712,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); } /** @@ -722,8 +722,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); } /** @@ -740,8 +740,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); } /** @@ -750,9 +750,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(); } @@ -763,7 +763,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)); @@ -775,8 +775,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 = mediaType.contentBuilder(); 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 f86fe6771dfcd..588092976cc72 100644 --- a/server/src/main/java/org/opensearch/common/settings/Setting.java +++ b/server/src/main/java/org/opensearch/common/settings/Setting.java @@ -594,7 +594,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 5da4f8d5c7833..4db2b352ac7ec 100644 --- a/server/src/main/java/org/opensearch/index/get/GetResult.java +++ b/server/src/main/java/org/opensearch/index/get/GetResult.java @@ -45,6 +45,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; @@ -476,6 +477,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 af37ddc41b567..ec4898769eecd 100644 --- a/server/src/main/java/org/opensearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/opensearch/index/mapper/MapperService.java @@ -348,7 +348,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 3c68a65c5d6f9..c05c2382e792e 100644 --- a/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/RootObjectMapper.java @@ -40,6 +40,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; @@ -458,7 +459,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 4f14e5bf274e9..5e8f4fac6dfb9 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -56,6 +56,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; @@ -1107,6 +1108,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 714de06fef1e0..cd0a07bf8d4cc 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java +++ b/server/src/main/java/org/opensearch/search/aggregations/InternalAggregation.java @@ -37,6 +37,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; @@ -368,7 +369,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 c8f33240b024f..5423c7b03730f 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 @@ -18,6 +18,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; @@ -146,7 +147,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 1fd94eaddb2dd..ece7638c69a71 100644 --- a/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java +++ b/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java @@ -51,6 +51,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; @@ -327,6 +328,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 e59d8e9d33efa..b79d5fc7b1baf 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; @@ -282,6 +283,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 7943892b2af89..7547e27877cff 100644 --- a/server/src/main/java/org/opensearch/search/suggest/Suggest.java +++ b/server/src/main/java/org/opensearch/search/suggest/Suggest.java @@ -47,6 +47,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; @@ -739,6 +740,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 db1aeb3eeb614..7783e21736c9f 100644 --- a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java @@ -76,6 +76,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; @@ -530,9 +531,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 a981c527b6da6..ba806cbf559ba 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 e1953797f5058..4166bf075ecf6 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 dd4f3e2b1ae0a..df76022248b02 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 f28876b838084..3d981a276eb18 100644 --- a/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/ParametrizedMapperTests.java @@ -41,6 +41,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; @@ -264,7 +265,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," @@ -278,7 +279,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)); @@ -287,16 +288,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) ); } @@ -305,7 +306,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\"}}}"; @@ -314,7 +315,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\"," @@ -328,7 +329,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 @@ -338,12 +339,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() { @@ -353,7 +357,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 { @@ -368,10 +372,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 @@ -379,7 +383,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); @@ -396,7 +400,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, @@ -411,20 +415,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)); @@ -445,7 +452,10 @@ public void testDeprecatedParameters() { TestMapper mapper = fromMapping(mapping, Version.V_2_0_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 { @@ -453,20 +463,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 @@ -475,7 +485,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 4fbf56babea29..dfc37d63b42f3 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 @@ -973,7 +973,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 + "}"; } @@ -999,7 +999,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); } @@ -1087,7 +1087,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 b5449480e38ff..c4ce92af782da 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 @@ -50,6 +50,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; @@ -450,7 +451,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")