As Boa mentioned before we would need both a default to print out, and a boolean that tells whether the current value is default or not, as the `currentValue != defaultValue` is not enough. Something like the following should help in most cases I think?

```
public static void maybeAdd(XContentBuilder builder, String key, Object value, Object defValue, boolean isDefault, boolean includeDefault) {
        if (value != null || !isDefault) {
            builder.field(key, value);
        } else if (includeDefault) {
            builder.field(key, defValue);
        }
    }
```

That said, maybe it doesn't cover 100% but 90% of the cases, and for the 10% left we can still have the custom if? In my opinion it doesn't need to be perfect but still better than copy pasting that `if` so many times.