Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend tryConvert method for catching mapping exceptions #204

Closed
PfeiJit opened this issue Apr 2, 2024 · 0 comments · Fixed by #216
Closed

Extend tryConvert method for catching mapping exceptions #204

PfeiJit opened this issue Apr 2, 2024 · 0 comments · Fixed by #216
Labels
enhancement New feature or request

Comments

@PfeiJit
Copy link
Contributor

PfeiJit commented Apr 2, 2024

Is your feature request related to a problem? Please describe.
When mapping from source with a nullable variable to a target with a corresponding non-nullable variable by tryConvert method, an exception is thrown. tryConvert should work in the same way as int.parse, so that each time there is any problem with parsing, a null is returned.

Describe the solution you'd like
Extend tryConvert method so that it catches all exceptions thrown during mapping (for example mapping a nullable variable to a non-nullable one). If any exception occurs, tryConvert returns null instead of throwing an exception. This behaviour is enabled by setting parameter safeMapping to true. By default safeMapping is false to keep backwards compatibility.

In addition, introduce optional parameter VoidCallback? onMappingError to tryConvert method that is called when exception during mapping occurs (can be used for example for logging).

Modify tryConvertList, convertIterable and convertSet accordingly.

@PfeiJit PfeiJit added the enhancement New feature or request label Apr 2, 2024
@PfeiJit PfeiJit closed this as completed May 14, 2024
@PfeiJit PfeiJit linked a pull request May 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant