serialization

serialize/deserialize a list of objects using BinaryFormatter

醉酒当歌 提交于 2019-12-23 20:19:47
问题 I know there were already many discussions on that topic, like this one: BinaryFormatter and Deserialization Complex objects but this looks awfully complicated. What I'm looking for is an easier way to serialize and deserialize a generic List of objects into/from one file. This is what I've tried: public void SaveFile(string fileName) { List<object> objects = new List<object>(); // Add all tree nodes objects.Add(treeView.Nodes.Cast<TreeNode>().ToList()); // Add dictionary (Type: Dictionary

Serializing std::vector of unique_ptr using boost::serialization fails on linux

≯℡__Kan透↙ 提交于 2019-12-23 20:16:35
问题 I am encountering an issue with using boost serialization of a std::vector of std::unique_ptr's. The type of the unique_ptr does not matter, and in the below example, integers are used: #include <boost/serialization/unique_ptr.hpp> #include <boost/serialization/vector.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/archive/xml_oarchive.hpp> #include <fstream> namespace boost { namespace serialization { template <class Archive> void serialize(Archive& ar, std::vector<unique_ptr

protobuf-net and serializing a linked list using interfaces

守給你的承諾、 提交于 2019-12-23 20:14:36
问题 I have come across a problem with protobuf-net and have narrowed it down to this simplest case. I want a linked list type structure, where a class has a property of the same type. When I serialize this it works great. However if the type is an interface instead of a class I get the following error: The type cannot be changed once a serializer has been generated for ConsoleApplication1.foo (ConsoleApplication1.ifoo) This is the code I have to generate this error: class Program { static void

How do I properly serialize and deserialize a QList class in QT using QDatastream?

眉间皱痕 提交于 2019-12-23 19:48:34
问题 I am trying to serialize a custom class Layer* and read it back using QDataStream. Now, Layer is an abstract class with virtual method which is inherited by different kinds of layers: RasterLayer , TextLayer , AdjustmentLayer etc. I have a QList<Layer*> layers which keeps track of all the layers, and any adjustments made to a layer are updated in the list. I need to serialize and deserialize the QList to its original state and restore the properties of the individual layers (of different

Is java's File class' object serializable?

自闭症网瘾萝莉.ら 提交于 2019-12-23 19:14:45
问题 I am working on a project, it requires to send directory information from one client to another on a network. so tell me, can i get this information on another client by only sending File class' object? please explain me the reason for your YES or NO. Updated Question i am posting the code which i have tried.... The Client Code:- public class FileClient{ public static void main(String str[]){ try{ Socket sock = new Socket("10.16.10.82",4000); /* Socket sock = new Socket("127.0.0.1",4000); */

Why can't the compiler detect this error regarding Serializable declaration at compile time?

强颜欢笑 提交于 2019-12-23 19:13:27
问题 From second paragraph of JavaDoc of Serializable interface : To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error

How to serialize / deserialize a Option<> class (functional java) with JSON?

旧城冷巷雨未停 提交于 2019-12-23 19:08:41
问题 I used Class Option in java as a replacement for the use of null with better type checks. http://functionaljava.googlecode.com/svn/artifacts/2.20/javadoc/fj/data/Option.html My question is how to serialize / deserialize my following code in JSON ? public Option<? extends ClassA> a; The result of serialization by using ObjectMapper is always: "a" : [ "Option$Some", { "none" : false, "some" : true } ] and the deserialization does not work. Thanks for any reponse. p/s: i paste my full code is as

WCF Services and Object Constructors

折月煮酒 提交于 2019-12-23 19:08:22
问题 I am just learning WCF services. I have a method that returns an object I created called GPSPosition. A GPS Position object has a Latitude and a Longitude. The object should never really exist without these properties.. So, I want to have the constructor accept the Lat and Long floats. So when the object is created, the values are set, and can never be invalid (Unset). But, it's an object of my WCF service. Can as WCF service object, that my calling application uses, have a constructor? If I

Storing unpicklabe pygame.Surface objects in external files

倖福魔咒の 提交于 2019-12-23 19:05:32
问题 So I've got a problem - I'm writing a game prototype in Python, using Pygame, and I want to save my games. All of the game-related data is in three instances of certain classes, and I want to save these three instances to a file. However, I've tried pickling these instances, and it doesn't work. Instead, I get "TypeError: can't pickle Surface objects". This is a problem, because I want to store Surface objects. I'm open to any alternatives to pickling that there may be, using any other kind

Inserting into a serialized array in PHP

廉价感情. 提交于 2019-12-23 18:46:58
问题 This is my first time here and I have been pulling my hair out over this one, so I thought it would be a good first question for me. I am saving some array data to a mysql database, and then later I am using unserialize to edit it. The problem is that it blanks out every other index in the array when I edit just one index. Here is some example code: foreach($post as $key => $value) { if (isset($row)) { if ($i > 2) { $tempArray = unserialize($row[$i]); } } $tempArray[$time] = $value; if ($key