ServiceStack.Text: Forcing serialization of a property not decorated with DataMember attribute

…衆ロ難τιáo~ 提交于 2019-12-11 06:27:32

问题


I have the following class (simplified).

[DataContract]
public class ServiceResponse
{
    public int Sequence { get; set; }

    [DataMember]
    public ServiceResponseStatus Status { get; set; }
}

I'm using ServiceStack to serialize objects for logging purposes, and letting DataContractSerializer do the rest. ServiceStack, as expected, will not serialize Sequence as it is not decorated with a DataMember attribute.

Is there a way to force ServiceStack to serialize this property?

Marc Gravell's answer to this similar question DataContract Serialization without DataMember Attribute seems to suggest a different approach, but I thought I'd ask.


回答1:


Decorating your classes with DataContract/DataMember attributes is specifically used for opting in which properties you want serialized. If you want all properties serialized remove all the attributes.

See this answer for other ways to ignore properties in Servicestack serializers.



来源:https://stackoverflow.com/questions/15971117/servicestack-text-forcing-serialization-of-a-property-not-decorated-with-datame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!