title: Multiple Jackson Serializers of Same Return Type
body: <p>I am using Jackson for JSON serialization and have written a couple custom <code>String</code> serializers, one for each getter method of a class. The methods each return the same type, <code>Set&lt;String&gt;</code>, but each uses a different serializer.</p>
  
  <p>Unfortunately, Jackson is not using each serializer, one for each method, but is using one serializer for both. It appears to take whatever method comes first alphabetically and uses its serializer for both methods. What I expect is that the serializer annotated on the first method is used for the first method, and the serializer annotated on the second method is used on the second method. Debugging appears to indicate that Jackson has the serializers in a map keyed by return type of the method (which is the same for both).</p>
  
  <p><em>An Example:</em></p>
  
  <pre><code>public class FooBar {
  
    private Set&lt;String&gt; foos = new HashSet&lt;String&gt;();
    private Set&lt;String&gt; bars = new HashSet&lt;String&gt;();
  
    @JsonProperty("FooWrapper")
    @JsonSerialize(contentUsing = FooSerializer.class)
    public Set&lt;String&gt; getFoos() {
      return foos;
    }
  
    @JsonProperty("BarWrapper")
    @JsonSerialize(contentUsing = BarSerializer.class)
    public Set&lt;String&gt; getBars() {
      return bars;
    }
  }
  </code></pre>
  
  <p>Any suggestions on how to get the <code>getFoos()</code> method to serialize with a <code>FooSerializer</code>, and the <code>getBars()</code> method to serialize with the <code>BarSerializer</code>? In this example, the <code>BarSerializer</code> is invoked for both methods.</p>
  
  <p>Note, if I change the signature of one of the methods to another collection type so they are different - <code>List&lt;String&gt;</code> for example - the serialization works.</p>
  
  <p>Thanks in advance.</p>