feat: update serde json

This commit is contained in:
2025-08-03 16:43:05 +08:00
parent 814b5e9442
commit 9eba818de9
2 changed files with 260 additions and 78 deletions

View File

@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{Result, Value};
use chrono::{DateTime, Utc, TimeZone};
// alternative JSON for human: https://crates.io/crates/json5
mod my_date_format {
use chrono::{DateTime, Utc, TimeZone};
use serde::{self, Deserialize, Serializer, Deserializer};
@@ -50,6 +51,8 @@ struct TestStruct {
struct TestStruct2 {
test_id: i32,
test_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
test_description: Option<String>,
}
fn main() -> Result<()> {
@@ -91,6 +94,7 @@ fn main() -> Result<()> {
let test_struct2 = TestStruct2 {
test_id: 1,
test_name: "Hatter".into(),
test_description: None,
};
println!("{}", serde_json::to_string(&test_struct2)?);