From 0badf3d92a4f431e140e8f6abbac904ea70507c5 Mon Sep 17 00:00:00 2001 From: Barnaby Gray Date: Fri, 9 Mar 2012 13:52:00 +0000 Subject: [PATCH] IOException when returning nested arrays. See: https://gist.github.com/2006593 --- .../common/xcontent/XContentBuilder.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index cf3d32a706c..6ba6c30c26f 100644 --- a/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -742,6 +742,8 @@ public final class XContentBuilder { } else if (value instanceof Map) { //noinspection unchecked value((Map) value); + } else if (value instanceof Iterable) { + value((Iterable) value); } else { throw new IOException("Type not allowed [" + type + "]"); } @@ -965,6 +967,18 @@ public final class XContentBuilder { return this; } + public XContentBuilder value(Iterable value) throws IOException { + if (value == null) { + return nullValue(); + } + startArray(); + for (Object o : value) { + value(o); + } + endArray(); + return this; + } + public XContentBuilder copyCurrentStructure(XContentParser parser) throws IOException { generator.copyCurrentStructure(parser); return this;