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

AnnotationException when trying to use type #25

Open
angekouf opened this issue Mar 3, 2018 · 0 comments
Open

AnnotationException when trying to use type #25

angekouf opened this issue Mar 3, 2018 · 0 comments

Comments

@angekouf
Copy link

angekouf commented Mar 3, 2018

I am trying to follow the example in the docs but I get an annotation error.

Example user class

use Ivory\Serializer\Mapping\Annotation as Serializer;

class User
{
	/**
	 * @Serializer\Type("string")
	 *
	 * @var string
	 */
	public $username;
	
	public function __construct(string $username) {
		$this->username = $username;
	}
}

Using serializer to serialize object to json

$obj = new User('testing');
var_dump($obj);

$serializer = new \Ivory\Serializer\Serializer();

$json = $serializer->serialize($obj, \Ivory\Serializer\Format::JSON);

var_dump($json);

It throws following error

AnnotationException in AnnotationException.php line 54: [Semantical Error] The annotation "@ivory\Serializer\Mapping\Annotation\Type" in property User::$username does not exist, or could not be auto-loaded.

What am I doing wrong?

In the end I want to use custom classes instead of string but it is not working even for string

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

1 participant