Is there any utility available to easily get the string representation of an arbitrary object if it exists and keep it null
if it was null
?
For example
String result = null;
if (object != null) {
result = object.toString();
}
but less verbose.
I have looked into ObjectUtils
and String.valueOf
but neither returns just null
itself. Both return default strings, i.e. the empty string or the string "null"
instead of just null
.