title: how to create a custom JsonDeserializer in Java?
body: <p>I have a <code>Map&lt;A,B&gt; fieldOfC</code> as a field of a class C. When I try to deserialize C with Jackson, an Exception is thrown because it can't find a Deserializer for Map's key A. So, I guess the solution is to extend StdJsonDeserializer and do it manually.<br>
  My problem is that I can't find an example on how to use the parser and the context of the method "deserialize" that I have to implement.</p>
  
  <p>Can anyone write the code for this simple example so I can use it as a start to build my real deserializer?</p>
  
  <pre><code>public class A{
    private String a1;
    private Integer a2;
  }
  
  public class B{
    private String b1;
  }
  
  public class C{
    @JsonDeserialize(keyUsing=ADeserializer.class)
    //also tried this: @JsonDeserialize(keyAs=A.class) without success
    private Map&lt;A,B&gt; fieldOfC;
    private String c1;
  }
  
  public class ADeserializer extends StdKeyDeserializer {
  
    protected ADeserializer(Class&lt;A&gt; cls) {
      super(cls);
    }
  
    protected Object _parse(String key, DeserializationContext ctxt) throws Exception {
      ObjectMapper mapper = new ObjectMapper();
      return mapper.readValue(key, A.class);
    }
  }
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT</strong>: googling, I found a <a href="http://archive.codehaus.org/lists/org.codehaus.jackson.user/msg/ceb609d80910021829r61997ec0q5fc64e926779f4c0@mail.gmail.com" rel="nofollow noreferrer">test</a> of the same problem I have. This is exactly my problem </p>
  
  <p><strong>EDIT</strong>: changed extended class from StdDeserializer to StdKeyDeserializer as I read <a href="http://jackson.codehaus.org/1.7.0/javadoc/org/codehaus/jackson/map/DeserializerProvider.html" rel="nofollow noreferrer">here</a> in method <code>findKeyDeserializer(org.codehaus.jackson.map.DeserializationConfig, org.codehaus.jackson.type.JavaType, org.codehaus.jackson.map.BeanProperty)</code></p>
  
  <p><strong>EDIT</strong>: After solving this issue I got <a href="https://stackoverflow.com/q/5614654/288247">this one</a> that is related.</p>