From 31d226188f75ac12affd336ec227da462c1137ce Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 8 May 2010 00:01:36 +0300 Subject: [PATCH] REST API: Allow to provide `case` parameter, with `camelCase` to return results in CamelCasing, closes #162. --- .../rest/action/support/RestXContentBuilder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java index 494dd06b5f4..7000435296d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java @@ -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; } }