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

Specify Type as nullable? #1191

Closed
lukepass opened this issue Apr 23, 2020 · 4 comments
Closed

Specify Type as nullable? #1191

lukepass opened this issue Apr 23, 2020 · 4 comments

Comments

@lukepass
Copy link

Q A
Bug report? no
Feature request? maybe
BC Break report? no
RFC? no

Hello, how can i specify that a type (DateTime, in this case) is nullable?

Not working:

/**
 * @var null|\DateTime
 *
 * @JMS\Type("?DateTime")
 */
public $zipDate;

Not working:

/**
 * @var null|\DateTime
 *
 * @JMS\Type("null|\DateTime")
 */
public $zipDate;

Not working:

/**
 * @var null|\DateTime
 *
 * @JMS\Type("DateTime?")
 */
public $zipDate;

Thanks.

@goetas
Copy link
Collaborator

goetas commented Apr 24, 2020

I have already examined this feature and currently there is no use case for such feature in the serializer context.

When serializing, the object is already instantiated by other software(and hopefully valid), when de-serializing, it is not serializer responsibility to perform validation.

I'm closing this ticket. If you have a specific use case, I can re-open this.

@goetas goetas closed this as completed Apr 24, 2020
@lukepass
Copy link
Author

Hello @goetas,
I actually have a use case for this: I have an API which is consumed by a third-party mobile app.
One of my models has a DateTime property which can be null when there are no data. Unfortunately there is no way to express this right now and the app developer can't know that this field can be null.

It would be really useful to add a support for ? or add a nullable attribute to the @Type annotation.

Thanks.

@goetas
Copy link
Collaborator

goetas commented Apr 24, 2020

I understand the situation and I had similar issues but this behavior is just about documentation, I guess that there is no chage in behavior needed for that case for the serializer library.

Maybe this issue should be raised in the tool you use to generate the API documentation?

@lukepass
Copy link
Author

I am using NelmioApiDocBundle which reads the deserialization information from JMS (since I am using it in my project).

Thanks anyway!

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

2 participants