Skip to content

Introduce ObjectUtils.nullSafeConciseToString() #30286

Closed
@sbrannen

Description

@sbrannen

Overview

org.springframework.util.ObjectUtils.nullSafeToString(Object) exists for generating a toString() representation of various objects in a "null-safe" manner, including support for object graphs, collections, etc.

However, there are times when we would like to generate a more "concise" null-safe toString() representation that does not include an entire object graph (or potentially a collection of object graphs).

org.springframework.beans.BeanUtils.isSimpleValueType(Class<?>) already provides a check for an opinionated list of "simple types"; however, that resides in spring-beans and therefore cannot be used in spring-core.

We should introduce ObjectUtils.nullSafeConciseToString(Object) that generates a concise, null-safe string representation of the supplied object relying on logic similar to BeanUtils.isSimpleValueType() to decide when to use the standard toString() implementation for the supplied object and when to replace the standard implementation with a more concise format -- for example, something along the lines of what Object#toString generates instead of including the toString() representation of an entire object graph recursively.

Deliverables

  • Introduce nullSafeConciseToString(Object) in ObjectUtils

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions