我们的团队已选择Couchbase作为我们应用程序的缓存。我们在此缓存中存储的对象是这样的对象
public class CatalogEntity
{
public int Id { get; set; }
public string Name { get; set; }
// this property gives us trouble
public Hashtable Attributes { get; set;}
}
在我们的代码中,从CouchBase缓存中检索对象后,我发现主要类型(Id
和Name
)的属性已正确反序列化,但Attributes
的{{1}} 1}}类型未反序列化并保持为JSON。例如,如果我有类似
Hashtable
来自缓存的对象将具有var entity = new CatalogEntity();
entity.Attributes["foo"] = new Foo();
属性作为Attributes["foo"]
类的JSON表示。
我想知道如何正确序列化/反序列化Foo
类型?我应该将对象序列化为二进制,而是将二进制流存储在CouchBase中吗?
答案 0 :(得分:0)
您是否需要使用Hashtable
?例如,您可以使用Dictionary<string,string>
吗?
我认为你所看到的原因是Json.NET最好的序列化哈希表的尝试(参见StackOverflow上的这个问题:Serialize hashtable using Json.Net)。