Reputation: 342
I'm writing a microservice that takes a json object as input. This json object is only partially known and therefore the struct to which I map it looks like this:
#[derive(Serialize, Deserialize)]
pub struct Incoming {
uri: String,
payload: serde_json::Value,
id: String
}
I then want to publish this to a RabbitMQ queue so I serialize it using bincode
:
let incoming = serde_json::from_slice::<Incoming>(&incoming).expect("Fail to serialize");
// This line fails:
bincode::serialize(&incoming).expect("Failed to deserialize to binary");
The receiving service (the consumer) fails to deserialize this (even though it has the exact same model) and results in Err(DeserializeAnyNotSupported)
.
From my understanding this comed from the serde_json::Value
-part of the struct.
So how do I serialize a partially unknown JSON-object to binary in order to deserialize it on the receiving service?
Upvotes: 2
Views: 1216