Merge pull request #11790 from jbarthelmes/master
Add a null-check for XContentBuilder#field for BigDecimals
This commit is contained in:
commit
7cf3096c3c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue