-1

I have created a class called User, which contain 2 property Name and IsSuperUser, IsSuperuser is by default true.I created an object of the same class and I've set the IsSuperUser = false. after the deserialization the IsSuperUser value is true instead of false( Please see the output).

Please refer the my c# code below and check the proto_file generated after the serialization.

Using Protobuf-net 3.2.16 version.[enter image description here](https://i.stack.imgur.com/8zslY.jpg)

#protobuf-net #protobuf

The value cannot be change.

dbc
  • 104,963
  • 20
  • 228
  • 340
  • Please [edit] your question to include your code and data as **text** rather than as screenshot(s). On stack overflow images should not be used for textual content, see [*Why should I not upload images of code/data/errors?*](https://meta.stackoverflow.com/a/285557) for why. For instructions on formatting see *[How do I format my code blocks?](https://meta.stackexchange.com/q/22186)*. A [mcve] showing what you have tried that did not work would maximize your chances of getting help. See [ask]. – dbc Apr 10 '23 at 13:36
  • But possibly related: [Force protobuf-net to serialize all default values](https://stackoverflow.com/q/12295976). – dbc Apr 10 '23 at 14:13
  • [Serialization of default values in optional members #363](https://github.com/protobuf-net/protobuf-net/issues/363) might also apply. – dbc Apr 10 '23 at 16:54

1 Answers1

1

If the default isn't the usual defaults: tell the serializer; add [DefaultValue(true)] to the property.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900