ServiceStack.Text json仅序列化结构属性 [英] ServiceStack.Text json only serialize struct properties
问题描述
是否可以像.net JavaScriptSerializer一样使ServiceStack.Text消毒结构的公共字段?
Is it possible to make ServiceStack.Text sterilize public fields of a struct just like the .net JavaScriptSerializer does?
当前,如果结构未将文件定义为属性,即c ++或get; set;中的property关键字;在C#中,该值未序列化.
Currently if a struct does not define a filed as a property, i.e. property keyword in c++ or get;set; in c# the value does not get serialized.
推荐答案
根据设计,ServiceStack序列化程序会尝试促进在服务的服务层/边界中使用特殊用途的DTO,在此目标中,我们仅序列化类型的公共属性,从而可以灵活地生成有线格式.
By design ServiceStack serializers tries to promote the use of special purpose DTOs for use in the service layer/boundary of your services, in this goal we only serialize public properties of types which allows flexibility in how the wire format is generated.
这与通用对象序列化程序相反,后者也可以序列化类型的内部表示(即私有字段和公共字段).
This is opposed to being a general purpose object serializer that would also serialize the internal representation of your types (i.e. private and public fields).
这篇关于ServiceStack.Text json仅序列化结构属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!