fdeantoni / prost-wkt

Prost Well-Known-Types serialization and deserialization.
Apache License 2.0
76 stars 35 forks source link

Serde JSON serialization breaks for `Any` types without `#[serde(default)]` #9

Closed rnbguy closed 2 years ago

rnbguy commented 2 years ago

Going through the serialize function, I realized, it calls try_unpack()

https://github.com/fdeantoni/prost-wkt/blob/190d4d310249b65581d1c50963f3cf2ac031ce24/wkt-types/src/pbany.rs#L138-L140

which may fail because "value" is assigned to {} in this block and the Message type may not derive #[serde(default)].

https://github.com/fdeantoni/prost-wkt/blob/190d4d310249b65581d1c50963f3cf2ac031ce24/wkt-types/src/pbany.rs#L113-L119

In such cases, serialization defaults to {"@type": ..., "value": ...}.

https://github.com/fdeantoni/prost-wkt/blob/190d4d310249b65581d1c50963f3cf2ac031ce24/wkt-types/src/pbany.rs#L142-L143

This breaks the protobuf serialization to JSON for the Any types without #[serde(default)].