scientific_workflow/storage/json_payload_decoder/string.rs
1//! JSON decoding for a state field whose concrete payload is [`String`].
2//!
3//! [`JsonStringDecoder`] converts exactly one raw JSON field value into an owned
4//! UTF-8 string. The series reader remains responsible for finding the field
5//! by key, selecting this decoder, and inserting the returned string into the
6//! matching state slot.
7//!
8//! The expected representation is a JSON string, including its surrounding
9//! quotation marks. Standard JSON escapes are decoded by Serde JSON, so
10//! `"line\nvalue"` becomes a string containing an actual newline. Empty strings
11//! and all valid Unicode content are accepted. JSON `null`, numbers, booleans,
12//! arrays, and objects are rejected rather than converted implicitly.
13//!
14//! This decoder deliberately performs no trimming, case conversion,
15//! normalization, non-empty validation, key lookup, record parsing, state
16//! mutation, or filesystem access. Applications requiring a constrained or
17//! transformed string should register a custom decoder for that key.
18
19use super::JsonPayloadDecoder;
20
21/// Stateless default decoder for payloads stored as [`String`].
22///
23/// The unit struct is zero-sized and may be copied freely while configuring
24/// decoder registries. Every registry entry still binds it to exactly one key
25/// and to the concrete [`String`] output type.
26#[derive(Clone, Copy, Debug, Default)]
27pub struct JsonStringDecoder;
28
29impl JsonPayloadDecoder<String> for JsonStringDecoder {
30 type Error = serde_json::Error;
31
32 /// Deserializes one complete JSON string into an owned [`String`].
33 ///
34 /// The returned value owns its UTF-8 buffer. On failure, the original
35 /// [`serde_json::Error`] is returned so the decoder registry can retain it
36 /// as the source of a stream-, index-, and key-aware storage error.
37 fn decode_json_payload(&self, raw_json: &str) -> Result<String, Self::Error> {
38 serde_json::from_str(raw_json)
39 }
40}