more explicit places where we don't want to conversion to happen when transforming to xcontent

This commit is contained in:
Shay Banon 2011-09-01 01:34:27 +03:00
parent b185078554
commit 3381d77c14
11 changed files with 63 additions and 16 deletions

View File

@ -164,7 +164,7 @@ public class IndicesStats extends BroadcastOperationResponse implements ToXConte
builder.startObject(Fields.INDICES);
for (IndexStats indexStats : indices().values()) {
builder.startObject(indexStats.index());
builder.startObject(indexStats.index(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("primaries");
indexStats.primaries().toXContent(builder, params);

View File

@ -146,6 +146,12 @@ public final class XContentBuilder {
return this;
}
public XContentBuilder startObject(XContentBuilderString name, FieldCaseConversion conversion) throws IOException {
field(name, conversion);
startObject();
return this;
}
public XContentBuilder startObject() throws IOException {
generator.writeStartObject();
return this;
@ -231,6 +237,17 @@ public final class XContentBuilder {
return this;
}
public XContentBuilder field(XContentBuilderString name, FieldCaseConversion conversion) throws IOException {
if (conversion == FieldCaseConversion.UNDERSCORE) {
generator.writeFieldName(name.underscore());
} else if (conversion == FieldCaseConversion.CAMELCASE) {
generator.writeFieldName(name.camelCase());
} else {
generator.writeFieldName(name.underscore());
}
return this;
}
public XContentBuilder field(String name) throws IOException {
if (fieldCaseConversion == FieldCaseConversion.UNDERSCORE) {
if (cachedStringBuilder == null) {
@ -293,6 +310,16 @@ public final class XContentBuilder {
return this;
}
public XContentBuilder field(String name, String value, FieldCaseConversion conversion) throws IOException {
field(name, conversion);
if (value == null) {
generator.writeNull();
} else {
generator.writeString(value);
}
return this;
}
public XContentBuilder field(XContentBuilderString name, String value) throws IOException {
field(name);
if (value == null) {
@ -303,6 +330,16 @@ public final class XContentBuilder {
return this;
}
public XContentBuilder field(XContentBuilderString name, String value, FieldCaseConversion conversion) throws IOException {
field(name, conversion);
if (value == null) {
generator.writeNull();
} else {
generator.writeString(value);
}
return this;
}
public XContentBuilder field(String name, Integer value) throws IOException {
field(name);
if (value == null) {

View File

@ -195,7 +195,7 @@ public class IndexingStats implements Streamable, ToXContent {
if (typeStats != null && !typeStats.isEmpty()) {
builder.startObject(Fields.TYPES);
for (Map.Entry<String, Stats> entry : typeStats.entrySet()) {
builder.startObject(entry.getKey());
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
entry.getValue().toXContent(builder, params);
builder.endObject();
}

View File

@ -73,7 +73,7 @@ public class RestNodesInfoAction extends BaseRestHandler {
for (NodeInfo nodeInfo : result) {
builder.startObject(nodeInfo.node().id(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("name", nodeInfo.node().name());
builder.field("name", nodeInfo.node().name(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("transport_address", nodeInfo.node().address().toString());
builder.startObject("attributes");

View File

@ -68,8 +68,8 @@ public class RestNodesShutdownAction extends BaseRestHandler {
builder.startObject("nodes");
for (DiscoveryNode node : response.nodes()) {
builder.startObject(node.id());
builder.field("name", node.name());
builder.startObject(node.id(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("name", node.name(), XContentBuilder.FieldCaseConversion.NONE);
builder.endObject();
}
builder.endObject();

View File

@ -65,7 +65,7 @@ public class RestNodesStatsAction extends BaseRestHandler {
for (NodeStats nodeStats : result) {
builder.startObject(nodeStats.node().id(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("name", nodeStats.node().name());
builder.field("name", nodeStats.node().name(), XContentBuilder.FieldCaseConversion.NONE);
if (nodeStats.indices() != null) {
nodeStats.indices().toXContent(builder, request);

View File

@ -31,14 +31,19 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentRestResponse;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestStatus.*;
import static org.elasticsearch.rest.action.support.RestActions.*;
/**
* @author imotov
@ -67,7 +72,7 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler {
builder.startObject();
for (IndexMetaData indexMetaData : metaData) {
builder.startObject(indexMetaData.index());
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("aliases");
for (AliasMetaData alias : indexMetaData.aliases().values()) {

View File

@ -109,7 +109,7 @@ public class RestGetMappingAction extends BaseRestHandler {
}
} else {
for (IndexMetaData indexMetaData : metaData) {
builder.startObject(indexMetaData.index());
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
if (!types.isEmpty() && !types.contains(mappingMd.type())) {

View File

@ -30,7 +30,12 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentRestResponse;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import java.io.IOException;
@ -68,7 +73,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
builder.startObject();
for (IndexMetaData indexMetaData : metaData) {
builder.startObject(indexMetaData.index());
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("settings");
Settings settings = settingsFilter.filterSettings(indexMetaData.settings());

View File

@ -100,7 +100,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
builder.startObject("_indices");
for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : result.indices().values()) {
builder.startObject(indexDeleteByQueryResponse.index());
builder.startObject(indexDeleteByQueryResponse.index(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("_shards");
builder.field("total", indexDeleteByQueryResponse.totalShards());

View File

@ -56,7 +56,7 @@ public class RestActions {
for (ShardOperationFailedException shardFailure : response.shardFailures()) {
builder.startObject();
if (shardFailure.index() != null) {
builder.field("index", shardFailure.index());
builder.field("index", shardFailure.index(), XContentBuilder.FieldCaseConversion.NONE);
}
if (shardFailure.shardId() != -1) {
builder.field("shard", shardFailure.shardId());