LocalDateTimeSerializationAdapter<G extends Generator, P extends Parser, DC extends DeserializationContext<Parser> , SC extends SerializationContext<Generator> > class
final
Serializes and deserializes Dart LocalDateTime values to and from ISO-8601 strings.
The LocalDateTimeSerializationAdapter provides a unified adapter for
handling LocalDateTime objects in both serialization and deserialization,
supporting JSON and generic generators/parsers.
Serialization Rules
- Converts the
LocalDateTimeto an ISO-8601 string usingtoString(). - Writes the string using
generator.writeString().
Deserialization Rules
- Accepts ISO-8601 formatted strings and converts them to
LocalDateTime. - Uses the context's
ConversionServiceif available for type conversion. - Throws
InvalidFormatExceptionif the input string is invalid.
Example
final adapter = LocalDateTimeSerializationAdapter();
final dateTime = LocalDateTime(2025, 6, 27, 8, 15, 30, 123);
adapter.serialize(dateTime, generator, context);
// JSON output: "2025-06-27T08:15:30.123"
final parsed = adapter.deserialize(parser, context, Class.forType(LocalDateTime));
// parsed is a LocalDateTime instance
Notes
- This adapter preserves both date and time information, but does not handle time zones.
- For non-ISO formats or custom time zone handling, use a dedicated
JsonConverter.
- Implemented types
-
- ObjectSerializable
- ObjectSerializer<
T, G, SC> - ObjectDeserializer<
T, P, DC>
- Annotations
-
- @Generic.new(LocalDateTimeSerializationAdapter)
Constructors
- LocalDateTimeSerializationAdapter()
- Creates a new LocalDateTimeSerializationAdapter.
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
-
canDeserialize(
Class type) → bool -
Returns whether the given
typecan be deserialized by the system.override -
canSerialize(
Class type) → bool -
Returns whether the given
typecan be serialized by the system.override -
deserialize(
P parser, DC ctxt, Class toClass) → LocalDateTime? -
Deserializes an object of type
Tusing the givenPand DeserializationContext.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
serialize(
LocalDateTime value, G generator, SC serializer) → void -
Serializes an object of type
Tinto an object using the provided Generator and SerializationContext.override -
supports(
DeserializationContext< Parser> context) → bool -
Determines whether this deserializer supports the given deserialization context.
inherited
-
supportsContext(
SerializationContext< Generator> context) → bool -
Determines whether this serializer supports the given serialization context.
inherited
-
toClass(
) → Class< LocalDateTime> -
Provides a contract for types capable of exposing their associated
runtime
Classmetadata representation within the Jetleaf reflection system. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited