JetsonObjectMapper class final

A high-level, multi-format Jetson object mapper with integrated support for JSON, XML, and YAML serialization and deserialization.

JetsonObjectMapper is the primary, production-grade object mapper used in the JetLeaf framework. It builds on top of AbstractAwareObjectMapper, providing:

  • Format-aware read/write operations (JSON, XML, YAML)
  • Feature flags for customizing serialization behavior
  • Naming strategies for transforming Dart field names
  • Auto-registration of Jetson serializers, deserializers, and adapters
  • ApplicationContext, Environment, and ConversionService awareness

It is the same mapper used internally by JetLeaf’s HTTP message converters, DI container integrations, and serialization infrastructure.

🌐 Multi-Format Serialization

All read and write APIs accept an optional ObjectMapperType parameter:

mapper.writeValueAsString(user, ObjectMapperType.XML);
mapper.readValue<User>(jsonString, Class<User>(), ObjectMapperType.JSON);
mapper.writeValueAsMap(user, ObjectMapperType.YAML);

This makes the mapper a unified entry point for all supported formats, without requiring users to instantiate separate specialized mappers.

πŸ”§ Configurable Serialization Features

Features are stored as simple string identifiers using _features. They can be toggled dynamically at runtime:

mapper.enableFeature(SerializationFeature.INDENT_OUTPUT.name);
mapper.disableFeature("CUSTOM_RULE");
if (mapper.isFeatureEnabled("FOO")) { /* ... */ }

This allows higher-level modules or libraries to plug in optional behaviors without modifying the mapper itself.

🧩 Naming Strategy Support

The mapper uses a NamingStrategy to convert Dart field names to serialized keys. By default, it uses:

SnakeCaseNamingStrategy()

but can be replaced easily:

mapper.setNamingStrategy(CamelCaseNamingStrategy());

Naming strategies apply uniformly across JSON, XML, and YAML.

πŸ” Application-Aware Behavior

As a subclass of AbstractAwareObjectMapper, this mapper:

  • Discovers all serializers, deserializers, generators, naming strategies, adapters, and contexts via the JetLeaf ApplicationContext.
  • Registers everything during onReady() using JetLeaf's annotation-based ordering model.
  • Automatically wires JSON, XML, and YAML generators if available.
  • Inherits its Environment and ConversionService from the application context unless manually overridden.

This makes the mapper fully integrated with JetLeaf’s inversion-of-control and configuration system.

🧱 Example: Basic JSON Use

final mapper = JetsonObjectMapper();

final user = mapper.readValue<User>('{"name":"Alice"}', Class<User>());
final json = mapper.writeValueAsString(user);

🧱 Example: XML + YAML Use

final xml = mapper.writeValueAsString(order, ObjectMapperType.XML);
final yaml = mapper.writeValueAsString(order, ObjectMapperType.YAML);

final parsed = mapper.readValue<Order>(xml, Class<Order>(), ObjectMapperType.XML);

πŸ“¦ Integration

This mapper is automatically used by:

  • Jetson2HttpMessageConverter (JSON)
  • Jetson2XmlHttpMessageConverter (XML)
  • Jetson2YamlHttpMessageConverter (YAML)

making it the central serialization component of JetLeaf’s web layer.

Inheritance

Constructors

JetsonObjectMapper([bool autoRegisterStandardAdapters = true])
A high-level, multi-format Jetson object mapper with integrated support for JSON, XML, and YAML serialization and deserialization.

Properties

autoRegisterStandardAdapters ↔ bool
Whether to auto add default adapters on instantiation
getter/setter pairinherited
hashCode β†’ int
The hash code for this object.
no setterinherited
runtimeType β†’ Type
A representation of the runtime type of the object.
no setterinherited

Methods

disableFeature(String featureName) β†’ void
Disables a configurable feature flag.
override
enableFeature(String featureName) β†’ void
Enables a configurable feature flag within the mapping engine.
override
getConversionService() β†’ ConversionService
Returns the global ConversionService responsible for type coercions and primitive value conversions.
inherited
getEnvironment() β†’ Environment
Returns the active Environment configuration associated with this mapper.
inherited
getJsonDeserializationContext() β†’ JsonDeserializationContext
Returns the active JsonDeserializationContext, creating it if necessary.
inherited
getJsonGenerator() β†’ JsonGenerator
Returns the active JsonGenerator, initializing it lazily if necessary.
inherited
getJsonParser(String content) β†’ JsonParser
Returns a JsonParser for the given JSON content.
inherited
getJsonSerializationContext() β†’ JsonSerializationContext
Returns the active JsonSerializationContext, creating it lazily when needed.
inherited
getNamingStrategy() β†’ NamingStrategy
Returns the naming strategy used for field name conversion.
override
getPackageName() β†’ String
Represents an abstraction for identifying the package that an object, resource, or service belongs to.
inherited
getXmlDeserializationContext() β†’ XmlDeserializationContext
Returns the active XmlDeserializationContext, creating it lazily if necessary.
inherited
getXmlGenerator() β†’ XmlGenerator
Returns the active XmlGenerator, creating one if necessary.
inherited
getXmlParser(String content) β†’ XmlParser
Creates and returns a new XmlParser for the provided XML content string.
inherited
getXmlSerializationContext() β†’ XmlSerializationContext
Returns the active XmlSerializationContext, creating it lazily if needed.
inherited
getYamlDeserializationContext() β†’ YamlDeserializationContext
Returns the current YamlDeserializationContext, creating it if needed.
inherited
getYamlGenerator() β†’ YamlGenerator
Returns the active YamlGenerator, creating one if needed.
inherited
getYamlParser(String content) β†’ YamlParser
Creates a new YamlParser for the given YAML content string.
inherited
getYamlSerializationContext() β†’ YamlSerializationContext
Returns the current YamlSerializationContext, creating it if necessary.
inherited
isFeatureEnabled(String featureName) β†’ bool
Returns whether a feature flag is currently enabled.
override
noSuchMethod(Invocation invocation) β†’ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onReady() β†’ Future<void>
Interface to be implemented by pods that require initialization logic after their properties have been set by the container.
inherited
readContentTree(String content) β†’ JsonNode
Parses the given JSON content string into a JsonNode tree.
inherited
readJsonValue<T>(String json, Class<T> type) β†’ T
Deserializes a structured json string into an object of type T.
inherited
readJsonValueFromMap<T>(Map<String, dynamic> map, Class<T> type) β†’ T
Deserializes a pre-parsed map into an object of type T.
inherited
readTree(JsonParser parser) β†’ JsonNode
Reads and parses JSON content from the given JsonParser into a JsonNode tree.
inherited
readValue<T>(String data, Class<T> type, [ObjectMapperType mapWith = ObjectMapperType.JSON]) β†’ T
Deserializes a structured string into an object of type T.
override
readValueFromMap<T>(Map<String, dynamic> map, Class<T> type, [ObjectMapperType mapWith = ObjectMapperType.JSON]) β†’ T
Deserializes a pre-parsed map into an object of type T.
override
readXmlContentTree(String content) β†’ XmlNode
Parses the given XML content string into an XmlNode tree.
inherited
readXmlTree(XmlParser parser) β†’ XmlNode
Reads and parses XML content from the given XmlParser into an XmlNode tree.
inherited
readXmlValue<T>(String xml, Class<T> type) β†’ T
Deserializes an XML string into an object of type T.
inherited
readXmlValueFromMap<T>(Map<String, dynamic> map, Class<T> type) β†’ T
Deserializes an XML-compatible map into an instance of type T.
inherited
readYamlContentTree(String content) β†’ YamlNode
Parses the given YAML content string into a YamlNode tree.
inherited
readYamlTree(YamlParser parser) β†’ YamlNode
Reads and parses YAML content from the given YamlParser into a YamlNode tree.
inherited
readYamlValue<T>(String yaml, Class<T> type) β†’ T
Deserializes a YAML string into an object of type T.
inherited
readYamlValueFromMap<T>(Map<String, dynamic> map, Class<T> type) β†’ T
Deserializes a YAML-compatible map into an instance of type T.
inherited
registerAdapter(Class type, ObjectSerializationAdapter<dynamic, Generator, Parser, DeserializationContext<Parser>, SerializationContext<Generator>> adapter) β†’ void
Registers a bidirectional adapter (ObjectSerializationAdapter) for type T.
inherited
registerDeserializer(Class type, ObjectDeserializer<dynamic, Parser, DeserializationContext<Parser>> deserializer) β†’ void
Registers a custom deserializer for type T.
inherited
registerSerializer(Class type, ObjectSerializer<dynamic, Generator, SerializationContext<Generator>> serializer) β†’ void
Registers a custom serializer for type T.
inherited
setApplicationContext(ApplicationContext applicationContext) β†’ void
Sets the ApplicationContext that this component runs in.
inherited
setConversionService(ConversionService conversionService) β†’ void
Sets the ConversionService that this component can use for type conversions.
inherited
setDeserializationContext(DeserializationContext<Parser> context) β†’ void
Assigns the DeserializationContext used during deserialization.
inherited
setEnvironment(Environment environment) β†’ void
Sets the Environment that this component runs in.
inherited
setJsonGenerator(JsonGenerator jsonGenerator) β†’ void
Sets the active JsonGenerator used for serializing Dart objects to JSON.
inherited
setJsonParserFactory(JsonParserFactory factory) β†’ void
Sets a custom JSON parser factory to create JsonParser instances from raw JSON strings.
inherited
setNamingStrategy(NamingStrategy strategy) β†’ void
Sets the active NamingStrategy for this mapper.
override
setSerializationContext(SerializationContext<Generator> context) β†’ void
Assigns the SerializationContext used during serialization.
inherited
setXmlGenerator(XmlGenerator generator) β†’ void
Sets the active XmlGenerator used for serializing Dart objects to XML.
inherited
setYamlGenerator(YamlGenerator generator) β†’ void
Sets the active YamlGenerator used for serializing Dart objects to YAML.
inherited
toString() β†’ String
A string representation of this object.
inherited
writeValueAsJson(Object? value) β†’ String
Serializes a Dart object into a JSON string.
inherited
writeValueAsJsonMap(Object? value) β†’ Map<String, dynamic>
Serializes a Dart object into a Map<String, dynamic> representation.
inherited
writeValueAsMap(Object? value, [ObjectMapperType mapWith = ObjectMapperType.JSON]) β†’ Map<String, dynamic>
Serializes a Dart object into a Map<String, dynamic> representation.
override
writeValueAsString(Object? value, [ObjectMapperType mapWith = ObjectMapperType.JSON]) β†’ String
Serializes a Dart object into a structured format string.
override
writeValueAsXml(Object? value) β†’ String
Serializes a Dart object into an XML string.
inherited
writeValueAsXmlMap(Object? value) β†’ Map<String, dynamic>
Serializes a Dart object into an XML Map<String, dynamic> representation.
inherited
writeValueAsYaml(Object? value) β†’ String
Serializes a Dart object into a YAML string.
inherited
writeValueAsYamlMap(Object? value) β†’ Map<String, dynamic>
Serializes a Dart object into a YAML Map<String, dynamic> representation.
inherited

Operators

operator ==(Object other) β†’ bool
The equality operator.
inherited