NunezGui / protobuf-net

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

Support for arrays (of nullables) is missing #365

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
1. Serialize Class with property of type int?[], where some of elements are 
nulls.
2. Deserialize.

What is the expected output? What do you see instead?
3. The size of the deserialized array differs from the origin.

What version of the product are you using? On what operating system?
protobuf-net r622 (full net30)

Original issue reported on code.google.com by lambh...@gmail.com on 2 Apr 2013 at 10:01

GoogleCodeExporter commented 8 years ago
I am having the same problem with double?[], but I don't think it's because 
values are null, because I have no null values. Basically I have a double?[] 
set up in my class. I see that my array is correctly sized double?[20] 
immediately before being serialized, but when de-serialilzed, they are double 
the expected size, double?[40], and the actual values are located at index 
20-39 and index 0-19 are null.

Original comment by michaels...@gmail.com on 3 Apr 2013 at 6:12

GoogleCodeExporter commented 8 years ago
By the way, changing an array to int[] hasn't fixed it.

The strange thing about it is, that on deserializing object protobuf calls 
getter of the int[] property before calling setter.

I've added that array property to wrap a 2d array property. Firstly the 
deserializer has thrown a nullref exception, cause of calling getter, which 
couldn't access 2d array. I've expected protobuf to call only setter on 
deserializing. That's why I've placed initialization of the 2d array in the 
setter of the int[] property.

Then I've "fixed" it by initializing 2d array property by deserializing of 
another property, which came earlier. But the length of the wrapper int[] 
property then was doubled. Is it an expected behavior?

Finally I could get it to work by returning null in the getter of int[] 
property after the default constructor (which is only used by the protobuf). 
After calling getter the protobuf deserializer has called setter of int[] with 
the correct length. Elements were also correct.

Original comment by lambh...@gmail.com on 4 May 2013 at 7:33

GoogleCodeExporter commented 8 years ago
If someone wants to see an example - you can find it on bitbucket: 
https://bitbucket.org/kostgr/sudokusolver/overview

The serializable class can be found under Sudoku/Grid/SudokuGrid.cs

Steps to reproduce: compile and try to load one of the samples.

Original comment by lambh...@gmail.com on 4 May 2013 at 7:38