Open
Description
Description
If I have for example this classes:
class A
{
public function __construct(
#[SerializedName("PropA")]
protected ?string $propA = null,
#[SerializedName("PropB")]
protected ?string $propB = null,
)
}
and a second, slightly different class with the same attributes, but in a different order
class B
{
public function __construct(
#[SerializedName("PropB")]
protected ?string $propB = null,
#[SerializedName("PropA")]
protected ?string $propA = null,
)
}
For security, I didn't want to make the properties public, so I needed to add getter/setter functions.
Because they are the same, I thought about using a Trait.
But that didn't work because ObjectNormalizer returns the Attributes in the order of the functions it found.
My idea is defining an Interface where the User can create their own Sort Functions
public function sortAttributes($string $object, array $attributes, ?string $format = null, array $context = []): array
So you could make the sort of the attributes depending on the object or the class of the object.
I don't know what kind of implementations (like sort by constructor params?) should be predefined
See also #27441
Example
No response