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

Serialization to json - Namespaces are not escaped #489

Closed
kosa03 opened this issue Mar 11, 2024 · 1 comment · Fixed by #490
Closed

Serialization to json - Namespaces are not escaped #489

kosa03 opened this issue Mar 11, 2024 · 1 comment · Fixed by #490

Comments

@kosa03
Copy link

kosa03 commented Mar 11, 2024

Hello ;)

I have a problem with serializing object namespaces (FQCN). Code below shows this situation:

Serilized objects:

final class CheckProduct
{
    public function __construct(
        public string $name,
        public string $class,
    ) {
    }
}

final class Strawberry
{
}

Test:

    #[Test]
    public function can_serialize_object_with_class_namespace(): void
    {
        // given
        $normalizer = (new \CuyZ\Valinor\MapperBuilder())
            ->normalizer(\CuyZ\Valinor\Normalizer\Format::json());
        // and
        $object = new CheckProduct('strawberry', Strawberry::class);

        // when
        $json = $normalizer->normalize($object);

        // then
        self::assertEquals(json_encode($object), $json);
    }

// output of $json variable

{"name":"strawberry","class":"Test\Unit\Strawberry"}

It's not a valid json, because backslashes are not escaped. It should be like this:

{"name":"strawberry","class":"Test\\Unit\\Strawberry"}

Is it a bug or did I forgot something?

@romm
Copy link
Member

romm commented Mar 12, 2024

Hey there, thanks for the report! It should have been fixed with #490. 😉

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

Successfully merging a pull request may close this issue.

2 participants