This adds asserts that will catch the case where we accidentally provide the same raw and readable field name in xcontent.
This commit is contained in:
parent
4307b1d607
commit
dd99125193
|
@ -725,6 +725,8 @@ public final class XContentBuilder implements Closeable, Flushable {
|
|||
* {@link Long} class.
|
||||
*/
|
||||
public XContentBuilder timeField(String name, String readableName, long value) throws IOException {
|
||||
assert name.equals(readableName) == false :
|
||||
"expected raw and readable field names to differ, but they were both: " + name;
|
||||
if (humanReadable) {
|
||||
Function<Object, Object> longTransformer = DATE_TRANSFORMERS.get(Long.class);
|
||||
if (longTransformer == null) {
|
||||
|
@ -937,6 +939,8 @@ public final class XContentBuilder implements Closeable, Flushable {
|
|||
//////////////////////////////////
|
||||
|
||||
public XContentBuilder humanReadableField(String rawFieldName, String readableFieldName, Object value) throws IOException {
|
||||
assert rawFieldName.equals(readableFieldName) == false :
|
||||
"expected raw and readable field names to differ, but they were both: " + rawFieldName;
|
||||
if (humanReadable) {
|
||||
field(readableFieldName, Objects.toString(value));
|
||||
}
|
||||
|
@ -956,6 +960,8 @@ public final class XContentBuilder implements Closeable, Flushable {
|
|||
|
||||
|
||||
public XContentBuilder percentageField(String rawFieldName, String readableFieldName, double percentage) throws IOException {
|
||||
assert rawFieldName.equals(readableFieldName) == false :
|
||||
"expected raw and readable field names to differ, but they were both: " + rawFieldName;
|
||||
if (humanReadable) {
|
||||
field(readableFieldName, String.format(Locale.ROOT, "%1.1f%%", percentage));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue