Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert FieldCapabilitiesResponse to a ToXContentObject. #30182

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
Expand All @@ -41,7 +41,7 @@
/**
* Response for {@link FieldCapabilitiesRequest} requests.
*/
public class FieldCapabilitiesResponse extends ActionResponse implements ToXContentFragment {
public class FieldCapabilitiesResponse extends ActionResponse implements ToXContentObject {
private static final ParseField FIELDS_FIELD = new ParseField("fields");

private Map<String, Map<String, FieldCapabilities>> responseMap;
Expand Down Expand Up @@ -123,8 +123,9 @@ private static void writeField(StreamOutput out,

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(FIELDS_FIELD.getPreferredName(), responseMap);
return builder;
return builder.startObject()
.field(FIELDS_FIELD.getPreferredName(), responseMap)
.endObject();
}

public static FieldCapabilitiesResponse fromXContent(XContentParser parser) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request,
fieldRequest.indicesOptions(
IndicesOptions.fromRequest(request, fieldRequest.indicesOptions())
);
return channel -> client.fieldCaps(fieldRequest,
new RestBuilderListener<FieldCapabilitiesResponse>(channel) {
@Override
public RestResponse buildResponse(FieldCapabilitiesResponse response,
XContentBuilder builder) throws Exception {
RestStatus status = OK;
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
return new BytesRestResponse(status, builder);
}
});
return channel -> client.fieldCaps(fieldRequest, new RestToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ protected Predicate<String> getRandomFieldsExcludeFilter() {
public void testToXContent() throws IOException {
FieldCapabilitiesResponse response = createSimpleResponse();

XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)
.startObject();
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();

String generatedResponse = BytesReference.bytes(builder).utf8ToString();
assertEquals((
Expand Down