serialization

boost serialize polymorphic class

£可爱£侵袭症+ 提交于 2020-01-02 09:13:17
问题 With the following example I attempting to learn a few new to me concepts. abstraction polymorphic classes factory programming. boost serialization The nuances of how pointers behave are still something I am working to figure out. Here is a small program that I have written to show you the issue I am struggling to understand. When I unserialize the polymorphic object below I only get an object created from the default constructor. TodoFactory::retrieveATodo is not recreating the object from

boost serialize polymorphic class

喜夏-厌秋 提交于 2020-01-02 09:13:12
问题 With the following example I attempting to learn a few new to me concepts. abstraction polymorphic classes factory programming. boost serialization The nuances of how pointers behave are still something I am working to figure out. Here is a small program that I have written to show you the issue I am struggling to understand. When I unserialize the polymorphic object below I only get an object created from the default constructor. TodoFactory::retrieveATodo is not recreating the object from

Deserializing child nodes outside of parent's namespace using XmlSerializer.Deserialize() in C#

时光怂恿深爱的人放手 提交于 2020-01-02 08:49:09
问题 I have an application that uses namespaces to help deserialize objects stored in XML. The XML namespace is also the C# namespace where the object resides. For example, given the following XML snip: <xml-config xmlns:app="MyAppNS"> <app:Person> <Name>Bill</Name> <Car> <Make>Honda</Make> <Model>Accord</Model> </Car> </app:Person> <app:Person> <Name>Jane</Name> <Car> <Make>VW</Make> <Model>Jetta</Model> </Car> </app:Person> <app:Car> <Make>Audi</Make> <Model>A6</Model> </app:Car> </xml-config>

Adding a DataMember to a different namespace to the DataContract

て烟熏妆下的殇ゞ 提交于 2020-01-02 08:26:30
问题 With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

Adding a DataMember to a different namespace to the DataContract

自作多情 提交于 2020-01-02 08:25:41
问题 With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

Why default constructor is not called while deserialization process?

三世轮回 提交于 2020-01-02 08:00:31
问题 ObjectInputStream is = new ObjectInputStream(new FileInputStream("test.ser")); TestClass tc = (TestClass)is.readObject(); I get the object of TestClass after deserialization but TestClass default constructor is not called. As per my understanding there are two ways to create object i.e either with new operator or TestClass.class.newInstance(). Both calls the default constructor. Looks like deserialization process creates the object not with about two methods thats why default constructor is

Save objects into JSON or XML file in Python

那年仲夏 提交于 2020-01-02 07:53:12
问题 I create objects (using tkinter widgets) that I wish to save in a JSON or XML file, so that I can recover them after startup. from Tkinter import * class Texte: def __init__(self, ax, ay, txt): self.entry = Entry(root,bd=0,font=("Purisa",int(15))) self.entry.insert(0, txt) self.x = ax self.y = ay self.entry.place(x=self.x,y=self.y) root = Tk() a = Texte(10, 20, 'blah') b = Texte(20, 70, 'blah2') # here the user will modify the entries' x, y, txt, etc. L = [a,b] # here save the list L

Object graph serialization in .NET and code version upgrades

丶灬走出姿态 提交于 2020-01-02 07:53:10
问题 I need to serialize some object graphs to disc What difficulties am I likely to encounter if I make changes to a class, then try to deserialize an old version? Do some serializers handle this better than others? What is the standard way of handling such a scenario? For example, in a new version of the code, do I need to retain all the old classes so that when deserializing an old file i can do so to the old class, then migrate the data to the new class? Will changing the class' name/namespace

Jackson Serialize Field to Different Name

痞子三分冷 提交于 2020-01-02 07:51:21
问题 I have this JSON to deserialize: { "first-name": "Alpha", "last-name": "Beta", "gender": "m" } I want to serialize it to 2 different formats: [A] { "first-name": "Alpha", "last-name": "Beta", "gender": "m" } [B] { "firstName": "Alpha", "lastName": "Beta", "gender": "m" } I'm able to serialize it to 1 format: [A] only or [B] only. Here's my code to serialize it to [B]: public String firstName; public String lastName; public String gender; @JsonProperty("firstName") public String getFirstNameCC

How can I build XmlDocument with many xml namespaces in a single node?

落花浮王杯 提交于 2020-01-02 07:17:27
问题 I'm trying to build XmlDocument so that after serialization I could achieve something like this xml: <?xml version="1.0" encoding="UTF-8"?> <wnio:element xmlns:wnio="somuri" xmlns:xf="abcd"> <xf:nestedelement>somtext</xf:nestedelement> </wnio:element> The things is that XmlElement allows to specify ONLY ONE namespace via NamespaceURI and Prefix properties. How can I accomplish this kind of functionality? 回答1: The attributes "xmlns:wnio" and "xmlns:xf" are attributes like any other. Simply add