Jetson2XmlHttpMessageConverter class
A high-priority HTTP message converter that uses Jetson’s XML-capable ObjectMapper to read and write XML request and response bodies.
This converter:
- Is registered with
Ordered.HIGHEST_PRECEDENCE - 1, running immediately after the JSON converter. - Supports
application/xmlandtext/xmlmedia types. - Only activates for reading or writing when the configured
_objectMapperis an XmlObjectMapper. - Delegates all XML → object and object → XML processing to Jetson.
- Respects declared request/response character encodings.
- Automatically sets the
Content-Typeresponse header (with charset) when missing.
Reading
The full request body is read using the resolved encoding and passed into the Jetson XML mapper:
mapper.readXmlValue(xmlString, type);
If the provided object mapper is not an XmlObjectMapper, this converter falls back to:
mapper.readValue(xmlString, type);
(This fallback is primarily useful for advanced integration scenarios.)
Any XML parsing or mapping errors bubble up naturally and are handled by the surrounding web framework.
Writing
Serialization uses the XML mapping function when available:
mapper.writeValueAsXml(object);
and otherwise falls back to:
mapper.writeValueAsString(object);
After serialization:
- The
Content-Typeheader is set to an XML media type if missing. - The XML string is written to the output stream in the resolved encoding.
Application Context
Unlike the JSON converter, this class does not customize its mapper via dependency injection, because XML usage is typically explicit and mapper configuration is expected to be provided externally.
Example
final converter = Jetson2XmlHttpMessageConverter(xmlMapper);
final dto = await converter.readInternal(Class<MyDto>(), inputMessage);
Most Jetleaf applications pick up this converter automatically when an XmlObjectMapper is present in the application context.
- Inheritance
-
- Object
- HttpMessageConverter<
Object> - AbstractHttpMessageConverter<
Object> - Jetson2XmlHttpMessageConverter
- Annotations
-
- @Order.new(Ordered.HIGHEST_PRECEDENCE - 1)
Constructors
- Jetson2XmlHttpMessageConverter(ObjectMapper _objectMapper)
- A high-priority HTTP message converter that uses Jetson’s XML-capable ObjectMapper to read and write XML 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