Skip to content

Add nullSafeConverter method to Converter interface#23946

Draft
peholmst wants to merge 1 commit intomainfrom
null-safe-converter
Draft

Add nullSafeConverter method to Converter interface#23946
peholmst wants to merge 1 commit intomainfrom
null-safe-converter

Conversation

@peholmst
Copy link
Member

Description

When writing converters, there are already methods provided for using mapper functions that map between the model and presentation values. This is useful, but these functions, like LocalDate::parse or LocalDate::toString always assume a non-null input. Since converters work with both null inputs and outputs, you virtually always have to write your own custom validators to handle nulls.

This helper function allows you to write converters like this:

Converter<String, LocalDate> converter = Converter.nullSafeConverter(
    Converter.from(LocalDate::parse, LocalDate::toString, Exception::getMessage)
);

Type of change

  • Bugfix
  • Feature

@peholmst peholmst marked this pull request as ready for review March 19, 2026 07:39
@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

 1 389 files  + 58   1 389 suites  +58   1h 25m 42s ⏱️ +21s
 9 935 tests +667   9 864 ✅ +668  71 💤 ±0  0 ❌  - 1 
10 408 runs  +667  10 328 ✅ +668  80 💤 ±0  0 ❌  - 1 

Results for commit 940caa8. ± Comparison against base commit e1dd8c3.

@peholmst peholmst marked this pull request as draft March 19, 2026 12:38
@peholmst
Copy link
Member Author

Converting back to draft. This needs some more work with regards to empty values. For some fields, the empty value is not null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant