C# 为什么json.net只显示s#arp EntityWithTypedId类?

C# 为什么json.net只显示s#arp EntityWithTypedId类?,c#,json.net,s#arp-architecture,C#,Json.net,S#arp Architecture,我在一个项目中使用了Sharp arch的旧版本,并尝试使用JSON.NET进行序列化。JavascriptSerializer可以工作,但我更喜欢JSON.NET作为首选项 问题出在这里。出于某种原因,当我尝试序列化一个简单的Sharp对象时,我得到以下结果: // my sharp object [Serializable] public class Contact : Entity { public virtual string EmailAddress { get; set; }

我在一个项目中使用了Sharp arch的旧版本,并尝试使用JSON.NET进行序列化。JavascriptSerializer可以工作,但我更喜欢JSON.NET作为首选项

问题出在这里。出于某种原因,当我尝试序列化一个简单的Sharp对象时,我得到以下结果:

// my sharp object
[Serializable]
public class Contact : Entity
{
    public virtual string EmailAddress { get; set; }
}

...

// in sharp, this is what happens to Entity
[Serializable]
public abstract class Entity : EntityWithTypedId<int> {
    protected Entity();
}

// and then into EntityWithTypedId
[Serializable]
public abstract class EntityWithTypedId<IdT> : ValidatableObject, IEntityWithTypedId<IdT> {
    protected EntityWithTypedId();

    [JsonProperty]
    [XmlIgnore]
    public virtual IdT Id { get; protected set; }

    public override bool Equals(object obj);
    public override int GetHashCode();
    protected override IEnumerable<PropertyInfo> GetTypeSpecificSignatureProperties();
    public virtual bool IsTransient();
}
有没有关于如何返回整个对象内容的想法?

S#arp体系结构中的BaseObject类将成员序列化设置为OptIn,该设置已在2.0中删除

你的选择是:

  • 升级至Sharp Architecture 2.0
  • 使用不同的json序列化器,这很好
  • 在删除属性的情况下重新编译Sharp Architecture 1.6
  • 将JsonProperty属性添加到要序列化的特定属性

您所提供的最新版本的sharp architecture和对象已正确序列化,您使用的是什么版本的sharp architecture/Newtonsoft.Json?您好,Attar,目前我们必须坚持使用SharpArch.dll v1.6.0.0。和最新版本的Newtonsoft.Json。感谢您的帮助,我最终恢复到了Json.NET 3.5。我一定会按照建议查看ServiceStack.Text。出于某种原因,我也忘记了重新编译:)
Contact test = new Contact {
    EmailAddress = "test@test.com"
};
string result = JsonConvert.SerializeObject(test);