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

Overriding a primitive converter (UUID) #119

Open
mplokita-figure opened this issue Nov 26, 2021 · 5 comments
Open

Overriding a primitive converter (UUID) #119

mplokita-figure opened this issue Nov 26, 2021 · 5 comments

Comments

@mplokita-figure
Copy link

I'm hoping to override the default behavior of zeroing an invalid UUID string. (For example, I might prefer to throw an exception or return null.)

Does this constitute a new feature request?

primitive {
    try {
        UUID.fromString(it)
    } catch (e: IllegalArgumentException) {
        null
    } ?: UUID(0, 0)
}
@Wicpar
Copy link
Collaborator

Wicpar commented Nov 30, 2021

you can use a nullable uuid parameter, it uses 0 as a default if you don't allow it to be null.

@mplokita-figure
Copy link
Author

@Wicpar Won't that affect the API spec? If we would like to communicate to readers of the spec that the UUID is not optional, then is there an alternative solution?

@Wicpar
Copy link
Collaborator

Wicpar commented Dec 2, 2021

You are right, there is no way to throw an error doing that, the correct implementation would be to remove the try-catch and have an exception handler catch and build a proper error response

@aphu-figure
Copy link
Contributor

@Wicpar As far as overriding default converter behavior, I'm assuming this is still a viable solution? Any plans to incorporate this?

#82 (comment)

@Wicpar
Copy link
Collaborator

Wicpar commented Feb 27, 2022

I'll accept the PR if you make one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants