expression

REST: test an old client against an added field

A client that ignores unfamiliar JSON object fields can often accept an additive response change. This is a narrow compatibility test: strict readers, exhaustive enums, altered defaults or changed semantics can still break. Test actual supported client contracts. Standalone synthetic example. Expected stdout (not executed): old client id: 7 Common mistake: Assuming every addition is safe for every client.

Formal Syntax & Structure

rust syntaxrust
serde_json::from_str::<OldView>(new_json)

Working Example

Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    #[derive(Deserialize)]    struct OldView { id: u32 }    #[derive(Serialize)]    struct NewView { id: u32, available: bool }    let response = serde_json::to_string(&NewView { id: 7, available: true }).unwrap();    let old: OldView = serde_json::from_str(&response).unwrap();    println!("old client id: {}", old.id);}
Rust Reference