using XmlArrayItem attribute without XmlArray on Serializable C# class

The following should serialize properly the way you want. The clue being [XmlElement(“credentials”)] on the list. I did this by taking your xml, generating a schema (xsd) from it in Visual Studio. Then running xsd.exe on the schema to generate a class. (And some small edits) public class CredentialsSection { public string Username { get; … Read more

What is the point of the ISerializable interface?

ISerializable is used to provide custom binary serialization, usually for BinaryFormatter (and perhaps for remoting purposes). Without it, it uses the fields, which can be: inefficient; if there are fields that are only used for efficiency at runtime, but can be removed for serialization (for example, a dictionary may look different when serialized) inefficient; as … Read more

Why should I always make my Exceptions [serializable]? (.NET)

Because your exceptions may need to be marshalled between different AppDomains and if they aren’t (properly) serializable you will lose precious debugging information. Unlike other classes, you won’t have control over whether your exception will be marshalled — it will. When I mean “you won’t have control” I mean that classes you create generally have … Read more

Is using Serializable in Android bad?

For in-memory use, Parcelable is far, far better than Serializable. I strongly recommend not using Serializable. You can’t use Parcelable for data that will be stored on disk (because it doesn’t have good guarantees about data consistency when things change), however Serializable is slow enough that I would strongly urge not using it there either. … Read more

Android ArrayList of custom objects – Save to SharedPreferences – Serializable?

Yes, you can save your composite object in shared preferences. Let’s say.. Student mStudentObject = new Student(); SharedPreferences appSharedPrefs = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); Editor prefsEditor = appSharedPrefs.edit(); Gson gson = new Gson(); String json = gson.toJson(mStudentObject); prefsEditor.putString(“MyObject”, json); prefsEditor.commit(); ..and now you can retrieve your object as: SharedPreferences appSharedPrefs = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); Gson gson = new … Read more

What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]

From the javadoc: The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the … Read more

What does Serializable mean?

Serialization is persisting an object from memory to a sequence of bits, for instance for saving onto the disk. Deserialization is the opposite – reading data from the disk to hydrate/create an object. In the context of your question, it is an interface that if implemented in a class, this class can automatically be serialized … Read more

Serializing private member data

You could use DataContractSerializer (but note you can’t use xml attributes – only xml elements): using System; using System.Runtime.Serialization; using System.Xml; [DataContract] class MyObject { public MyObject(Guid id) { this.id = id; } [DataMember(Name=”Id”)] private Guid id; public Guid Id { get {return id;}} } static class Program { static void Main() { var ser … Read more

tech