Skip to content

Commit 810e069

Browse files
committed
FieldError uses HexFormat to format byte[]
See gh-35675
1 parent 62f42ca commit 810e069

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.springframework.lang.Nullable;
2022
import org.springframework.util.Assert;
2123
import org.springframework.util.ObjectUtils;
@@ -126,8 +128,18 @@ public String toString() {
126128
// We would preferably use ObjectUtils.nullSafeConciseToString(rejectedValue) here but
127129
// keep including the full nullSafeToString representation for backwards compatibility.
128130
return "Field error in object '" + getObjectName() + "' on field '" + this.field +
129-
"': rejected value [" + ObjectUtils.nullSafeToString(this.rejectedValue) + "]; " +
131+
"': rejected value [" + formatRejectedValue() + "]; " +
130132
resolvableToString();
131133
}
132134

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

0 commit comments

Comments
 (0)