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

[Question]: Why #[SerializedName('is_kyc_completed')] is ignored when method name matches property? #2422

Open
darius-v opened this issue Jan 15, 2025 · 2 comments
Labels
question stale stale issue/PR

Comments

@darius-v
Copy link

darius-v commented Jan 15, 2025

Version

4.33.4

Question

#[SerializedName('is_kyc_completed')]
private bool $isKycCompleted = false;

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

    public function setIsKycCompleted(bool $isKycCompleted): void
    {
        $this->isKycCompleted = $isKycCompleted;
    }

$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
        $metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);

        $serializer = new Serializer(
            [
                new DateTimeNormalizer(),
                //new SellerSalesChannelNormalizer($this->normalizer),
                new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter)],
            ['json' => new JsonEncoder()]
        );

$serializer->serialize(
                $body,
                'json',
                [
                    AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
                    AbstractNormalizer::IGNORED_ATTRIBUTES => ['passwordHasherName'],
                    AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => function () {
                        return [];
                    },
                    //SellerSalesChannelNormalizer::KYC_COMPLETED_RENAME => true,
                ]
            )

If I do not use SellerSalesChannelNormalizer then it serializes this property name to

'kycCompleted' .

If I change getter to like getIsKycCompleted() then it serializes to is_kyc_completed - as in SerializedName attribute.

With custom normalized I fix it but that is additional code which I expect should not be needed.
Yea I see I could avoid custom normalizer by renaming getter to getIsKycCompleted, maybe I should choose this option but still even this is not expected to be needed.

Additional context

No response

@darius-v darius-v changed the title [Question]: Why #[SerializedName is ignored when method name matches property? [Question]: Why #[SerializedName('is_kyc_completed')] is ignored when method name matches property? Jan 15, 2025
@darius-v
Copy link
Author

Also similar problem - field does not appear in the doc when getter does not match property. Why? WHat getter has to do with this when all we do are writing near property?

public function getFBPOffer(): ?FBPOffer
{
   return $this->fbpOffer;
}

this adds field to response documentation:

public function getFbpOffer(): ?FBPOffer
{
   return $this->fbpOffer;
}

Copy link

This issue has been marked as stale because it has not had any activity for 60 days. Remove stale label or comment to prevent this from being closed in 21 days.

@github-actions github-actions bot added the stale stale issue/PR label Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question stale stale issue/PR
Projects
None yet
Development

No branches or pull requests

1 participant