MobilityData / gtfs-realtime-bindings

Language bindings generated from the GTFS Realtime protocol buffer spec for popular languages.
Apache License 2.0
369 stars 127 forks source link

Values equal to 0 not serialized by ProtoBuf in .NET #32

Open ghost opened 6 years ago

ghost commented 6 years ago

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:

Check also attached file.

screen

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:

bugbiter commented 5 years ago

I have the same issue with FeedHeader.Incrementality. Workaround?

barbeau commented 5 years ago

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?

adhunna commented 4 years ago

Anyone found solution yet?