title: Jackson deserialize objects as the same one
body: <p>I was working with jackson's <code>JsonIdentityInfo</code> annatation, the serialization looks good. But the deserialization didnt work as I expected, the objects sharing the same id, are not deserialized into the same objects. Below are the class definitions.</p>
  <pre><code>class ParameterResolver implements ObjectIdResolver {
      private final Map&lt;ObjectIdGenerator.IdKey,Object&gt; items = new HashMap&lt;&gt;();
  
      @Override
      public void bindItem(ObjectIdGenerator.IdKey id, Object pojo) {
          if (items.containsKey(id)) {
              throw new IllegalStateException(&quot;Already had POJO for id (&quot; + id.key.getClass().getName() + &quot;) [&quot; + id
                      + &quot;]&quot;);
          }
          items.put(id, pojo);
      }
  
      @Override
      public Object resolveId(ObjectIdGenerator.IdKey id) {
          Object object = items.get(id);
          return object == null ? getById(id) : object;
      }
  
      protected Object getById(ObjectIdGenerator.IdKey id){
          Object object;
          try {
              object = id.scope.getConstructor().newInstance();
              id.scope.getMethod(&quot;setId&quot;, Integer.class).invoke(object, (Integer) id.key);
          } catch (Exception e) {
              throw new IllegalStateException(e);
          }
          items.put(id, object);
          return object;
      }
  
      @Override
      public ObjectIdResolver newForDeserialization(Object context) {
          return new ParameterResolver();
      }
  
      @Override
      public boolean canUseFor(ObjectIdResolver resolverType) {
          return resolverType.getClass() == getClass();
      }
  }
  
  
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, resolver = ParameterResolver.class, property = &quot;id&quot;, scope = Parameter.class)
  class Parameter {
      private Integer id;
      private String data;
  
      public Parameter() {}
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getData() {
          return data;
      }
  
      public void setData(String data) {
          this.data = data;
      }
  }
  
  class Container {
      public Parameter p;
      public Container() {}
      public Container(Parameter p) {
          this.p = p;
      }
  }
  </code></pre>
  <p>and this is the unit test</p>
  <pre><code>    @Test
      public void test() throws JsonProcessingException {
          Parameter p1 = new Parameter(), p2 = new Parameter();
          p1.setId(1);
          p1.setData(&quot;1&quot;);
          List&lt;Container&gt; list = new ArrayList&lt;&gt;();
          list.add(new Container(p1));
          list.add(new Container(p1));
          ObjectMapper mapper = new ObjectMapper();
          String content = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(list);
          List&lt;Container&gt; listD = mapper.readValue(content, new TypeReference&lt;List&lt;Container&gt;&gt;() {});
          assertSame(listD.get(0).p, list.get(1).p); // didnt pass this assertion
      }
  </code></pre>