protobuf calling getter on deserialization?

156 views
Skip to first unread message

David Deutsch

unread,
Sep 18, 2013, 5:09:39 PM9/18/13
to prot...@googlegroups.com
I know this is a long shot, but is there any reason protobuf-net would call the getter of a property on deserialization, and not the setter? Most of my properties serialize and deserialize fine, but for one particular property only the getter is called, and thus deserialization fails. 

David Deutsch

unread,
Sep 19, 2013, 12:21:28 PM9/19/13
to prot...@googlegroups.com
So I *think* what is happening is that protobuf does a get of the property because it is a dictionary (actually, a dictionary of dictionaries). So what it is trying to do is grab the dictionary and populate it. It does not set the dictionary back to the original member because it must assume that I already have a handle to that dictionary. Problem is, I generate/consume the dictionary dynamically. Looks like there may be a way around this in v2 with IgnoreListHandling and/or OverwriteList. 

Marc Gravell

unread,
Sep 19, 2013, 12:54:04 PM9/19/13
to David Deutsch, Protocol Buffers

What is the property? A sub-object? A List? If the serializer doesn't think it needs to call the setter: it won't. For example, the typical list handling code could be paraphrased (not the actual implementation) as:

    var list = obj.SomeList;
    bool setValue = false;
    if(list == null) {
        list = new List<SomeType>();
        setValue = true;
    }
    while(nextTag == expected) {
         list.Add(ReadSomeType());
    }
    if(setValue) obj.SomeList = list;

Indeed, it is not uncommon that there *is no setter* (for a list / child object), so the library needs to support those scenarios too.

There are some flags you can set to help steer it to always write - but an example of your scenario would help.

Also, note that the library supports deserialization callbacks (to perform any pre-deserialization steps), custom type factories (to initialize objects in a different way) and constructor-skipping (to bypass any fields initializers) - these are all optional switches etc.

Marc

On 18 Sep 2013 22:09, "David Deutsch" <da...@reverenddave.com> wrote:
I know this is a long shot, but is there any reason protobuf-net would call the getter of a property on deserialization, and not the setter? Most of my properties serialize and deserialize fine, but for one particular property only the getter is called, and thus deserialization fails. 

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Marc Gravell

unread,
Sep 19, 2013, 1:05:31 PM9/19/13
to David Deutsch, Protocol Buffers

Yes, OverwriteList should fix this. IgnoreListHandling does something very different that doesn't apply here (see the intellisense comments for full usage

Marc

--
Reply all
Reply to author
Forward
0 new messages