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

Document request - validation example #13

Open
thim81 opened this issue Jun 2, 2016 · 2 comments
Open

Document request - validation example #13

thim81 opened this issue Jun 2, 2016 · 2 comments

Comments

@thim81
Copy link

thim81 commented Jun 2, 2016

Hi Mathielen,

Can you provide a bit more documentation

  • how the validation works? "Source" is clear but the "target: ~" is not clear.
  • how we can add other validations ? Is there a list of validation options?
  • How can we add custom validations options?

Regards,
Tim

@mathielen
Copy link
Owner

mathielen commented Jun 6, 2016

The idea of having 2 different validation types is that you can validate the source data (an array straight from the storage) and the target data after mapping and deserialization has been done.

Having set

validation:
    target: true

and using an object-factory like:

object_factory:
    type: jms_serializer
    class: My\ValueObject\SomeValueObject

you could -for example- use annotation-driven validation:

use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;

class SomeValueObject
{

    /**
     * @Type("string")
     * @Assert\NotBlank
     */
    private $property;

@thim81
Copy link
Author

thim81 commented Jun 6, 2016

Thanks for the clarification.

So there are 2 ways to validate:

  • validate raw file data
  • validate data after mapping

To define a target, now it says "~" this means? The raw data or the mapped data?

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