IOException when returning nested arrays. See: https://gist.github.com/2006593

This commit is contained in:
Barnaby Gray 2012-03-09 13:52:00 +00:00 committed by Shay Banon
parent 1ed07a0c50
commit 0badf3d92a
1 changed files with 14 additions and 0 deletions

View File

@ -742,6 +742,8 @@ public final class XContentBuilder {
} else if (value instanceof Map) { } else if (value instanceof Map) {
//noinspection unchecked //noinspection unchecked
value((Map<String, Object>) value); value((Map<String, Object>) value);
} else if (value instanceof Iterable) {
value((Iterable) value);
} else { } else {
throw new IOException("Type not allowed [" + type + "]"); throw new IOException("Type not allowed [" + type + "]");
} }
@ -965,6 +967,18 @@ public final class XContentBuilder {
return this; 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 { public XContentBuilder copyCurrentStructure(XContentParser parser) throws IOException {
generator.copyCurrentStructure(parser); generator.copyCurrentStructure(parser);
return this; return this;