Merge pull request #11790 from jbarthelmes/master
Add a null-check for XContentBuilder#field for BigDecimals
This commit is contained in:
commit
7cf3096c3c
|
@ -500,28 +500,36 @@ 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 (toDouble) {
|
||||
try {
|
||||
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
|
||||
} catch (ArithmeticException e) {
|
||||
if (value == null) {
|
||||
generator.writeNull();
|
||||
} else {
|
||||
if (toDouble) {
|
||||
try {
|
||||
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
|
||||
} catch (ArithmeticException e) {
|
||||
generator.writeString(value.toEngineeringString());
|
||||
}
|
||||
} else {
|
||||
generator.writeString(value.toEngineeringString());
|
||||
}
|
||||
} 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 (toDouble) {
|
||||
try {
|
||||
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
|
||||
} catch (ArithmeticException e) {
|
||||
if (value == null) {
|
||||
generator.writeNull();
|
||||
} else {
|
||||
if (toDouble) {
|
||||
try {
|
||||
generator.writeNumber(value.setScale(scale, rounding).doubleValue());
|
||||
} catch (ArithmeticException e) {
|
||||
generator.writeString(value.toEngineeringString());
|
||||
}
|
||||
} else {
|
||||
generator.writeString(value.toEngineeringString());
|
||||
}
|
||||
} else {
|
||||
generator.writeString(value.toEngineeringString());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue