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
456
votes
29 answers

Converting between strings and ArrayBuffers

Is there a commonly accepted technique for efficiently converting JavaScript strings to ArrayBuffers and vice-versa? Specifically, I'd like to be able to write the contents of an ArrayBuffer to localStorage and then read it back.
kpozin
  • 25,691
  • 19
  • 57
  • 76
452
votes
17 answers

Gson: How to exclude specific fields from Serialization without annotations

I'm trying to learn Gson and I'm struggling with field exclusion. Here are my classes public class Student { private Long id; private String firstName = "Philip"; private String middleName …
Liviu T.
  • 23,584
  • 10
  • 62
  • 58
424
votes
15 answers

What is object serialization?

What is meant by "object serialization"? Can you please explain it with some examples?
Warrior
  • 39,156
  • 44
  • 139
  • 214
407
votes
12 answers

Convert a python dict to a string and back

I am writing a program that stores data in a dictionary object, but this data needs to be saved at some point during the program execution and loaded back into the dictionary object when the program is run again. How would I convert a dictionary…
AJ00200
  • 16,327
  • 7
  • 23
  • 21
377
votes
7 answers

What is [Serializable] and when should I use it?

I found out that some classes use the [Serializable] attribute. What is it? When should I use it? What kinds of benefits will I get?
kevin
  • 13,559
  • 30
  • 79
  • 104
376
votes
10 answers

How do I save a trained model in PyTorch?

How do I save a trained model in PyTorch? I have read that: torch.save()/torch.load() is for saving/loading a serializable object. model.state_dict()/model.load_state_dict() is for saving/loading model state.
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
369
votes
19 answers

XmlSerializer - There was an error reflecting type

Using C# .NET 2.0, I have a composite data class that does have the [Serializable] attribute on it. I am creating an XMLSerializer class and passing that into the constructor: XmlSerializer serializer = new XmlSerializer(typeof(DataClass)); I am…
leora
  • 188,729
  • 360
  • 878
  • 1,366
364
votes
6 answers

Saving an Object (Data persistence)

I've created an object like this: company1.name = 'banana' company1.value = 40 I would like to save this object. How can I do that?
Peterstone
  • 7,119
  • 14
  • 41
  • 49
363
votes
6 answers

.NET NewtonSoft JSON deserialize map to a different property name

I have following JSON string which is received from an external party. { "team":[ { "v1":"", "attributes":{ "eighty_min_score":"", "home_or_away":"home", "score":"22", …
RasikaSam
  • 5,363
  • 6
  • 28
  • 36
358
votes
3 answers

How to deserialize a JObject to .NET object

I happily use the Newtonsoft JSON library. For example, I would create a JObject from a .NET object, in this case an instance of Exception (might or might not be a subclass) if (result is Exception) var jobjectInstance =…
Sebastian
  • 6,293
  • 6
  • 34
  • 47
358
votes
11 answers

Serialize an object to string

I have the following method to save an Object to a file: // Save an object out to the disk public static void SerializeObject(this T toSerialize, String filename) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); …
Vaccano
  • 78,325
  • 149
  • 468
  • 850
328
votes
12 answers

Java Serializable Object to Byte Array

Let's say I have a serializable class AppMessage. I would like to transmit it as byte[] over sockets to another machine where it is rebuilt from the bytes received. How could I achieve this?
iTEgg
  • 8,212
  • 20
  • 73
  • 107
321
votes
10 answers

converting Java bitmap to byte array

Bitmap bmp = intent.getExtras().get("data"); int size = bmp.getRowBytes() * bmp.getHeight(); ByteBuffer b = ByteBuffer.allocate(size); bmp.copyPixelsToBuffer(b); byte[] bytes = new byte[size]; try { b.get(bytes, 0,…
Tom Fobear
  • 6,729
  • 7
  • 42
  • 74
319
votes
13 answers

IntelliJ IDEA generating serialVersionUID

How do generate this value in IntelliJ IDEA? I go to Settings -> Errors -> Serialization issues -> Serializable class without ‘serialVersionUID’, but it still doesn't show me the warning. My class PKladrBuilding parent implements interface…
user1679671
314
votes
15 answers

Biggest differences of Thrift vs Protocol Buffers?

What are the biggest pros and cons of Apache Thrift vs Google's Protocol Buffers?
Bob