我想使用avro-rs序列化JSON值。我似乎找不到解决方法。要进行复制,您可以执行以下操作:
cargo new example
Cargo.toml
:[package]
name = "rust-example"
version = "0.1.0"
edition = "2018"
[dependencies]
serde_json = "1.0.52"
avro-rs = "0.10.0"
scr/main.rs
:use avro_rs::{Schema, Writer};
use serde_json::json;
fn main() {
let raw_schema = r#"
{
"type": "record",
"name": "action",
"fields": [
{"name": "id", "type": "string"}
]
}
"#;
let schema = Schema::parse_str(raw_schema).unwrap();
let mut writer = Writer::new(&schema, Vec::new());
let action = json!({
"id": "some id"
});
writer.append(action).unwrap(); // panics: ValidationError("value does not match schema")
}
cargo run
来查看输出。答案 0 :(得分:0)
您可以尝试使用avrow条板箱。它具有from_json
类型的Record
API:https://docs.rs/avrow/0.2.0/avrow/struct.Record.html#method.from_json。
检查存储库中的json example。