src/Services/UserService.php
/**
     * Method for creating user with validation and deserializer
     *
     * @param string $data JSON request data
     *
     * @return User
     * @throws ValidationException
     */
Method for creating user with validation and deserializer
@param string $data JSON request data

@return User
@throws ValidationException
Method for creating user with validation and deserializer @param string $data JSON request data @return User @throws ValidationException
public function createUser(string $data): User
    {
        $data = json_decode($data, true);
        $violations = $this->validator->validate(
            $data,
            UserRestConstraint::getPostMethodConstraint()
        );
        if ($violations->count() !== 0) {
            throw new ValidationException($violations);
        }
        $user = $this->serializer->denormalize(
            $data,
            User::class,
            'json'
        );
        $this->entityManager->persist($user);
        $this->entityManager->flush($user);
        return $user;
    }
public function createUser ( string $ data ) : User { $ data = json_decode ( $ data , true ) ; $ violations = $ this -> validator -> validate ( $ data , UserRestConstraint :: getPostMethodConstraint ( ) ) ; if ( $ violations -> count ( ) !== 0 ) { throw new ValidationException ( $ violations ) ; } $ user = $ this -> serializer -> denormalize ( $ data , User :: class , 'json' ) ; $ this -> entityManager -> persist ( $ user ) ; $ this -> entityManager -> flush ( $ user ) ; return $ user ; }
Method for creating user with validation and deserializer
 @param string $data JSON request data
Method for creating user with validation and deserializer @param string $data JSON request data
/** @var User $user */