使用Newtonsoft JsonConvert进行序列化会因特定的属性集而失败

时间:2013-04-21 19:48:38

标签: c# .net serialization json.net

我试图将对象树序列化为json字符串。对象树很复杂,并且通常序列化没有问题,除了一组属性是来自不同.DLL的对象。无论如何我还可以序列化这些吗?

这是序列化的代码:

var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
var json = JsonConvert.SerializeObject(exe.Value, settings);
File.WriteAllText(Path.Combine(folderCache, exe.Value.AccountId + ".txt"), json);

以下是未进行序列化的类属性的类型:

[DataContract(Namespace = Constants.ServiceManagementNS)]
public class Deployment : IExtensibleDataObject

exe.Value是一个基于EntityFramework的模型对象,其定义类似于此(它的结构很深)

[DataContract(IsReference = true)]
[KnownType(typeof(Account))]
public partial class AccountUser: IObjectWithChangeTracker, INotifyPropertyChanged

在树的深处,有一个名为AzureDeployment的属性没有被序列化:

    public Deployment AzureDeployment { get; set; }

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

原来我需要用[DataMember]

标记非序列化实体
相关问题