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().
  • null JSON values yield null.

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 null via int.tryParse.
Inheritance
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 type can be deserialized by the system.
override
deserialize(P parser, C ctxt, Class toClass) int?
Deserializes an object of type T using the given P and 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 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