pub struct JSONParser {
pub allow_empty: bool,
pub strict: bool,
}Expand description
JSON parser for application/json content type
§Strict Mode
The strict flag controls validation of parsed JSON values:
strict = true: Rejects non-finite float values (Infinity, -Infinity, NaN)strict = false: Allows any valid JSON (but still rejects invalid JSON)
§Limitations
Due to serde_json’s adherence to JSON RFC 8259, literal Infinity, -Infinity,
and NaN values are not valid JSON and will be rejected during parsing
regardless of the strict flag. The strict validation only affects post-parse
validation of float values.
In other words:
- Invalid JSON input (e.g., raw
Infinityliteral) → Always rejected by serde_json - Valid JSON with non-finite values → Rejected only if
strict = true
Fields§
§allow_empty: boolWhether to allow empty bodies (returns null)
strict: boolWhether to enforce strict JSON (reject Infinity, -Infinity, NaN)
Implementations§
Source§impl JSONParser
impl JSONParser
Sourcepub fn new() -> JSONParser
pub fn new() -> JSONParser
Create a new JSONParser with default settings (strict mode, empty not allowed).
§Examples
use reinhardt_core::parsers::json::JSONParser;
let parser = JSONParser::new();
assert!(!parser.allow_empty);
assert!(parser.strict);Sourcepub fn allow_empty(self, allow: bool) -> JSONParser
pub fn allow_empty(self, allow: bool) -> JSONParser
§Examples
use reinhardt_core::parsers::json::JSONParser;
let parser = JSONParser::new().allow_empty(true);
assert!(parser.allow_empty);Sourcepub fn strict(self, strict: bool) -> JSONParser
pub fn strict(self, strict: bool) -> JSONParser
§Examples
use reinhardt_core::parsers::json::JSONParser;
let parser = JSONParser::new().strict(false);
assert!(!parser.strict);Trait Implementations§
Source§impl Clone for JSONParser
impl Clone for JSONParser
Source§fn clone(&self) -> JSONParser
fn clone(&self) -> JSONParser
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JSONParser
impl Debug for JSONParser
Source§impl Default for JSONParser
impl Default for JSONParser
Source§fn default() -> JSONParser
fn default() -> JSONParser
Returns the “default value” for a type. Read more
Source§impl Parser for JSONParser
impl Parser for JSONParser
Source§fn media_types(&self) -> Vec<String>
fn media_types(&self) -> Vec<String>
Get the media types this parser can handle
Source§fn parse<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_content_type: Option<&'life1 str>,
body: Bytes,
_headers: &'life2 HeaderMap,
) -> Pin<Box<dyn Future<Output = Result<ParsedData, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
JSONParser: 'async_trait,
fn parse<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_content_type: Option<&'life1 str>,
body: Bytes,
_headers: &'life2 HeaderMap,
) -> Pin<Box<dyn Future<Output = Result<ParsedData, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
JSONParser: 'async_trait,
Parse the request body
Auto Trait Implementations§
impl Freeze for JSONParser
impl RefUnwindSafe for JSONParser
impl Send for JSONParser
impl Sync for JSONParser
impl Unpin for JSONParser
impl UnsafeUnpin for JSONParser
impl UnwindSafe for JSONParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().