servicestack-text

How to configure ServiceStack.Text to use EnumMember when serializing to csv or jsv?

时间秒杀一切 提交于 2019-12-11 06:55:18
问题 This is a follow up question to my earlier question about ServiceStack.Text and deserializing json to .Net enums. The answer to that question resolves how to get ServiceStack.Text to use .Net DataContract and EnumMember to map strings to enum values. Now I am trying to serialize the same enums to various formats and while json serialization is working in a round-trip way as expected, both csv and jsv conversion are ignoring the data contract. Is there a way to configure ServiceStack.Text

How to configure ServiceStack.Text to use EnumMember when deserializing?

孤街浪徒 提交于 2019-12-04 05:29:04
问题 I am using ServiceStack.Text to deserialize json received in rest api calls to objects C#. The model classes I use have defined the string representation using EnumMember attributes. The problem is that ServiceStack.Text does not seem to use those values. ServiceStack.Text documentation has a section called Custom enum serialization that discusses EnumMember attribute, but it talks only about serialization with no mention of deserialization. It is possible to configure ServiceStack.Text to

Is F# aware of its discriminated unions' compiled forms?

本秂侑毒 提交于 2019-12-04 02:23:26
A discriminated union in F# is compiled to an abstract class and its options become nested concrete classes. type DU = A | B DU is abstract while DU.A and DU.B are concrete. With ServiceStack, the serialization of types to JSON strings and back can be customized with functions. With respect to the DU type, here's how I could do it in C#. using ServiceStack.Text; JsConfig<DU.A>.SerializeFn = v => "A"; // Func<DU.A, String> JsConfig<DU.B>.SerializeFn = v => "B"; // Func<DU.B, String> JsConfig<DU>.DeserializeFn = s => if s == "A" then DU.NewA() else DU.NewB(); // Func<String, DU> Is F# aware of

Using ServiceStack.Text to deserialize a json string to object

房东的猫 提交于 2019-11-30 02:57:18
问题 I have a JSON string that looks like: "{\"Id\":\"fb1d17c7298c448cb7b91ab7041e9ff6\",\"Name\":\"John\",\"DateOfBirth\":\"\\/Date(317433600000-0000)\\/\"}" I'm trying to deserialize it to object (I'm implementing a caching interface) The trouble I'm having is when I use JsonSerializer.DeserializeFromString<object>(jsonString); It's coming back as "{Id:6ed7a388b1ac4b528f565f4edf09ba2a,Name:John,DateOfBirth:/Date(317433600000-0000)/}" Is that right? I can't assert on anything... I also can't use

ServiceStack - Is there a way to force all serialized Dates to use a specific DateTimeKind?

 ̄綄美尐妖づ 提交于 2019-11-28 07:35:18
I have a POCO like this: public class BlogEntry { public string Title { get; set; } public DateTime Date { get; set; } } Most of the time it's being hydrated from Entity Framework, but it can and will be used outside of Entity Framework. The DateTimeKind for the Date from EF is Unspecified, which from what I read is normal. When I cache this POCO in Redis (using the ServiceStack Redis client), it comes back with a DateTimeKind of Local. So there is a jitter with the returned objects. The first pass (uncached) has ISO-8061 with no offset (DateTimeKind.Unspecified). The second pass (cached) is

ServiceStack - Is there a way to force all serialized Dates to use a specific DateTimeKind?

我只是一个虾纸丫 提交于 2019-11-27 01:52:42
问题 I have a POCO like this: public class BlogEntry { public string Title { get; set; } public DateTime Date { get; set; } } Most of the time it's being hydrated from Entity Framework, but it can and will be used outside of Entity Framework. The DateTimeKind for the Date from EF is Unspecified, which from what I read is normal. When I cache this POCO in Redis (using the ServiceStack Redis client), it comes back with a DateTimeKind of Local. So there is a jitter with the returned objects. The