How do you do a deep copy of an object in .NET? 

Important Note BinaryFormatter has been deprecated, and will no longer be available in .NET after November 2023. See BinaryFormatter Obsoletion Strategy I’ve seen a few different approaches to this, but I use a generic utility method as such: Notes: Your class MUST be marked as [Serializable] for this to work. Your source file must include the following code: using … Read more

What is object serialization?

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialized – converted into a replica of the original object.

XmlSerializer – There was an error reflecting type

Look at the inner exception that you are getting. It will tell you which field/property it is having trouble serializing. You can exclude fields/properties from xml serialization by decorating them with the [XmlIgnore] attribute. XmlSerializer does not use the [Serializable] attribute, so I doubt that is the problem.

How to serialize an object into a string

Sergio: You should use BLOB. It is pretty straighforward with JDBC. The problem with the second code you posted is the encoding. You should additionally encode the bytes to make sure none of them fails. If you still want to write it down into a String you can encode the bytes using java.util.Base64. Still you should use … Read more

Task not serializable: java.io.NotSerializableException when calling function outside closure only on classes not objects

RDDs extend the Serialisable interface, so this is not what’s causing your task to fail. Now this doesn’t mean that you can serialise an RDD with Spark and avoid NotSerializableException Spark is a distributed computing engine and its main abstraction is a resilient distributed dataset (RDD), which can be viewed as a distributed collection. Basically, RDD’s elements are … Read more

JSON.NET Error Self referencing loop detected for type

That was the best solution https://docs.microsoft.com/en-us/archive/blogs/hongyes/loop-reference-handling-in-web-api Fix 1: Ignoring circular reference globally (I have chosen/tried this one, as have many others) The json.net serializer has an option to ignore circular references. Put the following code in WebApiConfig.cs file: The simple fix will make serializer to ignore the reference which will cause a loop. However, it … Read more

Is it possible to serialize and deserialize a class in C++?

The Boost::serialization library handles this rather elegantly. I’ve used it in several projects. There’s an example program, showing how to use it, here. The only native way to do it is to use streams. That’s essentially all the Boost::serialization library does, it extends the stream method by setting up a framework to write objects to a text-like format and read … Read more

Print array to a file

Either var_export or set print_r to return the output instead of printing it. Example from PHP manual You can then save $results with file_put_contents. Or return it directly when writing to file: