Merge pull request #11790 from jbarthelmes/master

Add a null-check for XContentBuilder#field for BigDecimals
This commit is contained in:
Adrien Grand 2015-06-25 09:45:28 +02:00
commit 7cf3096c3c
1 changed files with 20 additions and 12 deletions

View File

@ -500,6 +500,9 @@ public final class XContentBuilder implements BytesStream, Releasable {
public XContentBuilder field(String name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException {
field(name);
if (value == null) {
generator.writeNull();
} else {
if (toDouble) {
try {
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
@ -509,11 +512,15 @@ public final class XContentBuilder implements BytesStream, Releasable {
} else {
generator.writeString(value.toEngineeringString());
}
}
return this;
}
public XContentBuilder field(XContentBuilderString name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException {
field(name);
if (value == null) {
generator.writeNull();
} else {
if (toDouble) {
try {
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
@ -523,6 +530,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
} else {
generator.writeString(value.toEngineeringString());
}
}
return this;
}