33,544 questions
3478
votes
25
answers
1.2m
views
What is a serialVersionUID and why should I use it?
Eclipse issues warnings when a serialVersionUID is missing.
The serializable class Foo does not declare a static final
serialVersionUID field of type long
What is serialVersionUID and why is it ...
1771
votes
58
answers
1.1m
views
Convert form data to JavaScript object with jQuery
How do I convert all elements of my form to a JavaScript object?
I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do ...
1288
votes
15
answers
2.3m
views
How do I turn a C# object into a JSON string in .NET?
I have classes like these:
class MyDate
{
int year, month, day;
}
class Lad
{
string firstName;
string lastName;
MyDate dateOfBirth;
}
And I would like to turn a Lad object into a ...
1236
votes
11
answers
933k
views
Serializing to JSON in jQuery [duplicate]
I need to serialize an object to JSON. I'm using jQuery. Is there a "standard" way to do this?
My specific situation: I have an array defined as shown below:
var countries = new Array();
countries[0]...
736
votes
13
answers
178k
views
What is the difference between Serialization and Marshaling?
I know that in terms of several distributed techniques (such as RPC), the term "Marshaling" is used but don't understand how it differs from Serialization. Aren't they both transforming ...
672
votes
21
answers
241k
views
Preferred method to store PHP arrays (json_encode vs serialize)
I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast ...
541
votes
16
answers
844k
views
How to Deserialize XML document
How do I Deserialize this XML document:
<?xml version="1.0" encoding="utf-8"?>
<Cars>
<Car>
<StockNumber>1020</StockNumber>
<Make>Nissan</Make>
...
499
votes
30
answers
786k
views
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 ...
461
votes
17
answers
401k
views
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 = "...
426
votes
16
answers
334k
views
What is object serialization?
What is meant by "object serialization"? Can you please explain it with some examples?
401
votes
11
answers
466k
views
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 ...
379
votes
36
answers
681k
views
No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator
I am trying to consume an API using Retrofit and Jackson to deserialize. I am getting the onFailure error No Creators, like default construct, exist): cannot deserialize from Object value (no delegate-...
373
votes
19
answers
290k
views
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 ...
367
votes
11
answers
528k
views
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<T>(this T toSerialize, String filename)
{
XmlSerializer ...
330
votes
9
answers
496k
views
Storing Python dictionaries
Are there simple ways to store a dictionary (or multiple dictionaries) in, for example, a JSON or pickle file?
For example, if I have some data like:
data = {}
data ['key1'] = "keyinfo"
data ...
327
votes
13
answers
281k
views
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 ...
322
votes
9
answers
184k
views
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 ...
303
votes
21
answers
399k
views
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 ...
295
votes
12
answers
132k
views
What is the difference between Serializable and Externalizable in Java?
What is the difference between Serializable and Externalizable in Java?
289
votes
9
answers
594k
views
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 ...
262
votes
16
answers
405k
views
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 ...
254
votes
4
answers
298k
views
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 ...
244
votes
13
answers
241k
views
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 ...
236
votes
10
answers
98k
views
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 ...
233
votes
13
answers
149k
views
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 ...