From a68c00cd0dd182cf90fb68304f75fe47816fccb2 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 21 Sep 2010 01:41:35 +0200 Subject: [PATCH] add special handling for primitive arrays as fields in xcontent builder --- .../common/xcontent/XContentBuilder.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index 10127cf0f98..c480fc03926 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -239,6 +239,51 @@ public final class XContentBuilder { return this; } + public XContentBuilder field(String name, Object... value) throws IOException { + startArray(name); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + + public XContentBuilder field(String name, int... value) throws IOException { + startArray(name); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + + public XContentBuilder field(String name, long... value) throws IOException { + startArray(name); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + + public XContentBuilder field(String name, float... value) throws IOException { + startArray(name); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + + public XContentBuilder field(String name, double... value) throws IOException { + startArray(name); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + public XContentBuilder field(String name, Object value) throws IOException { if (value == null) { nullField(name); @@ -267,6 +312,16 @@ public final class XContentBuilder { field(name, (Map) value); } else if (value instanceof List) { field(name, (List) value); + } else if (value instanceof Object[]) { + field(name, (Object[]) value); + } else if (value instanceof int[]) { + field(name, (int[]) value); + } else if (value instanceof long[]) { + field(name, (long[]) value); + } else if (value instanceof float[]) { + field(name, (float[]) value); + } else if (value instanceof double[]) { + field(name, (double[]) value); } else { field(name, value.toString()); }