Android – SharedPreferences with serializable object

The accepted answer is misleading, we can store serializable object into SharedPreferences by using GSON. Read more about it at google-gson. you can add GSON dependency in Gradle file with: compile ‘com.google.code.gson:gson:2.7’ Here the snippet: First, create your usual sharedPreferences: //Creating a shared preference SharedPreferences mPrefs = getPreferences(MODE_PRIVATE); Saving from serializable object to preference: Editor … Read more

How to globally set default options for System.Text.Json.JsonSerializer?

You can create an extension method. Here’s an example I use separate methods vs having to build special settings, so that all the settings will be in a single spot and easily reusable. public static class DeserializeExtensions { private static JsonSerializerOptions defaultSerializerSettings = new JsonSerializerOptions(); // set this up how you need to! private static … Read more

How to serialize a large graph of .NET objects into a SQL Server BLOB without creating a large buffer?

There is no built-in ADO.Net functionality to handle this really gracefully for large data. The problem is two fold: there is no API to ‘write’ into a SQL command(s) or parameters as into a stream. The parameter types that accept a stream (like FileStream) accept the stream to READ from it, which does not agree … Read more

JSON.NET StackOverflowException while serialization

The reason you are getting the stackoverflow exception is that Json.NET is a recursive, single-pass tree or graph serializer that, when PreserveReferencesHandling.Objects is enabled, always serializes the first occurrence of each object. You have constructed your 15,000 element Chacha [] array so that the first entry is the head of a linked list containing all … Read more

JSON.NET Serializes Empty JSON

As stated by Newtonsoft in this issue, MetadataTypeAttribute attributes are in fact supported by Json.NET. However, it appears that Json.NET requires that the MetadataClassType members must be properties when the corresponding “real” members are properties, and fields when the corresponding “real” members are fields. Thus, if I define your Plant type as follows, with two … Read more

GSON does not deserialize reference to outer class

As Gson documentation says: Gson can serialize static nested classes quite easily. Gson can also deserialize static nested classes. However, Gson can not automatically deserialize the pure inner classes since their no-args constructor also need a reference to the containing Object which is not available at the time of deserialization. You can address this problem … Read more

how to do performance test using the boost library for a custom library

Okay, so I added serialization to the types (why did you leave it out?) struct X { int p; double q; private: friend boost::serialization::access; template <typename Ar> void serialize(Ar& ar, unsigned) { ar & BOOST_SERIALIZATION_NVP(p); ar & BOOST_SERIALIZATION_NVP(q); } }; struct Y { float m; double n; private: friend boost::serialization::access; template <typename Ar> void serialize(Ar& … Read more

How to marshall a string using JAXB that sometimes contains XML content and sometimes does not?

Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group. This use case is mapped using the @XmlAnyElement annotation and specifying a DOMHandler. There appears to be bug when doing this with the JAXB RI, but the following use case works with EclipseLink JAXB (MOXy). BodyDomHandler By default a … Read more