title: Deserialize with Jackson with reference to an existing object
body: <p>JSON</p>
  
  <pre><code>{
    "schools": [
      {
        "id": 1,
        "name": "School A"
      },
      {
        "id": 2,
        "name": "School B"
      }
    ],
    "students": [
      {
        "id": 1,
        "name": "Bobby",
        "school": 1
      }
    ]
  
  }
  </code></pre>
  
  <p>How would I map the JSON into the following classes such that Bobby's school is mapped to the already instantiated School A.</p>
  
  <pre><code>public class School {
    private Integer id;
    private String name;
  }
  
  public class Student {
    private Integer id;
    private String name;
    private School school;
  }
  </code></pre>
  
  <p>I've tried some weird stuff with the Student class...</p>
  
  <pre><code>public class Student {
    private Integer id;
    private String name;
    private School school;
  
    @JsonProperty("school")
    public void setSchool(Integer sid) {
      for (School school : getSchools()) {
        if (school.id == sid) {
          this.school = school;
          break;
        }
      }
    }
  }
  </code></pre>
  
  <p>The problem I'm having is that both the schools and the students are being parsed from the JSON at the same time, so I'm not sure how to get a list of the schools. Maybe I should parse these separately so I have the list of schools first?</p>