开发者

Json issue in a sub-class

I have 2 DTO files, with one of them being a sub-class of the other. The fields on the super-class are as follows:

[JsonProperty]
protected int financialFormatHeaderID;

[JsonProperty]
protected string financialFormatHeaderCode;

[JsonProperty]
protected string description = string.Empty;

[JsonProperty]
protected FinancialFormatPurpose purpose = FinancialFormatPurpose.Standard;

[JsonPrope开发者_JAVA技巧rty]
protected IList<FinancialFormatDetailDto> details = new List<FinancialFormatDetailDto>();

[JsonProperty]
protected bool active = true;

The sub-class has this:

public RecoveryFormatHeaderDto()
  : base() {
  this.purpose = FinancialFormatPurpose.Recovery;
}

[JsonProperty]
private bool isPerSquareArea;

They both have the JsonObject(MemberSerialization.OptIn) and Serializable attributes above the class name (but under the namespace).

My problem is that when I try to save an instance of the sub-class I get the following error:

Newtonsoft.Json.JsonSerializationException was unhandled by user code

Message=A member with the name 'financialFormatHeaderID' already exists on 'RecoveryFormatHeaderDto'. Use the JsonPropertyAttribute to specify another name.

Source=Newtonsoft.Json

What is happening here? How do I fix this?

EDIT: Class signatures are as follows:

public class FinancialFormatHeaderDto
public class RecoveryFormatHeaderDto : FinancialFormatHeaderDto


Though I don't know Json.Net, my guess would be that the problem is somewhat related to that you have the JsonObjectAttribute(MemberSerialization.OptIn) on both classes. Perhaps you should try removing that attribute from the sub-class, and see if it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜