ServiceStack ORMLite不會從Postgresql反序列化我的類。ServiceStack ormlite json不會從數據庫反序列化
保持緩存中的對象解決了問題,但無法將它們加載回去(保存無誤)。
下面是重現問題的代碼。
void Main()
{
var inv = new Inventory();
inv.Items.Add(new Item{Id=1,CreatedAt=DateTime.Now, Key="potion10", Descriptions=new Dictionary<int, string>{{1,"Poção que recupera um pouco de vida."},{2,"Potion that restores a little of health."}}, HealthModifier=10,IsUseable=true, Names=new Dictionary<int, string>{{1,"Poção Leve"},{2,"Minor Potion"}}, UpdatedAt=DateTime.Now}, 2);
var invJson = inv.ToJson().To<Inventory>(); // can't deserialize
var invJsv = inv.ToJsv().To<Inventory>(); // same problem
}
public class Item
{
public Item()
{
Names = new Dictionary<int, string>();
Descriptions = new Dictionary<int, string>();
}
public long Id { get; set; }
public string Key { get; set; }
public Dictionary<int, string> Names { get; set; }
public Dictionary<int, string> Descriptions { get; set; }
public int HealthModifier { get; set; }
public bool IsUseable { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
public class Inventory
{
public Inventory()
{
Items = new Dictionary<Item, int>();
}
public Dictionary<Item, int> Items { get; set; }
}
Postgresql上的JSON與上面的代碼相同。
{
"Items":{
"{"Id":1,
"Key":"potion10",
"Names":{
"1":"Poção Leve",
"2":"Minor Potion"
},
"Descriptions":{
"1":"Poção que recupera um pouco de vida.",
"2":"Potion that restores a little of health."
},
"HealthModifier":10,
"IsUseable":true,
"CreatedAt":"\/Date(1430743156138-0300)\/",
"UpdatedAt":"\/Date(1430743156139-0300)\/"
}:2
}
}
'inv.ToJson()'返回的json是什麼樣的? – dbc
另外,Postgresql的JSON看起來像什麼? – dbc