title: error[E0277]: the trait bound `Request<Body>: serde::ser::Serialize` is not satisfied
body: <p>I am trying to output the Hyper HTTP Request Object as JSON. I am using Serde to Serialize the object to JSON.</p>
  <p>Since I am not defining the HTTP Request Struct, I can't add the attribute <code>#[derive(Serialize, Deserialize)]</code> to it. any ideas on how to get around this?</p>
  <p>my code:</p>
  <pre><code>use hyper::body::HttpBody as _;    
  use hyper::{Body, Client, Method, Request, Uri};    
  use hyper_tls::HttpsConnector;    
  #[cfg(feature = &quot;std&quot;)]
  use serde::{Deserialize, Deserializer, Serialize, Serializer};    
  use serde_json::{json, Result as re_, Value};    
  use tokio::io::{stdout, AsyncWriteExt as _};    
  #[tokio::main]
  async fn main() -&gt; Result&lt;(), Box&lt;dyn std::error::Error + Send + Sync&gt;&gt; {
  let https = HttpsConnector::new();
  
  // Client Object
  let client = Client::builder().build::&lt;_, hyper::Body&gt;(https);    
  let uri: Uri = &quot;https://api.api.com&quot;.parse()?;
  let http_body = String::from(&quot; body&quot;);
  let content_length = http_body.chars().count();
  //Build Request
  let req = Request::builder()
      .method(Method::POST)
      .uri(uri)
      .header(&quot;accept&quot;, &quot;application/xml&quot;)
      .header(&quot;content-type&quot;, &quot;application/xml&quot;)
      .header(&quot;Content-Length&quot;, content_length)
      .body(Body::from(http_body))?;
  
  // Serialize it to a JSON string.
  let j = serde_json::to_string(&amp;req)?;
  
  // Print HTTP Request
  println!(&quot;{}&quot;, j);
  
  // Await the response...
  let mut resp = client.request(req).await?;
  println!(&quot;Response: {}&quot;, resp.status());
  Ok(())
  }
  </code></pre>
  <p>stack trace shows:</p>
  <pre><code>|     let j = serde_json::to_string(&amp;req)?;
       |             --------------------- ^^^^ the trait `serde::ser::Serialize` is not implemented for `Request&lt;Body&gt;`
       |             |
       |             required by a bound introduced by this call
       |
  note: required by a bound in `serde_json::to_string`
      --&gt; /home/joel/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.79/src/ser.rs:2225:17
       |
  2225 |     T: ?Sized + Serialize,
       |                 ^^^^^^^^^ required by this bound in `serde_json::to_string`
  </code></pre>
  <p>Cargo.toml</p>
  <pre><code>[dependencies]
  serde = { version = &quot;1.0.136&quot;, features = [&quot;derive&quot;] }
  serde_json = &quot;1.0.79&quot;
  serde_derive = &quot;1.0.136&quot;
  hyper = { version = &quot;0.14.18&quot;, features = [&quot;full&quot;] }
  tokio = { version = &quot;1.17.0&quot;, features = [&quot;full&quot;] }
  hyper-tls = &quot;0.5.0&quot;
  rustls = &quot;0.20.4&quot;
  </code></pre>