serialization

Is ISerializable backwards-compatible with previous versions of classes with fewer fields?

血红的双手。 提交于 2019-12-20 06:04:26
问题 Sorry if I've worded the question a bit odd! Basically, I have a serializable class that has a single field at this current time, but will definitely gain more in the future as we add features to the system. The serialization process will be used for both passing instances to a WCF service, and for reading/writing it from/to file. Of course, the latter may be a big problem if I'm continually updating the class with extra fields. Luckily, I think I've solved the problem by adding a try/catch

Avro schema for Json array

。_饼干妹妹 提交于 2019-12-20 05:37:28
问题 Suppose I have following json: [ {"id":1,"text":"some text","user_id":1}, {"id":1,"text":"some text","user_id":2}, ... ] What would be an appropriate avro schema for this array of objects? 回答1: [short answer] The appropriate avro schema for this array of objects would look like: const type = avro.Type.forSchema({ type: 'array', items: { type: 'record', fields: [ { name: 'id', type: 'int' }, { name: 'text', type: 'string' }, { name: 'user_id', type: 'int' } ] } }); [long answer] We can use

Deep cloning an object : Clone vs Serialize

安稳与你 提交于 2019-12-20 05:36:06
问题 I have this function duplicateCourseAction whose goal is to ... duplicate a Course object public function duplicateCourseAction(Request $request) { if ($this->getRequest()->isXmlHttpRequest() == false) { return new Response("Bad request", 405); } $em = $this->getDoctrine()->getManager(); $parameters = $request->request->all(); $course = $em->getRepository('EntTimeBundle:Course')->findOneById($parameters['id']); $duplicate = clone $course; $duplicate->setDate(new \DateTime($parameters['date'])

C# XML Serialization/Deserialization

余生长醉 提交于 2019-12-20 05:28:53
问题 I am brand new to C#. I'm taking a class on it right now, and one of our class examples wont compile. Visual Studio 2010 gives me this error: There is an error in XML document (3, 2). How should I edit the XML file to make it work with the code? Thank you for your help! public class SerializeIn { public static void Main() { // Declarations. Person[] p = new Person[0]; string infile = "Persons.xml"; StreamReader sr = new StreamReader(infile); XmlSerializer xs = new XmlSerializer(p.GetType());

BinaryFormatter for serialization

白昼怎懂夜的黑 提交于 2019-12-20 05:27:07
问题 I am working on my own remote desktop C# program. I wondered if I could Serialize using BinaryFormatter an object of my own for example "Packet" that contains properties of BitMap screenshot, mouse cordinates and maybe some text. And then the client would deserialize it. Theoretically it might be a comfortable way to do this. Is it possible? 回答1: BinaryFormatter is not a good choice for serialization over the network or to persistent storage, it is designed for serialization when you are

How to serialize boost::rational

核能气质少年 提交于 2019-12-20 05:26:29
问题 I cannot serialize boost::rational<int> . I searched for a boost/serialize/rational.h header but it does not exist. /usr/include/boost/serialization/access.hpp:118:9: error: ‘class boost::rational<int>’ has no member named ‘serialize’ Is there a way to achieve it? 回答1: Just serialize the numerator and denominator. Here's the legwork, in semi-generic form (supports archives with named nodes, like XML serialization, too): Live On Coliru #include <boost/archive/xml_iarchive.hpp> #include <boost

XML serialization of interfaces

风格不统一 提交于 2019-12-20 05:14:10
问题 I need to serialize complex objects in my project and put them in a database. I'd like to serialize them using XML for obtain a easier debugging of my application. My case is very similar to what is described in this article: http://geekswithblogs.net/SoftwareDoneRight/archive/2008/01/16/how-to-serialize-an-interface-using-the-xmlserializer.aspx So I have an object containing a Property which type is defined by an interface. Then I have different concrete types implementing it. Following the

Boost serialize child class

江枫思渺然 提交于 2019-12-20 04:56:17
问题 I have base class User which is serializable : class User { public: User(); std::string GetLogin() const; void SetLogin(std::string login); protected: std::string mLogin; friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & mLogin; } }; This class can be inherited by other class like this : class UserA : public User { UserA(); private: friend class boost::serialization::access; template<class Archive> void serialize

Getting NotSerializableException on a serializable object

回眸只為那壹抹淺笑 提交于 2019-12-20 04:51:48
问题 Basically, I've written a program that paints shapes onto the screen, and saves each of the shapes into an ArrayList. What I want to do is figure out how to save the ArrayList to a file, so that I can call it back up later and edit the already existing shapes. So I've been having some trouble figuring out why exactly I keep getting a NotSerializableException when I made the object Shape serializable already. Below is the save portion of my code, and the Shape object. save.addActionListener

jaxrs could not find my custom (de)serializers for joda.money type

放肆的年华 提交于 2019-12-20 04:51:33
问题 I have written my custom (de)serializer for joda.money.Money type. I register them with Object Mapper. But when I deploy my war file, it says could not find serializers for joda.money.Money type. import org.joda.money.Money; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; public class MoneyDeserializer extends