所以,我這是最初被GSON人口數OrmLite 4.41模型類(簡化爲清楚起見)如何應對OrmLite ForeignCollection場在與Android的機型GSON
public class Crag {
@DatabaseField(id=true) private int id;
@ForeignCollectionField(eager=true, maxEagerLevel=2) @SerializedName("CragLocations")
private Collection<CragLocation> cragLocations;
}
public class CragLocation {
@DatabaseField(id=true) private int id;
@DatabaseField private int locationType;
@DatabaseField(foreign=true, foreignAutoCreate=true, foreignAutoRefresh=true)
private Crag crag;
@DatabaseField(foreign=true, foreignAutoCreate=true, foreignAutoRefresh=true)
private Location location;
}
public class Location {
@DatabaseField(id=true) private int id;
@DatabaseField private BigDecimal latitude;
@DatabaseField private BigDecimal longitude;
}
我然後測試該事情正在發生,因爲我期待...
@Test
public void canFindById() {
Crag expected = ObjectMother.getCrag431();
_repo.createOrUpdate(template431);
Crag actual = _repo.getCragById(431);
assertThat(actual, equalTo(template431));
}
他們不相等...爲什麼不呢?因爲在由GSON創建的對象中(在ObjectMother.getCrag431()
),Crag的cragLocations字段是一個ArrayList,並且由OrmLite加載它是一個EagerForeignCollection我在這裏錯過了一個技巧嗎?有沒有辦法告訴OrmLite我想要那個集合是什麼類型?我應該只是有一個方法,返回集合作爲一個數組列表並測試它是否相等?
在此先感謝