serialization

Ignore property when serializing under certain conditions

≡放荡痞女 提交于 2020-01-14 12:54:09
问题 Json.net has a very useful property that can be set on the JsonPropertyAttribute called NullValueHandling . If you decorate a property like this: [JsonProperty(NullValueHandling=NullValueHandling.Ignore)] string MyProp { get; set; } Then if MyProp is null, it won't be included in the output at all. I would like to do something similar, but with a different condition for exclusion. For example - say we have an enum public enum MyEnum { None = 0, Value1 = 1, Value2 = 2, Value3 = 4 }; And a

Can I use C# Serialization to read a binary file in custom format?

a 夏天 提交于 2020-01-14 12:53:40
问题 I have a custom binary file which I want to read into my C# program. There are several different formats, some MSB first, some LSB first and some with the variables in different orders. Currently, I have a class which reads the right number of bytes, one at a time. It is very slow and so I am looking to improve performance any way I can. Is serialization likely to perform better? If so, is this possible with the scenario I have decsribed? Is it possible to customise the BinaryFormatter for

Ignore property when serializing under certain conditions

南楼画角 提交于 2020-01-14 12:52:26
问题 Json.net has a very useful property that can be set on the JsonPropertyAttribute called NullValueHandling . If you decorate a property like this: [JsonProperty(NullValueHandling=NullValueHandling.Ignore)] string MyProp { get; set; } Then if MyProp is null, it won't be included in the output at all. I would like to do something similar, but with a different condition for exclusion. For example - say we have an enum public enum MyEnum { None = 0, Value1 = 1, Value2 = 2, Value3 = 4 }; And a

How do I serialize an array of array-references in Perl?

穿精又带淫゛_ 提交于 2020-01-14 10:43:36
问题 There are so many modules for serializing data for Perl, and I don't know which one to choose. I've the following data that I need to serialize as a string so I can put it in the database: my @categories = ( ["Education", "Higher Education", "Colleges"], ["Schooling", "Colleges"] ); How could I turn it into text, and then later when I need it, turn back into an array of array-references? 回答1: I vote for JSON (or Data::Serializer as mentioned in another answer, in conjunction with JSON ). The

How can I deserialise an XML element into an array of elements with both attributes and text in C#?

▼魔方 西西 提交于 2020-01-14 09:54:08
问题 I am having a problem trying to deserialise this XML: <?xml version="1.0" encoding="UTF-8"?> <links> <link title="ABC">http://abc.co.uk</link> <link title="eBay">http://ebay.co.uk</link> <link title="Best Damn Site on the Web">http://stackoverflow.com</link> </links> Using the code: [XmlRoot("links")] public class LinksInterface { [XmlElement("link")] public List<LinkElement> Links; public class LinkElement { [XmlAttribute("title")] public string Title; [XmlText] // This bit is the

Ignoring a property during deserialization

做~自己de王妃 提交于 2020-01-14 08:44:38
问题 I have a class that is serializing very nicely - finally! Now I want to add a property to this class, that I don't want to be serialized at all. Is it possible to add this new property with some kind of attribute so that when I call serialize or deserialize methods, this property will go unnoticed? 回答1: [XmlIgnore] public int DoNotSerialize { get { ... } set { ... } } 回答2: I think your looking for [XmlIgnore] attribute 来源: https://stackoverflow.com/questions/1198910/ignoring-a-property-during

Boost Serializing of Object containing Map (with object values) and Multimap (with std::string values): what is needed?

孤街醉人 提交于 2020-01-14 08:01:17
问题 See below a main() and two very simple classes. Then per Boost serialization (and what is shown) my questions are: 1) Does class B need the normal overloaded stream insertion operators '<<' and '>>' to be defined? Currently in my real code it doesn't have these. 2) Does class A in the store() and load() methods need to iterate through the map and multimap containers explicitely, storing/loading their key:value pairs explicitely? e.g. something like: void A::store(const char* filename){ std:

Jackson Not Overriding Getter with @JsonProperty

我只是一个虾纸丫 提交于 2020-01-14 07:09:29
问题 JsonProperty isn't overriding the default name jackson gets from the getter. If I serialize the class below with ObjectMapper and jackson I get {"hi":"hello"} As you can see the JsonProperty annotation has no effect class JacksonTester { String hi; @JsonProperty("hello") public String getHi() { return hi; } } Putting @JsonProperty on the String itself doesn't work either. The only way it seems that I can change the name is by renaming the getter, the only problem is that it then will always

Serialization Use Cases [closed]

半城伤御伤魂 提交于 2020-01-14 06:04:49
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . It's not clear to me when should one use serialization / deserialization techniques Can anybody provide me some basic use case scenarios? 回答1: Serialization is the process for turning an object into some kind of encoded representation to move it from one place to another. Usually,

Serializing a Inner Class instance

泪湿孤枕 提交于 2020-01-14 05:38:06
问题 Is it possible to serialize a non Static Inner class? If yes can you provide a good example. I googled through few blogs and sites non of answer convinced me. EDIT: How about the inner class having final staic variable. 回答1: Inner class contains an implicit reference to the outer class, so for an inner class to be serializable its outer class must be as well. Exactly from docs: Serialization of inner classes (i.e., nested classes that are not static member classes), including local and