Questions tagged [serialization]

Serialization is the process by which data-structures are converted into a format that can be easily stored or transmitted and subsequently reconstructed.

Serialization is the process of converting a or object's state into a format that can be stored (for example, in a flat file or memory ) or transmitted over a network, to be reconstructed later maintaining data integrity - typically in a different run-time environment which may or may not be on the same computer.

The process of serializing an object is sometimes referred to as - however depending on the context / language this term may take on a slightly different meaning. The process of reconstructing a data structure from its serialized form is known as .

Popular formats for serialization are and .

33160 questions
309
votes
9 answers

Django rest framework, use different serializers in the same ModelViewSet

I would like to provide two different serializers and yet be able to benefit from all the facilities of ModelViewSet: When viewing a list of objects, I would like each object to have an url which redirects to its details and every other relation…
BlackBear
  • 22,411
  • 10
  • 48
  • 86
301
votes
21 answers

How to get string objects instead of Unicode from JSON

I'm using Python 2 to parse JSON from ASCII encoded text files. When loading these files with either json or simplejson, all my string values are cast to Unicode objects instead of string objects. The problem is, I have to use the data with some…
Brutus
  • 7,139
  • 7
  • 36
  • 41
294
votes
8 answers

What is the correct way to make a custom .NET Exception serializable?

More specifically, when the exception contains custom objects which may or may not themselves be serializable. Take this example: public class MyException : Exception { private readonly string resourceName; private readonly IList
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
294
votes
12 answers

What is the difference between Serializable and Externalizable in Java?

What is the difference between Serializable and Externalizable in Java?
Sasha
288
votes
4 answers

What is deserialize and serialize in JSON?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
257
votes
16 answers

Convert Dictionary to JSON in Swift

I have create the next Dictionary: var postJSON = [ids[0]:answersArray[0], ids[1]:answersArray[1], ids[2]:answersArray[2]] as Dictionary and I get: [2: B, 1: A, 3: C] So, how can I convert it to JSON?
Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79
257
votes
3 answers

Python - json without whitespaces

I just realized that json.dumps() adds spaces in the JSON object e.g. {'duration': '02:55', 'name': 'flower', 'chg': 0} how can remove the spaces in order to make the JSON more compact and save bytes to be sent via HTTP? such…
Daniele B
  • 19,801
  • 29
  • 115
  • 173
256
votes
11 answers

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

Getting strange behavior when calling function outside of a closure: when function is in a object everything is working when function is in a class get : Task not serializable: java.io.NotSerializableException: testing The problem is I need my…
Nimrod007
  • 9,825
  • 8
  • 48
  • 71
256
votes
17 answers

Serializing class instance to JSON

I am trying to create a JSON string representation of a class instance and having difficulty. Let's say the class is built like this: class testclass: value1 = "a" value2 = "b" A call to the json.dumps is made like this: t =…
ferhan
  • 2,639
  • 2
  • 14
  • 9
254
votes
9 answers

Converting Stream to String and back

I want to serialize objects to strings, and back. We use protobuf-net to turn an object into a Stream and back, successfully. However, Stream to string and back... not so successful. After going through StreamToString and StringToStream, the new…
flipuhdelphia
  • 2,543
  • 2
  • 12
  • 5
247
votes
9 answers

C#: Printing all properties of an object

Is there a method built into .NET that can write all the properties and such of an object to the console? One could make use of reflection of course, but I'm curious if this already exists...especially since you can do it in Visual Studio in the…
Svish
  • 152,914
  • 173
  • 462
  • 620
236
votes
12 answers

Parcelable encountered IOException writing serializable object getactivity()

so I am getting this in logcat: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list.Student) I know this means that my student class is not serializable, but it is, here is…
user2896762
  • 2,427
  • 3
  • 13
  • 12
229
votes
13 answers

How do I copy a hash in Ruby?

I'll admit that I'm a bit of a ruby newbie (writing rake scripts, now). In most languages, copy constructors are easy to find. Half an hour of searching didn't find it in ruby. I want to create a copy of the hash so that I can modify it without…
Precipitous
  • 5,253
  • 4
  • 28
  • 34
229
votes
4 answers

How to generate serial version UID in Intellij

When I used Eclipse it had a nice feature to generate serial version UID. But what to do in IntelliJ? How to choose or generate identical serial version UID in IntelliJ? And what to do when you modify old class? If you haven't specify the id, it is…
catch23
  • 17,519
  • 42
  • 144
  • 217
228
votes
10 answers

Why generate long serialVersionUID instead of a simple 1L?

When class implements Serializable in Eclipse, I have two options: add default serialVersionUID(1L) or generated serialVersionUID(3567653491060394677L). I think that first one is cooler, but many times I saw people using the second option. Is there…
IAdapter
  • 62,595
  • 73
  • 179
  • 242