#[non_exhaustive]pub struct JsonParseOptions {
pub ignore_unknown_enum_values: bool,
pub strict_extension_keys: bool,
pub strict_any_type_urls: bool,
}json only.Expand description
Options controlling protobuf JSON parsing behavior.
Use JsonParseOptions::new plus builder methods to construct:
let opts = JsonParseOptions::new().ignore_unknown_enum_values(true);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.ignore_unknown_enum_values: boolWhen true, an enum name that the enum does not declare is replaced
with the default value, left unset, or dropped, depending on the kind
of field. In an optional, repeated or map field of a closed
enum, a number in the i32 range that the enum does not declare is
left unset or dropped too. A value that cannot be an enum value, such
as a bool or 1.5, is a parse error with the option on or off. See
the module docs for each kind of field. Default: false.
strict_extension_keys: boolWhen true, "[pkg.ext]" JSON keys that are not in the extension
registry produce a parse error instead of being silently dropped.
The default (false, lenient) matches the pre-extension-registry
behavior where all unknown keys were dropped by serde’s derive.
protobuf-go (protojson/decode.go:175) and protobuf-es
(from-json.ts:251) both error on unregistered extension keys unless
their respective ignore-unknown flags are set; set true here to
match. The error pinpoints the missing registration.
Extendee mismatch (key IS registered but extends a different message) always errors regardless of this flag — that’s a contract violation, not a mere miss.
This flag covers "[pkg.ext]" keys only, and only for messages that
preserve unknown fields. Ordinary unknown field names are governed by
the codegen option buffa_build::Config::deny_unknown_json_fields,
which also rejects "[pkg.ext]" keys on a message generated with
preservation off.
strict_any_type_urls: boolWhen true, the @type of a google.protobuf.Any must be a type
URL: it must contain a /. A bare message full name such as
"pkg.Message" is a parse error.
With the default (false), a bare full name is accepted when the
type registry has a JSON entry for a message of that name, and the
Any keeps it as its type_url. protobuf-go and Python read such a
name. C++ and Java reject it, and any.proto says that a type URL
contains at least one /. Set true to reject what C++ and Java
reject.
A bare name without a JSON entry is a parse error with the option on
or off, and so is an @type that is empty or ends in /.
The option covers parsing, and generated message types only.
Serialization writes the type_url an Any holds, and
Any::type_name and Any::is_message in buffa-types read a bare
name with the option on or off: test type_url for a / yourself
where that matters. JSON parsing of a DynamicMessage does not read
the option. Set DynamicMessageSeed::strict_any_type_urls in
buffa-descriptor for that.
Implementations§
Source§impl JsonParseOptions
impl JsonParseOptions
Sourcepub fn ignore_unknown_enum_values(self, ignore: bool) -> Self
pub fn ignore_unknown_enum_values(self, ignore: bool) -> Self
Set whether enum values that the enum does not declare are ignored instead of producing a parse error. See the module docs for what “ignored” means for each kind of field.
Sourcepub fn strict_extension_keys(self, strict: bool) -> Self
pub fn strict_extension_keys(self, strict: bool) -> Self
Set whether unregistered "[pkg.ext]" JSON keys produce a parse error
(true) or are silently dropped (false, the default).
Sourcepub fn strict_any_type_urls(self, strict: bool) -> Self
pub fn strict_any_type_urls(self, strict: bool) -> Self
Set whether the @type of a google.protobuf.Any must contain a /
(true), or may also be the bare full name of a registered message
(false, the default).