add special handling for primitive arrays as fields in xcontent builder

This commit is contained in:
kimchy 2010-09-21 01:41:35 +02:00
parent 2715212868
commit a68c00cd0d
1 changed files with 55 additions and 0 deletions

View File

@ -239,6 +239,51 @@ public final class XContentBuilder {
return this; 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 { public XContentBuilder field(String name, Object value) throws IOException {
if (value == null) { if (value == null) {
nullField(name); nullField(name);
@ -267,6 +312,16 @@ public final class XContentBuilder {
field(name, (Map<String, Object>) value); field(name, (Map<String, Object>) value);
} else if (value instanceof List) { } else if (value instanceof List) {
field(name, (List) value); 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 { } else {
field(name, value.toString()); field(name, value.toString());
} }