@樓若生 T one = ((Class<T>) typeOfT).newInstance(); 這個方法生成的Entity,是和ObjectBox detached的,ObjectBox直接報錯,在ObjectBox文檔中,有專門提到了The @Entity annotation identifies the Java class User as a persistable entity. This will trigger ObjectBox to generate persistence code tailored for this class. 如果手動做attach處理,反射的newInstanc方法不會與數(shù)據(jù)庫關(guān)聯(lián),而直接使用new方法出來的instance則自動與database attach在一起。文章中的所有代碼,只對ToOne和ToMany在序列化和反序列化中進(jìn)行處理,但是對于Entity其他基本類型屬性沒有做處理,也沒有給出處理的回調(diào)。
你的代碼我用Kotlin大概跑了,跑不通
ObjectBox Entity 與 Json 之間的相互轉(zhuǎn)換/序列化都知道在ObjectBox中,表關(guān)系在POJO中是用ToOne或ToMany對象來表示的。而當(dāng)我們的業(yè)務(wù)場景中需要用到Json數(shù)據(jù)進(jìn)行轉(zhuǎn)換時,這兩個對象的存在則成為了一種麻煩...