Jetson2YamlHttpMessageConverter class
A high-priority HTTP message converter that uses Jetson’s YAML-capable ObjectMapper to read and write YAML request and response bodies.
This converter:
- Is registered with
Ordered.HIGHEST_PRECEDENCE - 2, running after the XML converter and before other lower-precedence converters. - Supports the standard and extended YAML media types:
application/yamlapplication/x-yamltext/yamltext/x-yaml
- Only participates in reading/writing when the configured
_objectMapperis a YamlObjectMapper. - Delegates all YAML → object and object → YAML transformations to Jetson.
- Honors declared request/response character encodings.
- Automatically assigns the
Content-Typeheader (with charset) when not already present.
Reading
The full request body is decoded using the resolved character encoding, then passed into the YAML-aware Jetson mapper:
mapper.readYamlValue(yamlString, type);
If the provided object mapper is not a YamlObjectMapper, the converter gracefully falls back to generic Jetson deserialization:
mapper.readValue(yamlString, type);
Any parsing or mapping errors propagate naturally to the caller, where they can be handled by the surrounding JetLeaf HTTP framework.
Writing
Objects are serialized using:
mapper.writeValueAsYaml(object);
with a fallback of:
mapper.writeValueAsString(object);
After serialization:
- The
Content-Typeheader is set toapplication/yaml(with charset) if not already specified. - The YAML string is written to the output stream using the resolved encoding.
Application Context
This converter does not customize its mapper via dependency injection. Instead, YAML support is enabled simply by providing a YamlObjectMapper to the converter at construction time, or by exposing one in the application context that Jetson is configured to use.
Example
final converter = Jetson2YamlHttpMessageConverter(yamlMapper);
final dto = await converter.readInternal(Class<MyDto>(), inputMessage);
Most JetLeaf applications automatically register this converter when a YAML mapper is present in the environment.
- Inheritance
-
- Object
- HttpMessageConverter<
Object> - AbstractHttpMessageConverter<
Object> - Jetson2YamlHttpMessageConverter
- Annotations
-
- @Order.new(Ordered.HIGHEST_PRECEDENCE - 2)
Constructors
- Jetson2YamlHttpMessageConverter(ObjectMapper _objectMapper)
- A high-priority HTTP message converter that uses Jetson’s YAML-capable ObjectMapper to read and write YAML request and response bodies.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addDefaultHeaders(
HttpHeaders headers, MediaType? contentType) → void -
Adds default headers to the HTTP message if not already present.
inherited
-
addSupportedMediaType(
MediaType type) → void -
Adds a media type to the list of supported types.
inherited
-
canRead(
Class type, [MediaType? mediaType]) → bool -
Determines whether this converter can deserialize the given type from the specified media type.
override
-
canWrite(
Class type, [MediaType? mediaType]) → bool -
Determines whether this converter can serialize the given type to the specified media type.
override
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
getClassSupportedMediaTypes(
Class< Object> type) → List<MediaType> -
Returns the media types specifically supported for a given class type.
inherited
-
getDefaultEncoding(
) → Encoding -
Returns the default character encoding used by this converter.
inherited
-
getSupportedMediaTypes(
) → List< MediaType> -
Returns the list of media types this converter supports by default.
inherited
-
matchesType(
Class type) → bool -
Returns whether the given
typematches this filter's criteria.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
Class< Object> type, HttpInputMessage inputMessage) → Future<Object> -
Deserializes an HTTP input message to a Dart object of type
T.inherited -
readInternal(
Class< Object> type, HttpInputMessage inputMessage) → Future<Object> -
Template method for reading and deserializing HTTP input.
override
-
removeSupportedMediaType(
MediaType type) → void -
Removes a media type from the list of supported types.
inherited
-
resolveRequestEncoding(
HttpInputMessage inputMessage) → Encoding -
Resolves the appropriate character encoding for reading the request body.
inherited
-
resolveResponseEncoding(
HttpOutputMessage outputMessage) → Encoding -
Resolves the appropriate character encoding for writing the response body.
inherited
-
setDefaultEncoding(
Encoding encoding) → void -
Sets the default character encoding for this converter.
inherited
-
setSupportedMediaTypes(
List< MediaType> types) → void -
Replaces the current supported media types with the provided list.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
Object object, MediaType? contentType, HttpOutputMessage outputMessage) → Future< void> -
Serializes a Dart object to an HTTP output message.
inherited
-
writeInternal(
Object object, HttpOutputMessage outputMessage) → Future< void> -
Template method for serializing an object to an HTTP output message.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited