そのため、最初に GSON によって入力される OrmLite 4.41 モデル クラスがいくつかあります (わかりやすくするために簡略化しています)。
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 にコレクションの型を指定する方法はありますか? コレクションをarraylistとして返し、それが等しいかどうかをテストするメソッドが必要ですか?
前もって感謝します