Rewrote SuggestResponse#toString method

It only prints out json now (as the SearchResponse does)
Added missing startObject & endObject (was causing JsonGenerationException)

Closes #3661
This commit is contained in:
Luca Cavanna 2013-09-10 22:31:51 +02:00
parent 0efa78710b
commit 0b79ba9493
1 changed files with 12 additions and 13 deletions

View File

@ -19,20 +19,19 @@
package org.elasticsearch.action.suggest;
import java.io.IOException;
import java.util.List;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.search.suggest.Suggest;
import java.io.IOException;
import java.util.List;
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
/**
* The response of the suggest action.
*/
@ -70,14 +69,14 @@ public final class SuggestResponse extends BroadcastOperationResponse {
@Override
public String toString() {
String source;
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
suggest.toXContent(builder, null);
source = XContentHelper.convertToJson(builder.bytes(), true);
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
suggest.toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
source = "Error: " + e.getMessage();
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
return "Suggest Response["+source+"]";
}
}