IntDeserializer<P extends Parser, C extends DeserializationContext<Parser> > class
final
Deserializes JSON numeric values into Dart int instances.
The IntDeserializer converts JSON numbers into Dart integers with safe fallback behavior:
- If the JSON value is already an
int, it is returned unchanged. - If the JSON value is a
num(e.g., a double), it is coerced using.toInt(). - If the value is a string, the deserializer attempts
int.tryParse(). nullJSON values yieldnull.
Core Responsibilities
- Safely coerce JSON numeric values into Dart
int. - Handle numbers, numeric strings, and null values gracefully.
- Integrate cleanly into JetLeaf's deserialization pipeline.
Example
final deserializer = IntDeserializer();
final parser = JsonParser('42');
final result = deserializer.deserialize(parser, context, Class.forType(int));
// result == 42
Notes
- Floating-point input is truncated using
.toInt(). - Non-numeric strings return
nullviaint.tryParse.
- Inheritance
-
- Object
- ObjectDeserializer<
int, P, C> - IntDeserializer
- Annotations
-
- @Generic.new(IntDeserializer)
Constructors
- IntDeserializer()
-
Creates a new IntDeserializer.
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
-
canDeserialize(
Class type) → bool -
Returns whether the given
typecan be deserialized by the system.override -
deserialize(
P parser, C ctxt, Class toClass) → int? -
Deserializes an object of type
Tusing the givenPand DeserializationContext.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
supports(
DeserializationContext< Parser> context) → bool -
Determines whether this deserializer supports the given deserialization context.
inherited
-
toClass(
) → Class< int> -
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