serialization

How to implement Serializable?

让人想犯罪 __ 提交于 2019-12-21 07:00:16
问题 How should I implement the Serializable interface? I have a class Student , and need to be able to save it to disk. For my homework, I have to serialize five different Student objects and save them to file. class Student { String mFirstName; String mSecondName; String mPhoneNumber; String mAddress; String mCity; Student(final String pFirstName, final String pSecondName, final String pPhoneNumber, final String pAddress, final String pCity){ this.mFirstName = pFirstName; this.mSecondName =

Serialize C# Enum Definition to Json

懵懂的女人 提交于 2019-12-21 06:51:04
问题 Given the following in C#: [Flags] public enum MyFlags { None = 0, First = 1 << 0, Second = 1 << 1, Third = 1 << 2, Fourth = 1 << 3 } Are there any existing methods in ServiceStack.Text for serializing to the following JSON? { "MyFlags": { "None": 0, "First": 1, "Second": 2, "Third": 4, "Fourth": 8 } } Currently I'm using the routine below, are there better ways to do this? public static string ToJson(this Type type) { var stringBuilder = new StringBuilder(); Array values = Enum.GetValues

Json string deserialized to array list of objects

吃可爱长大的小学妹 提交于 2019-12-21 06:45:01
问题 Please help! Getting this error on Deserializing: Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List' JSON string from client: "\"[{\\"id\\":\\"18_0_2_0\\",\\"ans\\":\\"You can enter free text in place of * \\"},{\\"id\\":\\"23_1_3_1\\",\\"ans\\":\\"The refresh button\\"},{\\"id\\":\\"11_2_1_2\\",\\"ans\\":\\"False\\"}]\"" Edit: Unescaped (see comments): [{"id":"18_0_2_0","ans":"You can enter free text in place of * "},{"id":"11_2_1_2","ans":"False"}]

Json string deserialized to array list of objects

旧城冷巷雨未停 提交于 2019-12-21 06:43:15
问题 Please help! Getting this error on Deserializing: Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List' JSON string from client: "\"[{\\"id\\":\\"18_0_2_0\\",\\"ans\\":\\"You can enter free text in place of * \\"},{\\"id\\":\\"23_1_3_1\\",\\"ans\\":\\"The refresh button\\"},{\\"id\\":\\"11_2_1_2\\",\\"ans\\":\\"False\\"}]\"" Edit: Unescaped (see comments): [{"id":"18_0_2_0","ans":"You can enter free text in place of * "},{"id":"11_2_1_2","ans":"False"}]

How to serialize big objects in .NET? (OutOfMemory Exceptions)

非 Y 不嫁゛ 提交于 2019-12-21 06:20:48
问题 I'm using serialization for "save" feature in my application. But when the data is too big (15+ MB) I'm starting to get OutOfMemory exceptions. I've got so many objects and they are connected with other little objects, I think this is causing too much processing power and data held in the memory. My code is based on this, almost same: http://www.codeproject.com/KB/vb/TreeViewDataAccess.aspx Edit : I don't use custom serialization, it's all done by [Serialization] attributes. Excluding some

Unit Testing serializability for all classes in java project

北慕城南 提交于 2019-12-21 05:42:06
问题 I've thousands of classes in our java project. Some of them implements serializable interface. Now here's a problem. It's possible someone can go in a class, add new variable that is neither transient nor serializable. Code compiles fine however process would blow up at runtime. To illustrate this class Foo implements Serializable { .... // all good } class Foo implements Serializable { // OOps, executorService is not serializable. It's not declared as transient either private ExecutorService

Boost serialization in Qt: is it a proper way?

别说谁变了你拦得住时间么 提交于 2019-12-21 05:41:08
问题 I'm thinking about serializing data in an application which is Qt-based. Essentially what I'm going to serialize is my hierarchical model, which is composed of different classes that derive from, say, TreeModelItem: class TreeModelItem { protected: QList<TreeModelItem *> m_children; //... }; Should I study boost::serialization and go on with it? Is there any hidden wall I can hit by the way? E.g. while (de)serializing child elements, or when restoring custom singal-slot connections? I hope

XML to/from a Python dictionary

浪尽此生 提交于 2019-12-21 05:39:16
问题 I need to use Python 2.4.4 to convert XML to and from a Python dictionary. All I need are the node names and values, I'm not worried about attributes because the XML I'm parsing doesn't have any. I can't use ElementTree because that isn't available for 2.4.4, and I can't use 3rd party libraries due to my work environment. What's the easiest way for me to do this? Are there any good snippets? Also, if there isn't an easy way to do this, are there any alternative serialization formats that

Ember-data: deserialize embedded model

拥有回忆 提交于 2019-12-21 05:35:33
问题 I really don't get it here... I have the following code: App.Instance = DS.Model.extend({ hash: DS.attr('string'), users: DS.hasMany('user', { embedded: 'always' }) }); App.User = DS.Model.extend({ name: DS.attr('string'), color: DS.attr('string'), lat: DS.attr('number'), lng: DS.attr('number'), instance: DS.belongsTo('instance') }); App.InstanceSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { users: { embedded: 'always' } } }); And instance like so: var instance = {

MongoDb custom collection serializer

◇◆丶佛笑我妖孽 提交于 2019-12-21 05:29:27
问题 I have four simple classes public class Zoo{ public ObjectId Id { get; set; } public List<Animal> Animals { get; set; } } public class Animal{ public ObjectId Id { get; set; } public string Name { get; set; } } public class Tiger : Animal{ public double Height { get; set; } } public class Zebra : Animal{ public long StripesAmount { get; set; } } I have created the custom serializer which allows me to store Animal object in a distinct collection ("animals"). class MyAnimalSerializer :