serialization

Why do data classes not implement Serializable?

房东的猫 提交于 2020-06-16 02:48:09
问题 I am new to kotlin but a veteran of scala . The former has impressed me so far. But at this moment I am working through a head scratcher - that the data class does not implement Serializable . How a class with that name could expected to not be routinely expected to be used in that manner eludes me. What are the technical challenge(s) that precluded that support? I'm interested because i'd like to create a wrapper. It seems that the expectation is to always provide a serializer() ? That is

C# Xml Serializer deserializes list to count of 0 instead of null

孤街醉人 提交于 2020-06-14 06:23:27
问题 I am confused on how XmlSerializer works behind the scenes. I have a class that deserializes XML into an object. What I am seeing is for the following two elements that are NOT part of the Xml being deserialized. [XmlRootAttribute("MyClass", Namespace = "", IsNullable = false)] public class MyClass { private string comments; public string Comments { set { comments = value; } get { return comments; } } private System.Collections.Generic.List<string> tests = null; public System.Collections

How to serialize a Func<int, int> (or even a general delegate) type field with DataContract/DataMember in WCF

冷暖自知 提交于 2020-06-13 19:32:25
问题 I am trying to serialize a Func<int, int> field marked with [DataMember] , of a class marked with [DataContract] , whose target or Lambda expression definition is also part of the contract or could even be in the class itself. I am using a custom DataContractResolver which works perfectly well when I unmark the Func field but when I mark it, it does not resolve a System.DelegateSerializationHolder type needed for the serialization. I tried to add this type to my custom DataContractResolver

Newtonsoft Json.NET JsonConverter attribute preserve references issue when deserializing

岁酱吖の 提交于 2020-06-12 18:34:14
问题 In the models of a project I am using a JsonConverter attribute to help with the (de)serialization of those models. The converter currently looks like this: public class CustomJsonConverter : Newtonsoft.Json.JsonConverter { bool _canWrite = true; public override bool CanWrite { get { return _canWrite; } } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects; serializer

Json and Xml serialization, what is better performance?

时光毁灭记忆、已成空白 提交于 2020-06-11 16:53:31
问题 I have to store some config info in file. In C# code config data represents by class and in file I am going to save this class in json or xml format. So, what is the best performance of serialization json or xml? 回答1: Well instead of guessing, I have the answer. Here is the test program: class Program { static void Main(string[] args) { string xmlConfig = ""; string jsonConfig = ""; Config myConfig = new Config() { value = "My String Value", DateStamp = DateTime.Today, counter = 42, Id = Guid

Json and Xml serialization, what is better performance?

与世无争的帅哥 提交于 2020-06-11 16:53:07
问题 I have to store some config info in file. In C# code config data represents by class and in file I am going to save this class in json or xml format. So, what is the best performance of serialization json or xml? 回答1: Well instead of guessing, I have the answer. Here is the test program: class Program { static void Main(string[] args) { string xmlConfig = ""; string jsonConfig = ""; Config myConfig = new Config() { value = "My String Value", DateStamp = DateTime.Today, counter = 42, Id = Guid

Django Rest Framework - Nested Serialization not working as expected

馋奶兔 提交于 2020-06-09 17:23:27
问题 While using Django-REST-Framework, I am not able to display selected fields in a nested serialized object. I am correctly able to serialize the entirety of the Address model, but I want only a few fields from Address , nested in my serialized Outlet . There is a Got AttributeError when attempting to get a value for field outlet_address on serializer OutletSerializer . The serializer field might be named incorrectly and not match any attribute or key on the Outlet instance. Original exception

Using XML decorations to specify default values during de-serialization

久未见 提交于 2020-06-09 16:57:11
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

好久不见. 提交于 2020-06-09 16:56:09
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

亡梦爱人 提交于 2020-06-09 16:56:07
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the