Commit 1b88b8b
committed
feature #38361 Can define ChatMessage transport to null (odolbeau)
This PR was submitted for the 5.1 branch but it was merged into the 5.2-dev branch instead.
Discussion
----------
Can define ChatMessage transport to null
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
I'm using notiier & messenger together to send notification asynchronously.
In order to have json messages in my broker, here is the messenger config I use:
```yaml
serializer:
default_serializer: messenger.transport.symfony_serializer
symfony_serializer:
format: json
context: { }
```
I send a new `ChatMessage`:
```php
use Symfony\Component\Notifier\ChatterInterface;
use Symfony\Component\Notifier\Message\ChatMessage;
$chatter->send(new ChatMessage('Using notifier & messenger together is amazing!');
```
Message is correctly sent to my broker, in json:
```json
{
"subject": "Using notifier & messenger together is amazing!",
"recipientId": null,
"options": null,
"transport": null,
"notification": null
}
```
But when I want to consume it, as the `transport` method used by the serializer to create the `ChatMessage` doesn't accept `null` value, I get the following error:
```
[Symfony\Component\Messenger\Exception\MessageDecodingFailedException]
Could not decode message: Failed to denormalize attribute "transport" value for class "Symfony\Component\Notifier\Message\ChatMessage": Expected argument of type "string", "null" given at property path "transport".
```
This PR correct the problem, even if I'm not sure it's the best way to go...
Commits
-------
09c9bde Can define ChatMessage transport to null1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
0 commit comments