-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
[WIP] Allow deserializing null #1005
base: master
Are you sure you want to change the base?
Conversation
22b1d4f
to
3dbeb21
Compare
The main trick here are the interaction between the changes in the graph navigator and the visitor |
@@ -151,7 +156,7 @@ protected function setUp() | |||
$this->serializationNavigator->initialize($this->serializationVisitor, $this->context); | |||
|
|||
$this->deserializationNavigator = new DeserializationGraphNavigator($this->metadataFactory, $this->handlerRegistry, $this->objectConstructor, $this->accessor, $this->dispatcher); | |||
$this->deserializationNavigator->initialize($this->deserializationVisitor, $this->context); | |||
$this->deserializationNavigator->initialize($this->deserializationVisitor, $this->deserializeContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was just a typo in the previous test
@@ -726,14 +746,14 @@ public function testDeserializingNull() | |||
self::assertEquals($this->getContent('blog_post_unauthored'), $this->serialize($post, SerializationContext::create()->setSerializeNull(true))); | |||
|
|||
if ($this->hasDeserializer()) { | |||
$deserialized = $this->deserialize($this->getContent('blog_post_unauthored'), get_class($post), DeserializationContext::create()->setSerializeNull(true)); | |||
$deserialized = $this->deserialize($this->getContent('blog_post_unauthored'), get_class($post)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo. DeserializationContext::setSerializeNull
has no effect when doing deserialization
|
||
self::assertEquals('2011-07-30T00:00:00+00:00', $this->getField($deserialized, 'createdAt')->format(\DateTime::ATOM)); | ||
self::assertAttributeEquals('This is a nice title.', 'title', $deserialized); | ||
self::assertAttributeSame(false, 'published', $deserialized); | ||
self::assertAttributeSame(false, 'reviewed', $deserialized); | ||
self::assertAttributeEquals(new ArrayCollection(), 'comments', $deserialized); | ||
self::assertEquals(null, $this->getField($deserialized, 'author')); | ||
self::assertEquals($author, $this->getField($deserialized, 'author')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the BC break. Not sure even if the current behavior makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this even happening if deserialize null is false
@@ -197,7 +214,10 @@ public function accept($data, ?array $type = null) | |||
$this->context->pushPropertyMetadata($propertyMetadata); | |||
try { | |||
$v = $this->visitor->visitProperty($propertyMetadata, $data); | |||
$this->accessor->setValue($object, $v, $propertyMetadata, $this->context); | |||
|
|||
if (null !== $v || true === $this->shouldDeserializeNull) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so here is where you prevent it instead of doing in the visitor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is breaking the tests and now that I think about it, it is not needed at all. Without it, tests pass.
3dbeb21
to
110bebf
Compare
@@ -726,14 +746,15 @@ public function testDeserializingNull() | |||
self::assertEquals($this->getContent('blog_post_unauthored'), $this->serialize($post, SerializationContext::create()->setSerializeNull(true))); | |||
|
|||
if ($this->hasDeserializer()) { | |||
$deserialized = $this->deserialize($this->getContent('blog_post_unauthored'), get_class($post), DeserializationContext::create()); | |||
$ctx = DeserializationContext::create() | |||
$deserialized = $this->deserialize($this->getContent('blog_post_unauthored'), get_class($post), $ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change looks like it isn't needed
The only problem I see with this that it will make all fields in the request deserialize null, not sure if that is a good thing. |
4008e9f
to
9efa114
Compare
@kunicmarko20 I've found some time to work on this. Something as: class BlogPost
{
/**
* @Type("?string")
*/
private $id = 'what_a_nice_id';
/**
* @Type("?DateTime")
*/
private $createdAt;
/**
* @Type("?array<JMS\Serializer\Tests\Fixtures\Comment>")
*/
private $comments2;
/**
* @Type("array<string,?string>")
*/
private $metadata;
} When |
9efa114
to
01a91f3
Compare
Well, this looks amazing. Now you can choose to deserialize null for everything or per prop? |
If |
ah, so you need to enable it and then select which properties this works on? |
yes. main reason backward compatibility. Thinking it twice, having just trying to understand if there might have other implications... |
Ye, it looks like |
No, the |
What could be an issue or a problem with merging this? Also the target doesn't have to be master anymore |
What do you mean? |
Well, it is not a BC break, so no need to merge it on master? (assuming master is next major and not minor?) |
The master branch is targeting 3.1 and not 4.x. There are not yet any plans for a new major, so I'm keeping one branch less to manage |
My bad, then we just wait. 😄 |
01a91f3
to
20eb38d
Compare
20eb38d
to
b5f5ba2
Compare
I would guess some time is passed now :) |
Any plans to release this? |
Alternative implementation of #1004