Values equal to 0 not serialized by ProtoBuf in .NET
Opened this issue · 3 comments
I will show it basing on FeedHeader serialization:
new FeedHeader()
{
gtfs_realtime_version = "2.0",
incrementality = FeedHeader.Incrementality.FULL_DATASET, // FeedHeader.Incrementality.FULL_DATASET == 0
timestamp = Utils.ToUnixTime(DateTime.UtcNow)
};
After serializing by ProtoBuf it seems that incrementality value (which is equal to 0) in FeedHeader class is not serialized, because when testing feed with https://github.com/CUTR-at-USF/gtfs-realtime-validator that validator shows me error "header incrementality not populated" and when I check (in that validator) protobuf file contents:
"header": {
"gtfs_realtime_version": "2.0",
"timestamp": 1520343087
}
Same problem is i.e. with:
- ScheduleRelationship enums
- delay in StopTimeEvent
- etc.
Check also attached file.
How to solve it? Can I control somehow which values should always be serialized even if they are null / zero / empty? I am using classess provided by Google:
I have the same issue with FeedHeader.Incrementality. Workaround?
Looks like this is the underlying issue:
https://stackoverflow.com/questions/12295976/force-protobuf-net-to-serialize-all-default-values
@bugbiter @PiotrWojtowicz Are you able to try this workaround in your code to see if it works?
Anyone found solution yet?