Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SerializedName with numbers does not work properly (symfony/serializer) #49538

Copy link
Copy link
Closed
@elevado

Description

@elevado
Issue body actions

Symfony version(s) affected

6.2.*

Description

A JSON must be created where the properties are field numbers.

class Person
{
    #[SerializedName('1')]
    private string $firstname;

    #[SerializedName('2')]
    private string $lastname;

    #[SerializedName('3')]
    private string $email;
   
    /*
         getter and setter
    */   
}
$person = new Person();
$person->setFirstname('John');
$person->setLastname('Doe');
$person->setEmail('john.doe@example.com');

$jsonContent = $this->serializer->serialize($person, 'json');

/*
        {
    	    "1": "John",
    	    "2": "Doe"
    	    "3": "john.doe@example.com"
	}
*/

However, an error occurs during deserialisation.

$deserializePerson = $this->serializer->deserialize($jsonContent, Person::class, 'json');

/*
	App\Dto\Person Object
	(
	    [firstname:App\Dto\Person:private] => Doe
	    [lastname:App\Dto\Person:private] => john.doe@example.com
	)
*/
  • When debugging, I discovered that the last property in \Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter::denormalize is not processed, so the method is not called for it.
  • The second to last property gets the value of the last property.

How to reproduce

I have pushed a fresh Symfony with only one Controller and DTO in here:
https://github.com/elevado/symfony-serializer-serializedname-bug

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.