Skip to content

Commit 8b698f0

Browse files
turn GetFieldMappingsResponse to ToXContentObject (#31544)
1 parent 629c376 commit 8b698f0

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2929
import org.elasticsearch.common.xcontent.ObjectParser;
3030
import org.elasticsearch.common.xcontent.ToXContentFragment;
31+
import org.elasticsearch.common.xcontent.ToXContentObject;
3132
import org.elasticsearch.common.xcontent.XContentBuilder;
3233
import org.elasticsearch.common.xcontent.XContentHelper;
3334
import org.elasticsearch.common.xcontent.XContentParser;
@@ -47,7 +48,7 @@
4748
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
4849

4950
/** Response object for {@link GetFieldMappingsRequest} API */
50-
public class GetFieldMappingsResponse extends ActionResponse implements ToXContentFragment {
51+
public class GetFieldMappingsResponse extends ActionResponse implements ToXContentObject {
5152

5253
private static final ParseField MAPPINGS = new ParseField("mappings");
5354

@@ -111,6 +112,7 @@ public FieldMappingMetaData fieldMappings(String index, String type, String fiel
111112

112113
@Override
113114
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
115+
builder.startObject();
114116
for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
115117
builder.startObject(indexEntry.getKey());
116118
builder.startObject(MAPPINGS.getPreferredName());
@@ -126,6 +128,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
126128
builder.endObject();
127129
builder.endObject();
128130
}
131+
builder.endObject();
129132
return builder;
130133
}
131134

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBui
8181
if (mappingsByIndex.isEmpty() && fields.length > 0) {
8282
status = NOT_FOUND;
8383
}
84-
builder.startObject();
8584
response.toXContent(builder, request);
86-
builder.endObject();
8785
return new BytesRestResponse(status, builder);
8886
}
8987
});

server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public void testSimpleGetFieldMappingsWithPretty() throws Exception {
149149
params.put("pretty", "true");
150150
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
151151
XContentBuilder responseBuilder = XContentFactory.jsonBuilder().prettyPrint();
152-
responseBuilder.startObject();
153152
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
154-
responseBuilder.endObject();
155153
String responseStrings = Strings.toString(responseBuilder);
156154

157155

@@ -163,9 +161,7 @@ public void testSimpleGetFieldMappingsWithPretty() throws Exception {
163161

164162
response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
165163
responseBuilder = XContentFactory.jsonBuilder().prettyPrint().lfAtEnd();
166-
responseBuilder.startObject();
167164
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
168-
responseBuilder.endObject();
169165
responseStrings = Strings.toString(responseBuilder);
170166

171167
prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();

0 commit comments

Comments
 (0)