我遇到ServiceStack(SS)的奇怪问题。我传递给方法的实体总是被序列化为SS来清空json字符串。所以s总是“{}”。我调试并看到实体是一个带有值的属性的水合实例。
为什么会出现这种情况?
public virtual void Serialize<TEntity>(TEntity entity, Stream stream)
{
// s is always {}
var s = JsonSerializer.SerializeToString(entity);
// rest is not important at this point...
s = JsvFormatter.Format(s);
using (var writer = new StreamWriter(stream))
{
writer.Write(s);
}
}
我正在编辑问题,显示传入(VolumeCreated)实体的确切内容。
public class VolumeEvent : IEvent<VolumeID>
{
public VolumeEvent(VolumeID identity)
{
Identity = identity;
}
#region Implementation of IEvent<out VolumeIdentity>
public VolumeID Identity { get; private set; }
#endregion
}
public class VolumeCreated : VolumeEvent
{
public DateTime PublishDate { get; set; }
public string Title { get; set; }
public VolumeCreated(VolumeID identity, string title, DateTime publishDate)
: base(identity)
{
Title = title;
PublishDate = publishDate;
}
}
答案 0 :(得分:4)
ServiceStack序列化仅序列化公共属性。