nats-io/nats.rs

Failure to deserialise Config for Message Stream

bengsparks opened this issue · 1 comments

Observed behavior

Roundtrip de/serialising a stream::Config with default values fails.
Specifically, the ConsumerLimits struct fails to deserialise from null. See example below.

Expected behavior

Roundtrip should succeed.

Server and client version

Client: async-nats@0.35.1, Server: N/A

Host environment

N/A; serde-level failure.

Steps to reproduce

  • main.rs
use async_nats::jetstream::stream;

fn main() {
    let config = stream::Config { ..Default::default() }; 

    let roundtrip: stream::Config = {
        let ser = serde_json::to_string(&config).unwrap();
        let de = serde_json::from_str(&ser).unwrap();

        de
    };

    dbg!(roundtrip);
}
  • Cargo.toml
[package]
name = "async-nats-message-stream-deser"
version = "0.1.0"
edition = "2021"

[dependencies]
async-nats = "0.35.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.122"

Output:

thread 'main' panicked at src/main.rs:8:45:
called `Result::unwrap()` on an `Err` value: Error("invalid type: null, expected struct ConsumerLimits", line: 1, column: 186)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Hey!
Thanks for reporting the issue.
However server never sends null, so it should never be an issue in real-world scenario, it's good to protect against those things.