Skip to content

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

@darius-v

Description

@darius-v

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions