title: Asymmetric serialization/deserialization using Symfony Serilizer
body: <p>I'm using Symfony 5.4 and its Symfony/Serializer component.</p>
  <p>I receive a JSON payload like the following one:</p>
  <pre><code>{
    &quot;name&quot;: &quot;Truck&quot;,
    &quot;age&quot;: 23
  }
  </code></pre>
  <p>I wish I could deserialize it to the following model, where the <code>name</code> JSON field would be mapped onto the <code>lastname</code> User class attribute:</p>
  <pre><code>class User {
    protected lastname;
    protected age;
  }
  </code></pre>
  <p>My issue here is that the deserialization fails since there is no <code>name</code> field in my model.</p>
  <p>Sure I could add a <code>name</code> field to my User model, and write its getter/setters as follow and use Serializer's group not to serialize the <code>name</code> field :</p>
  <pre><code>public function getName(): string
  {
      return $this-&gt;lastname;
  }
  
  public function setName(string $name): User
  {
      $this-&gt;lastname = $name;
  
      return $this;
  }
  </code></pre>
  <p>But this looks hackish. Anyway, on top of the aforementioned, I need any <code>User</code> entity to be serialized to :</p>
  <pre><code>{
    &quot;lastname&quot;: &quot;Truck&quot;,
    &quot;age&quot;: 23
  }
  </code></pre>
  <p>As a consequence, I can not use <code>@SerializedName('name')</code> here.</p>
  <p>What would be the cleaner way to achieve this?</p>