REST API: Allow to provide `case` parameter, with `camelCase` to return results in CamelCasing, closes #162.

This commit is contained in:
kimchy 2010-05-08 00:01:36 +03:00
parent e222d38b84
commit 31d226188f
1 changed files with 9 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.util.xcontent.XContentFactory;
import org.elasticsearch.util.xcontent.XContentType;
import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException;
@ -47,6 +48,14 @@ public class RestXContentBuilder {
if (request.paramAsBoolean("pretty", false)) {
builder.prettyPrint();
}
String casing = request.param("case");
if (casing != null && "camelCase".equals(casing)) {
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
} else {
// we expect all REST interfaces to write results in underscore casing, so
// no need for double casing
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
}
return builder;
}
}