Conerlius / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Empty dictionary serializes/deserializes as null. #131

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a class with an dictionary as a field, marked with the right 
attributes for protubuf-net serialization.
2. Serialize an instance of that class with the dictionary having no items in 
it but not being set to null.
3. Deserialize. The returned instance will have the dictionary set to null 
rather than an empty dictionary.

Expected output to match input.

This is using the v1 branch.

Original issue reported on code.google.com by sharedpr...@gmail.com on 13 Aug 2010 at 8:44

GoogleCodeExporter commented 8 years ago
Ok, never mind. It doesn't seem to be doing this anymore...

Original comment by sharedpr...@gmail.com on 25 Aug 2010 at 9:12

GoogleCodeExporter commented 8 years ago
In the core "protobuf" spec there is sadly no "null" - it is either there or it 
isn't. And an empty list (which includes dictionary for our puroses) simply 
isn't there.

If your constructor initialises the dictionary it should be fine.

Original comment by marc.gravell on 26 Aug 2010 at 11:26

GoogleCodeExporter commented 8 years ago
Yeah. You probably already realized this, but if you switch to using 
FormatterServices.GetUninitializedObject() as innahema suggested in Issue 106, 
you will have to serialize a flag for each list to determine whether it was 
empty or null.

Original comment by sharedpr...@gmail.com on 27 Aug 2010 at 7:52

GoogleCodeExporter commented 8 years ago
Oh sorry, I see this duplicates Issue 58.

Original comment by sharedpr...@gmail.com on 27 Aug 2010 at 7:56