Skip to content

Commit af86b30

Browse files
committed
Merge branch '6.2.x'
2 parents c42020e + 810e069 commit af86b30

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

spring-context/src/main/java/org/springframework/validation/FieldError.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.validation;
1818

19+
import java.util.HexFormat;
20+
1921
import org.jspecify.annotations.Nullable;
2022

2123
import org.springframework.util.Assert;
@@ -125,8 +127,18 @@ public String toString() {
125127
// We would preferably use ObjectUtils.nullSafeConciseToString(rejectedValue) here but
126128
// keep including the full nullSafeToString representation for backwards compatibility.
127129
return "Field error in object '" + getObjectName() + "' on field '" + this.field +
128-
"': rejected value [" + ObjectUtils.nullSafeToString(this.rejectedValue) + "]; " +
130+
"': rejected value [" + formatRejectedValue() + "]; " +
129131
resolvableToString();
130132
}
131133

134+
private String formatRejectedValue() {
135+
136+
// Special handling of byte[], to be moved into ObjectUtils in 7.0
137+
if (this.rejectedValue instanceof byte[] bytes && bytes.length != 0) {
138+
return "{" + HexFormat.of().formatHex(bytes) + "}";
139+
}
140+
141+
return ObjectUtils.nullSafeToString(this.rejectedValue);
142+
}
143+
132144
}

0 commit comments

Comments
 (0)