ektorp/CouchDB混合HashMap和注释
在jcouchdb中,我曾经扩展BaseDocument,然后以透明的方式混合注释和未声明的字段。 例如: 然后使用它:ektorp/CouchDB混合HashMap和注释,couchdb,ektorp,Couchdb,Ektorp,在jcouchdb中,我曾经扩展BaseDocument,然后以透明的方式混合注释和未声明的字段。 例如: 然后使用它: // Create a SiteDocument SiteDocument site2 = new SiteDocument(); site2.setProperty("site", "http://www.starckoverflow.com/index.html"); // Set value using setSite site2.setSite("www.stacko
// Create a SiteDocument
SiteDocument site2 = new SiteDocument();
site2.setProperty("site", "http://www.starckoverflow.com/index.html");
// Set value using setSite
site2.setSite("www.stackoverflow.com");
// and using setProperty
site2.setProperty("description", "Questions & Answers");
db.createOrUpdateDocument(site2);
当我使用通过注释定义的文档字段(站点)和未定义的属性字段(描述)时,在保存文档时,这两个字段都会被序列化
这对我来说很方便,因为我可以处理半结构化文档
当我尝试用Ektorp做同样的事情时,我有使用注释的文档和使用HashMap的文档,但我找不到一种简单的方法来混合两者(我尝试过使用自己的序列化程序,但对于我在jcouchdb中免费获得的东西来说,这似乎有很多工作要做)。我还尝试注释一个HashMap字段,但随后被序列化为一个对象,我得到了自动保存的字段,但位于一个名为HashMap字段的对象内
使用Ektorp是否可能(轻松/免费)?这绝对是可能的。您有两个选择:
// Create a SiteDocument
SiteDocument site2 = new SiteDocument();
site2.setProperty("site", "http://www.starckoverflow.com/index.html");
// Set value using setSite
site2.setSite("www.stackoverflow.com");
// and using setProperty
site2.setProperty("description", "Questions & Answers");
db.createOrUpdateDocument(site2);