Pass Serializable Object to Pending Intent

There are known issues with putting custom objects into an Intent that is then passed to AlarmManager or NotificationManager or other external applications. You can try to wrap your custom object in a Bundle, as this will sometimes work. For example, change your code to: Intent myIntent = new Intent(getApplicationContext(), AlarmAlertBroadcastReciever.class); Bundle bundle = new … Read more

Get private data members for non intrusive boost serialization C++

You can use good old-fashioned friends: Live On Coliru template <typename T> class A { public: A(const T &id) : m_id(id) {} private: template <typename Ar, typename U> friend void boost::serialization::serialize(Ar&,A<U>&,const unsigned); T m_id; }; namespace boost { namespace serialization { template <class Archive, typename T> void serialize(Archive &ar, A<T> &a, const unsigned int) { … Read more

Serializing dictionaries with JavaScriptSerializer

Although I agree that JavaScriptSerializer is a crap and Json.Net is a better option, there is a way in which you can make JavaScriptSerializer serialize the way you want to. You will have to register a converter and override the Serialize method using something like this: public class KeyValuePairJsonConverter : JavaScriptConverter { public override object … Read more

Configure Json.NET serialization settings on a class level

If you’re using Json.NET 9.0.1 or later you can use the NamingStrategyType property on the JsonObjectAttribute to achieve what you want. If you need to pass arguments to the NamingStrategy‘s constructor then specify them with the NamingStrategyParameters property. Below is an example of how to specify a class with a camel case naming strategy. [JsonObject(NamingStrategyType … Read more

Saving content of a treeview to a file and load it later

You can use BinaryFormatter to Serialize/Deserialize Nodes public static void SaveTree(TreeView tree, string filename) { using (Stream file = File.Open(filename, FileMode.Create)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList()); } } public static void LoadTree(TreeView tree, string filename) { using (Stream file = File.Open(filename, FileMode.Open)) { BinaryFormatter bf = new BinaryFormatter(); object obj = bf.Deserialize(file); … Read more

Json Encoder AND Decoder for complex numpy arrays

Here is my final solution that was adapted from hpaulj’s answer, and his answer to this thread: https://stackoverflow.com/a/24375113/901925 This will encode/decode arrays that are nested to arbitrary depth in nested dictionaries, of any datatype. import base64 import json import numpy as np class NumpyEncoder(json.JSONEncoder): def default(self, obj): “”” if input object is a ndarray it … Read more