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

Allow disabling default Optional values in CreationContext #931

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ragulka
Copy link
Contributor

@ragulka ragulka commented Jan 15, 2025

DTOs that have properties using the Optional type can be a little painful to work with when creating the DTO in a context where you'd rather have a missing value be resolved to null. This can happen when preparing a DTO on the server-side, later to be converted to a JSON payload. For instance, when an Eloquent model is converted to array, it may not include all the keys for the DTO - which would result in Optional type being used for the matching properties.

This PR makes it possible to control whether the DefaultValuesPipeline will set properties that support the Optional type to Optional, or fall back to null (if allowed by the property).

See the docs diff for usage.

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

Successfully merging this pull request may close these issues.

1 participant