Skip to content

[Serializer] Supports nested abstract items #27827

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

Merged
merged 1 commit into from
Jul 19, 2018

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Jul 3, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27816, #27641
License MIT
Doc PR ø

This adds support for nested "abstract" objects.

@voodoo-dn
Copy link

This PR works well and fix my problem, thanks.

@voodoo-dn voodoo-dn mentioned this pull request Jul 3, 2018
@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Jul 3, 2018
* Get the types for the given class and attribute.
*
* @param string $currentClass
* @param string $attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed, we don't duplicate the signature when not adding more than what it already tells.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure why I've done that 😄

* @param string $currentClass
* @param string $attribute
*
* @return null|Type[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type[]|null

}
}

return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, is it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo it's better to say "returning null" rather than not returning anything (void)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue it is worth being explicit as well.

Copy link
Contributor Author

@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated after review.

* Get the types for the given class and attribute.
*
* @param string $currentClass
* @param string $attribute
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure why I've done that 😄

}
}

return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue it is worth being explicit as well.

@sroze sroze force-pushed the supports-nested-abstract-items branch from 2f7230e to 43dc167 Compare July 4, 2018 07:10
fabpot
fabpot previously requested changes Jul 5, 2018
@@ -357,6 +357,20 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
throw new NotNormalizableValueException(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute, $currentClass, implode('", "', array_keys($expectedTypes)), gettype($data)));
}

/**
* Get the types for the given class and attribute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gets, but I think you can remove the description as it does not add anything that is not already part of the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough; removed!

@sroze sroze force-pushed the supports-nested-abstract-items branch from 43dc167 to dcb93b8 Compare July 5, 2018 10:59
@sroze
Copy link
Contributor Author

sroze commented Jul 8, 2018

@fabpot made the change you were asking for. Can you review again?

dunglas
dunglas previously requested changes Jul 9, 2018
/**
* @return Type[]|null
*/
protected function getTypes(string $currentClass, string $attribute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it @internal? The proliferation of public methods in this class make it very hard to maintain (we should split it in several classes/traits instead).

/**
* {@inheritdoc}
*/
protected function getTypes(string $currentClass, string $attribute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only in this subclass?

@nicolas-grekas
Copy link
Member

rebase needed

@sroze sroze force-pushed the supports-nested-abstract-items branch 2 times, most recently from 3c242a1 to e84e467 Compare July 12, 2018 08:09
@sroze sroze force-pushed the supports-nested-abstract-items branch from e84e467 to ec4b04b Compare July 12, 2018 08:11
@sroze
Copy link
Contributor Author

sroze commented Jul 12, 2018

Updated. No need to add a protected method in the end, it's all private 💃

Status: Needs Review

@sroze sroze dismissed dunglas’s stale review July 13, 2018 08:51

Changes made.

@fabpot
Copy link
Member

fabpot commented Jul 19, 2018

Thank you @sroze.

@fabpot fabpot merged commit ec4b04b into symfony:4.1 Jul 19, 2018
fabpot added a commit that referenced this pull request Jul 19, 2018
This PR was merged into the 4.1 branch.

Discussion
----------

[Serializer] Supports nested abstract items

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27816, #27641
| License       | MIT
| Doc PR        | ø

This adds support for nested "abstract" objects.

Commits
-------

ec4b04b Supports nested "abstract" object while serializing and de-serializing
@fabpot fabpot mentioned this pull request Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants