BoolSerializer<G extends Generator, C extends SerializationContext<Generator>> class final

Serializes Dart bool values into JSON boolean values.

The BoolSerializer handles boolean serialization for both JSON-specific generators and generic text-based generators:

Serialization Rules

  • When the generator is a JsonGenerator, the value is written as a JSON boolean using writeBoolean().
  • For non-JSON generators, the boolean value is converted to a string via toString() and emitted using writeString().

This ensures correct JSON boolean semantics while maintaining flexibility for other output formats.

Example

final serializer = BoolSerializer();
serializer.serialize(true, generator, context);
// JSON output: true

Notes

  • No transformation or coercion is performed; the raw boolean is emitted.
  • For domain-specific serialization rules (e.g., "yes"/"no"), use a JsonConverter.
Inheritance
Annotations
  • @Generic.new(BoolSerializer)

Constructors

BoolSerializer()
Creates a new BoolSerializer.
const

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

canSerialize(Class type) bool
Returns whether the given type can be serialized by the system.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
serialize(bool value, G generator, C ctxt) → void
Serializes an object of type T into an object using the provided Generator and SerializationContext.
override
supportsContext(SerializationContext<Generator> context) bool
Determines whether this serializer supports the given serialization context.
inherited
toClass() → Class<bool>
Provides a contract for types capable of exposing their associated runtime Class metadata representation within the JetLeaf reflection system.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited