1
0
Эх сурвалжийг харах

turn GetFieldMappingsResponse to ToXContentObject (#31544)

Vladimir Dolzhenko 7 жил өмнө
parent
commit
8b698f0bce

+ 4 - 1
server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

@@ -28,6 +28,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ConstructingObjectParser;
 import org.elasticsearch.common.xcontent.ObjectParser;
 import org.elasticsearch.common.xcontent.ToXContentFragment;
+import org.elasticsearch.common.xcontent.ToXContentObject;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentHelper;
 import org.elasticsearch.common.xcontent.XContentParser;
@@ -47,7 +48,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
 
 /** Response object for {@link GetFieldMappingsRequest} API */
-public class GetFieldMappingsResponse extends ActionResponse implements ToXContentFragment {
+public class GetFieldMappingsResponse extends ActionResponse implements ToXContentObject {
 
     private static final ParseField MAPPINGS = new ParseField("mappings");
 
@@ -111,6 +112,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
 
     @Override
     public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
+        builder.startObject();
         for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
             builder.startObject(indexEntry.getKey());
             builder.startObject(MAPPINGS.getPreferredName());
@@ -126,6 +128,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
             builder.endObject();
             builder.endObject();
         }
+        builder.endObject();
         return builder;
     }
 

+ 0 - 2
server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java

@@ -81,9 +81,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
                         if (mappingsByIndex.isEmpty() && fields.length > 0) {
                             status = NOT_FOUND;
                         }
-                        builder.startObject();
                         response.toXContent(builder, request);
-                        builder.endObject();
                         return new BytesRestResponse(status, builder);
                     }
                 });

+ 0 - 4
server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java

@@ -149,9 +149,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
         params.put("pretty", "true");
         GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
         XContentBuilder responseBuilder = XContentFactory.jsonBuilder().prettyPrint();
-        responseBuilder.startObject();
         response.toXContent(responseBuilder, new ToXContent.MapParams(params));
-        responseBuilder.endObject();
         String responseStrings = Strings.toString(responseBuilder);
 
 
@@ -163,9 +161,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
 
         response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
         responseBuilder = XContentFactory.jsonBuilder().prettyPrint().lfAtEnd();
-        responseBuilder.startObject();
         response.toXContent(responseBuilder, new ToXContent.MapParams(params));
-        responseBuilder.endObject();
         responseStrings = Strings.toString(responseBuilder);
 
         prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();