servicestack-text

ServiceStack OnDeserialized Equivalent

对着背影说爱祢 提交于 2021-02-19 06:16:48
问题 I am deserialize a websocket message in real time. In the message (string of json) I receive there is a unix timestamp (long). As soon as each object is deserialized I need it to call a method ASAP so that I can capture the delay between the time the message was sent and received. With Json.NET that was simple I just added this method to my DataContract class: [OnDeserialized] private void OnDeserialized(StreamingContext context) { Timestamp = DateTimeOffset.FromUnixTimeMilliseconds

Couchbase Lite 2 + JsonConvert

本小妞迷上赌 提交于 2021-01-27 12:49:08
问题 The following code sample writes a simple object to a couchbase lite (version 2) database and reads all objects afterwards. This is what you can find in the official documentation here This is quite a lot of manual typing since every property of every object must be transferred to the MutableObject . class Program { static void Main(string[] args) { Couchbase.Lite.Support.NetDesktop.Activate(); const string DbName = "MyDb"; var db = new Database(DbName); var item = new Item { Name = "test",

JsonSerializer not serializing derived class properties

陌路散爱 提交于 2019-12-24 06:46:01
问题 I have a class like below which is added to the project/solution as reference public class FileContents { public List<RecordBase> Records { get; set; } } public class RecordBase { public int LineNumber { get; set; } } There few other class which are not added to the reference but dynamicaly loaded and those classes are derived from RecordBase class the below is the snippet on how it is loaded var fileContents = new FileContents(); var dll = Assembly.LoadFile(derivedClassesAssemblyLocation);

Deserialize Root Object in ServiceStack Explicit Response DTO

可紊 提交于 2019-12-24 06:14:32
问题 I'm consuming a third party WebApi using ServiceStack. Imagine this API has the following route. https://api.example.com/v1/people/{id} returns the person with the specified ID. JSON: { "id": 1, "name": "Jean-Luc Picard" } I could consume this with the following C# code. class Program { static void Main(string[] args) { var client = new JsonServiceClient("https://api.example.com/v1/"); Person person = client.Get(new GetPerson() { ID = 1 }); } } [Route("/people/{id}")] public class GetPerson :

ServiceStack ORMLite not deserializing JSON stored in DB text field

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:33:39
问题 I have some telemetry data that was stored in a text field as JSON. I'm attempting to reverse-engineer POCOs to seamlessly extract and present that data without having to do any post-processing ForEach loops. When I attempt to manually parse the JSON string in the data field, it works. When I am selecting via ORMLite, it comes back with the default object. What am I missing? Works string x = "{\"alive\":true,\"paperStatus\":\"0:NoIssue\"}"; var telemetry = JsonSerializer.DeserializeFromString

ServiceStack returning JSV instead of JSON

时光怂恿深爱的人放手 提交于 2019-12-23 15:28:08
问题 I have a service created with ServiceStack. Recently I updated the ServiceStack libraries and now I am getting JSV responses instead of JSON responses. The request looks something like: POST http://localhost/api/rest/poll/create?format=json&PollFormat=1 HTTP/1.1 Host: localhost Connection: keep-alive Content-Length: 160 Accept: */* Origin: http://localhost X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500

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

狂风中的少年 提交于 2019-12-21 08:23:06
问题 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

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

喜你入骨 提交于 2019-12-21 08:23:05
问题 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

Deserializing Multidimensional array from JSON with ServiceStack fails

ぐ巨炮叔叔 提交于 2019-12-12 03:22:10
问题 I have an object with a single double[,] property, which was serialized using ServiceStack ToJson() method as follows: {"xy":[[-2.9774,-2.0682],[-1.1378,2.7118]]} However I cannot deserialize it back to my object type ( Parameters ) using "abovestring".FromJson<Parameters>() as it throws the following exception: System.Runtime.Serialization.SerializationException: Failed to set property 'xy' with '[[-2.9774,-2.0682],[-1.1378,2.7118]]' ---> System.FormatException: Input string was not in a

Deserialize CSV with CustomHeaders using ServiceStack.Text

对着背影说爱祢 提交于 2019-12-12 02:54:31
问题 I'm trying to use ServiceStack.Text for deserializing a csv file containing custom headers. var csv = "Col-1,Col-2" + Environment.NewLine + "Val1,Val2" + Environment.NewLine + "Val3,Val3" + Environment.NewLine; public class Line { public string Col1 { get; set; } public string Col2 { get; set; } } ServiceStack.Text.CsvConfig<Line>.CustomHeadersMap = new Dictionary<string, string> { {"Col1", "Col-1"}, {"Col2", "Col-2"} }; var r2 = ServiceStack.Text.CsvSerializer.DeserializeFromString<List<Line