Repository navigation
fix(#641): trim member full name before persistence - #798
IrynaLypnyk wants to merge 5 commits into
Conversation
|
|
@IrynaLypnyk I am going to hold this off for a couple more days. I am going to collate all the fields that require this fix and send them to you. As a follow-up, we also need a script to fix this in the backend. I will assign this to myself for now, I will add more info and assign back to you. |
| UPDATE_SQL, | ||
| member.getFullName(), | ||
| StringUtils.trim(member.getFullName()), | ||
| member.getSlackDisplayName(), |
There was a problem hiding this comment.
Instead of adding this "StringUtils.trim()" this should be handled at the time of deserialization. And then for the fields we do not need the Trim can have custom annotation say - NoTrim can be used if we do not want to strip the leading/trailing spaces.
| member.getSlackDisplayName(), | |
| 1. An opt-out annotation | |
| package com.wcc.platform.deserializers; | |
| /** Marks a String property that must be deserialized as-is, without trimming (e.g. passwords). */ | |
| @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) | |
| @Retention(RetentionPolicy.RUNTIME) | |
| public @interface NoTrim {} | |
| 2. A trimming String deserializer | |
| package com.wcc.platform.deserializers; | |
| /** | |
| * Strips leading and trailing whitespace from every JSON string value, unless the target | |
| * property is annotated with {@link NoTrim}. | |
| */ | |
| public class TrimmingStringDeserializer extends StdScalarDeserializer<String> | |
| implements ContextualDeserializer { | |
| public TrimmingStringDeserializer() { | |
| super(String.class); | |
| } | |
| @Override | |
| public String deserialize(final JsonParser parser, final DeserializationContext context) | |
| throws IOException { | |
| final String value = StringDeserializer.instance.deserialize(parser, context); | |
| return value == null ? null : value.strip(); | |
| } | |
| @Override | |
| public JsonDeserializer<?> createContextual( | |
| final DeserializationContext context, final BeanProperty property) { | |
| if (property != null && property.getAnnotation(NoTrim.class) != null) { | |
| return StringDeserializer.instance; | |
| } | |
| return this; | |
| } | |
| } | |
| It uses strip() rather than trim() because strip() also removes Unicode whitespace, such as a non-breaking space pasted from a document. | |
| 3. Register it once in ObjectMapperConfig | |
| new SimpleModule() | |
| .addDeserializer(String.class, new TrimmingStringDeserializer()) | |
| // ...existing serializers/deserializers | |
| 4. Opt out where needed | |
| public record LoginRequest(@NotBlank String email, @NoTrim @NotBlank String password) {} | |
| After this, fullName, email, city and every other string, including items inside List<String>, arrive already trimmed. The mappers don't need to do anything, and @NotBlank checks the trimmed value. | |
| Eg - | |
| - Password fields need @NoTrim. They're in AuthController (login), PasswordResetService request types, and SeedUser. Each one missed would silently change what the user typed. | |
There was a problem hiding this comment.
Hi @Sowmiya07 and @goelsonali
@Sowmiya07, you mentioned collecting the other fields that need trimming. @goelsonali, you suggested a global trimming deserializer.
That approach would trim JSON string values across the API, with explicit opt-outs for passwords and other whitespace-sensitive fields, so it broadens the scope beyond member names.
Could you confirm whether you’d prefer to keep this PR focused on member fields and introduce the global deserializer in a follow-up, or include it here?
In the meantime, I’ve addressed Slack display name trimming and validation in the admin form.
|



Description
Trims leading and trailing whitespace from member full names before saving them to the database.
The fix is applied at the shared member persistence layer, so it covers Member, Mentor, and Mentee create/update flows.
The admin member create form was also updated to trim
fullNamebefore submission and to reject whitespace-only names.Related Issue
Fixes #641
Change Type
Screenshots
Not applicable — no visual UI changes.
Pull request checklist
Please check if your PR fulfills the following requirements: