I am doing an update of my protobuf-net library reference, specifically from 2.4.4 to 3.0.101. Previously, we used null
in lists as they contain meaningful information to the business (e.g., new[] { "one", "two", null, null, "five" }
). However, they are not supported in 3.x yet as far as I understand (https://protobuf-net.github.io/protobuf-net/releasenotes#).
Is there a suggested migration strategy for collections with nulls?
I can mitigate the change going forward with additional fields (e.g., transposing the collection to a dictionary & back again on serializing/deserializing), however backwards compatibility seems broken for data serialied with 2.x libraries. Are there any migration guides?
Given that 3.x doesn't yet support null retention, your options are somewhat limited:
- Submit a PR to add the missing feature. A quick glance through the protobuf source code makes me think that it would be fairly trivial to implement. In line 161 of the linked source file there seems to be a throw for nulls, which is where I'd start. I could be very wrong about how complicated this would be, though.
- See if you can use both libraries concurrently. You would need to know (or detect) whether data to serialize is in v2 or v3 format (I have not checked but would be surprised if there wasn't a way to detect this by looking at the first few bytes). You may need to compile a custom version to give it a different namespace, in order for the two to co-exist.
- Migrate data to v3. You can do this as a one-off operation (smaller amounts of data that you control) or on-demand (large amounts of data or externally received data). You'll need to re-design the types used in lists with nulls, so that you no longer have nulls (e.g. by having a custom value that logically represents null).
- Stay with v2. It's stable and works exceptionally well, so unless you have a specific need to upgrade it may not be worth the effort.