like this :
Can you provide such a method
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull("abc") = "abc"
StringUtils.trimToNull(" abc ") = "abc"
org.apache.commons.lang3.StringUtils#trimToNull
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
public void setUsername(String username) {
this.username = StringUtils.trimToNull(username);
}
That's where more specific cases should be handled by yourself.
Myself I would prefer to use or just allow an empty string instead or even an optional of String. Why not even use the Option class from Vavr.
I hope you see my point. You have so much opinions in the java community it would be difficult or impossible to please everyone.
Believe or not this is a common case, would be great have the option of trim the string in the @Data or @Setter.
If this is a "common case" is more an individual point of perspective imo.
Personally I can't remember to have seen this before.
And this would only work for String arguments.
Therefore I would suggest more a specialized annotation like @StringSetter which could handle more string specific behaviour.
@StringSetter(trim=true, convertion=uppercase|lowercase|none, maxLength=positiveNumber|unset)
The @StringSetter option sounds amazing. About my point of view, you not always have the option to edit or optimize your data sources, and when the DB admin define the data as fixed char instead or varchar, and other similar cases, you need to do the setters at hand with the boilerplate code, or use reflections and the performance impoverishment of that. Your option make my life a lot easier.
May be having property for Setter (and @Data) like lombok.setter.trimString, default false will support as is, activated true as needed
Hi, is this ticket lost?
Most helpful comment
Believe or not this is a common case, would be great have the option of trim the string in the @Data or @Setter.