1

So, I would like to treat -1, "" and NaN as null values when serializing some fields in a protobuffer. This is to deal with legacy code. Right now I'm populating the a protobuffer based on a C# object I'm provided, and a number of the properties have these values which indicate a kind of null value. I'd like very much not to have write and maintain a ton of if checks to see if the field holds one of these so called null values.

Is there some kind of .NET protobuffer serialization option that would silently treat these values and null and not serialize them?

For clarity this is .NET 4.5 with protoc 2.6.1.

lucidquiet
  • 6,124
  • 7
  • 51
  • 88
  • Just write a function that tests for those and return null( or if it's a string response, replace them with null) if they match. The call it when you need to check – dinotom May 12 '16 at 21:00
  • Can you share a [simple example](https://stackoverflow.com/help/mcve) of the type you are serializing, and what you are doing currently? – dbc May 12 '16 at 21:18
  • Also, is this a duplicate of [Conditional serialization with protobuf-net](https://stackoverflow.com/questions/35469388/conditional-serialization-with-protobuf-net)? – dbc May 12 '16 at 21:25

0 Answers0