Be able to parse the following JSON format:
{
"token": "ASDSD",
"action": "Foo",
"payload": {},
}
Where token maps to a uuid::Uuid (got this) and action maps to an ActionType enum (got this, but very verbose).
The tricky part is mapping payload to predefined structs (there's a lot of them). Some examples are:
#[derive(RustcDecodable, Debug)]
pub struct IncomingMessage<T> {
pub token: Uuid,
pub action: ActionType,
pub payload: Option<T>,
}
pub struct AuthenticatePayload {
pub id: u64,
pub name: String,
}
pub struct MessageUserPayload {
pub user: u64,
pub message: String,
}
@hjr3 Yeah it's definitely a hard problem to solve when trying to avoid being super explicit. Was trying to make use of rustc-serialize's automatic decoding, but have had no luck targeting nested objects directly. Will look into your approach.