How to map multiple parameter names to POJO when binding spring mvc command objects
<p>My question is actually a spin-off of this question <a href="https://stackoverflow.com/questions/8986593/how-to-customize-parameter-names-when-binding-spring-mvc-command-objects">as seen here...</a> so it might help to check that thread before proceeding.</p>

<p>In my Spring Boot project, I have two entities <code>Sender</code> and <code>Recipient</code> which represent a <code>Customer</code> and pretty much have the same fields, so I make them extend the base class <code>Customer</code>; </p>

<p><strong><em>Customer</em> base class;</strong></p>

<pre><code>@MappedSuperclass
public class Customer extends AuditableEntity {

    @Column(name = "firstname")
    private String firstname;

    @Transient
    private CustomerRole role;

    public Customer(CustomerRole role) {
        this.role = role;
    }

    //other fields &amp; corresponding getters and setters
}
</code></pre>

<p><strong><em>Sender</em> domain object;</strong></p>

<pre><code>@Entity
@Table(name = "senders")
public class Sender extends Customer {

    public Sender(){
        super.setRole(CustomerRole.SENDER);
    }
}
</code></pre>

<p><strong><em>Recipient</em> domain object;</strong></p>

<pre><code>@Entity
@Table(name = "recipients")
public class Recipient extends Customer {

    public Recipient(){
        super.setRole(CustomerRole.RECIPIENT);
    }
}
</code></pre>

<p>NOTE - <code>Sender</code> and <code>Recipient</code> are exactly alike except for their roles. These can be easily stored in a single <strong>customers</strong> Table by making the <code>Customer</code> base class an entity itself, but I intentionally separate the entities this way because I have an obligation to persist each customer type in separate database tables.</p>

<p>Now I have one form in a view that collects details of both <code>Sender</code> &amp; <code>Recipient</code>, so for example to collect the firstname, I had to name the form fields differently as follows;</p>

<p><strong><em>Sender section of the form;</em></strong></p>

<pre><code>&lt;input type="text" id="senderFirstname" name="senderFirstname" value="$!sender.firstname"&gt;
</code></pre>

<p><strong><em>Recipient section of the form;</em></strong></p>

<pre><code>&lt;input type="text" id="recipientFirstname" name="recipientFirstname" value="$!recipient.firstname"&gt;
</code></pre>

<p>But the fields available for a customer are so many that I'm looking for a way to map them to a pojo by means of an annotation as asked in <a href="https://stackoverflow.com/questions/8986593/how-to-customize-parameter-names-when-binding-spring-mvc-command-objects">this question here</a>. However, the solutions provided <a href="https://stackoverflow.com/questions/8986593/how-to-customize-parameter-names-when-binding-spring-mvc-command-objects">there</a> would mean that I have to create separate proxies for both domain objects and annotate the fields accordingly e.g </p>

<pre><code>public class SenderProxy {

    @ParamName("senderFirstname")
    private String firstname;

    @ParamName("senderLastname")
    private String lastname;
    //...
}

public class RecipientProxy {

    @ParamName("recipientFirstname")
    private String firstname;

    @ParamName("recipientLastname")
    private String lastname;
    //...
}
</code></pre>

<p>So I got very curious and was wondering, is there a way to map this Proxies to more than one @ParamName such that the base class for example can just be annotated as follows?;</p>

<pre><code>@MappedSuperclass
public class Customer extends AuditableEntity {

    @Column(name = "firstname")
    @ParamNames({"senderFirstname", "recipientFirstname"})
    private String firstname;

    @Column(name = "lastname")
    @ParamNames({"senderLastname", "recipientLastname"})
    private String lastname;

    @Transient
    private CustomerRole role;

    public Customer(CustomerRole role) {
        this.role = role;
    }

    //other fields &amp; corresponding getters and setters
}
</code></pre>

<p>And then perhaps find a way to select value of fields based on annotation??</p>