HasOne extends Relationship<T> implements Serializable { @Override public T get(Document document) { return get(document, null); } HasOne();  HasOne(String type, String id);  HasOne(ResourceIdentifier linkedResource); @Override T get(Document document); T get(Document document, T defaultValue); ResourceIdentifier get(); void set(ResourceIdentifier identifier); void set(String type, String id); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void resolution() throws Exception { Document document = new ObjectDocument(); assertNull(createHasOne().get(document)); Person holder = new Person(); assertEquals(createHasOne().get(document, holder), holder); Person person = new Person(); person.setId("5"); document.addInclude(person); assertEquals(createHasOne().get(document), person); }
@Test public void deserialization() throws Exception { assertThat(TestUtil.moshi().adapter(HasOne.class).fromJson("{\"data\":{\"type\":\"people\",\"id\":\"5\"}}"), equalTo((HasOne) createHasOne())); assertNull(TestUtil.moshi().adapter(HasOne.class).fromJson("{\"data\":null}").get()); }