Skip to content

Allow serializing when property and method start from "is" #4125

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

Closed

Conversation

maks-rafalko
Copy link
Contributor

@maks-rafalko maks-rafalko commented Mar 9, 2021

Q A
Branch? 2.6
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Follow up for https://github.com/api-platform/core/pull/4064/files

In #4064, there was a fix for documentation generated on UI. But, unfortunately, when we use public function isActive() method and $isActive property, the value is not being serialized - it is not included in the response.

The reason is the same - $options array does not contain 'enable_getter_setter_extraction' => true default value.

I have some issues with the tests, probably you can help me with understanding what's going on, will comment below.

"@type": "DummyBoolean",
"id": 1,
"isDummyBoolean": true,
"dummyBoolean": true
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 have no idea where dummyBoolean serialized key/value comes from.

If I remove the fix ('enable_getter_setter_extraction' => true) - both isDummyBoolean and DummyBoolean are absent.

Is it something json-ld adds in addition to isDummyBoolean?

I can't reproduce it locally on 2.6.3 in our project (we use application/json)

Copy link
Member

Choose a reason for hiding this comment

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

I think it's more a normalizer issue and it should be fixed in Symfony itself.
I saw it too when debugging the previous PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I think I understand why I can't reproduce it locally - because we have a composer.lock and our serializer doesn't have this bug, while api-platform/core installs the latest versions

@@ -0,0 +1,30 @@
Feature: Serialization of boolean properties
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better in serializer?

@alanpoulain
Copy link
Member

The unit tests need to be fixed too.

@maks-rafalko maks-rafalko force-pushed the bugfix/is-properties branch 2 times, most recently from 90ea6bf to ef4731a Compare March 9, 2021 15:43
{
$this->isDummyBoolean = $isDummyBoolean;
}

Copy link
Member

Choose a reason for hiding this comment

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

we should avoid changing old tests

$options = [];
$options = [
/* @see https://github.com/symfony/symfony/blob/v5.1.0/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php */
'enable_getter_setter_extraction' => true,
Copy link
Member

Choose a reason for hiding this comment

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

wondering if this should be opt-in, does this break existing tests?

Copy link
Member

Choose a reason for hiding this comment

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

No it doesn't break existing tests. However it can be considered as a BC break.

@alanpoulain alanpoulain force-pushed the bugfix/is-properties branch from b8c4da4 to bb142f0 Compare March 17, 2021 10:27
@alanpoulain
Copy link
Member

I think this feature should probably target 2.7 and can be considered as a BC break.
For instance if you have an entity like this:

<?php

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ApiResource
 * @ORM\Entity
 */
class Test
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer", nullable=true)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $last;

    public function getId()
    {
        return $this->id;
    }

    public function last(): bool
    {
        return $this->last;
    }
}

Before it was not serialized and now it will be. WDYT @maks-rafalko @soyuka?

@alanpoulain
Copy link
Member

As @soyuka said we could make it opt-in too.
We should change what #4064 is doing too to reflect what we do here.

@soyuka soyuka added this to the 2.7 milestone May 26, 2021
@stale
Copy link

stale bot commented Nov 4, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 4, 2022
@maks-rafalko
Copy link
Contributor Author

@Stale

It still the issue, however I don't have time/energy to complete it. If someone can help, that would be awesome.

@stale stale bot removed the wontfix label Nov 6, 2022
@stale
Copy link

stale bot commented Jan 5, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 5, 2023
@stale stale bot closed this Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants