From 0be1a879ab8c3b881407f3e519ad720c4419d282 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 1 Mar 2026 09:07:01 +0100 Subject: [PATCH 1/3] feat: added function that turns protojson into json --- adapter/rest/src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/adapter/rest/src/main.rs b/adapter/rest/src/main.rs index 847a0eb..474b2dc 100644 --- a/adapter/rest/src/main.rs +++ b/adapter/rest/src/main.rs @@ -14,6 +14,7 @@ use hyper::{ server::conn::http1, }; use hyper_util::rt::TokioIo; +use serde_json::{Map, Number, Value as J}; use std::collections::HashMap; use std::convert::Infallible; use std::net::SocketAddr; @@ -58,6 +59,36 @@ fn json_error(status: StatusCode, msg: &str) -> Response> { .unwrap() } +fn pb_value_to_json(v: &Value) -> serde_json::Value { + match v.kind.as_ref() { + None => J::Null, + + Some(Kind::NullValue(_)) => J::Null, + + Some(Kind::BoolValue(b)) => J::Bool(*b), + + Some(Kind::StringValue(s)) => J::String(s.clone()), + + Some(Kind::NumberValue(n)) => { + if let Some(num) = Number::from_f64(*n) { + J::Number(num) + } else { + J::Null + } + } + + Some(Kind::ListValue(lv)) => J::Array(lv.values.iter().map(pb_value_to_json).collect()), + + Some(Kind::StructValue(st)) => { + let mut obj = Map::new(); + for (k, v) in &st.fields { + obj.insert(k.clone(), pb_value_to_json(v)); + } + J::Object(obj) + } + } +} + fn build_response( status: StatusCode, headers: HashMap, @@ -210,8 +241,9 @@ async fn execute_flow_to_hyper_response( }; // payload -> json bytes - let json = serde_json::to_vec_pretty(payload_val).unwrap_or_else(|err| { - format!(r#"{{"error":"Serialization failed: {}"}}"#, err).into_bytes() + let json_val = pb_value_to_json(payload_val); + let json = serde_json::to_vec_pretty(&json_val).unwrap_or_else(|err| { + format!(r#"{{"error":"Serialization failed: {:?}"}}"#, err).into_bytes() }); let status = From 8339d5312cae7858e9c7208908af5fd6299967b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20G=C3=B6tz?= <52959657+raphael-goetz@users.noreply.github.com> Date: Sun, 1 Mar 2026 09:14:17 +0100 Subject: [PATCH 2/3] Update adapter/rest/src/main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Raphael Götz <52959657+raphael-goetz@users.noreply.github.com> --- adapter/rest/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adapter/rest/src/main.rs b/adapter/rest/src/main.rs index 474b2dc..d3ce845 100644 --- a/adapter/rest/src/main.rs +++ b/adapter/rest/src/main.rs @@ -72,7 +72,16 @@ fn pb_value_to_json(v: &Value) -> serde_json::Value { Some(Kind::NumberValue(n)) => { if let Some(num) = Number::from_f64(*n) { J::Number(num) + } else if n.is_nan() { + J::String("NaN".to_string()) + } else if n.is_infinite() { + if n.is_sign_positive() { + J::String("Infinity".to_string()) + } else { + J::String("-Infinity".to_string()) + } } else { + // Fallback for unexpected cases where from_f64 returns None. J::Null } } From 584f3b93b8be2d75a4392335c64bce40db869c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20G=C3=B6tz?= <52959657+raphael-goetz@users.noreply.github.com> Date: Sun, 1 Mar 2026 09:14:51 +0100 Subject: [PATCH 3/3] Update adapter/rest/src/main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Raphael Götz <52959657+raphael-goetz@users.noreply.github.com> --- adapter/rest/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adapter/rest/src/main.rs b/adapter/rest/src/main.rs index d3ce845..e19a985 100644 --- a/adapter/rest/src/main.rs +++ b/adapter/rest/src/main.rs @@ -252,7 +252,11 @@ async fn execute_flow_to_hyper_response( // payload -> json bytes let json_val = pb_value_to_json(payload_val); let json = serde_json::to_vec_pretty(&json_val).unwrap_or_else(|err| { - format!(r#"{{"error":"Serialization failed: {:?}"}}"#, err).into_bytes() + let fallback = serde_json::json!({ + "error": format!("Serialization failed: {}", err), + }); + serde_json::to_vec(&fallback) + .unwrap_or_else(|_| br#"{"error":"Serialization failed"}"#.to_vec()) }); let status =