Parsing values
Strict modeβ
By default, ZodArt parsers operate in strict mode. This means they will only accept input values that match the expected type exactly. Any type mismatch will result in a ParseError.
The only exception is ZObject, which accepts only Map<String, dynamic> as input.
| β‘οΈinput β¬οΈoutput | List | bool | DateTime | double | int | Map<String, dynamic> | String | others |
|---|---|---|---|---|---|---|---|---|
| ZArray | β | β | β | β | β | β | β | β |
| ZBool | β | β | β | β | β | β | β | β |
| ZDateTime | β | β | β | β | β | β | β | β |
| ZDouble | β | β | β | β | β | β | β | β |
| ZInt | β | β | β | β | β | β | β | β |
| ZObject | β | β | β | β | β | β | β | β |
| ZString | β | β | β | β | β | β | β | β |
π§ Parsing with coertion parameter (coertion: true)β
β οΈ Coercion support will be implemented in future versions. For now, when parsing data from forms or loosely typed sources, please use explicit transformation chains, e.g.
ZString().toInt().
When the coercion option is enabled, ZodArt will attempt to convert compatible input values automatically, if there's no risk of data loss.
- β
int->doubleis allowed (safe upcast) - β
double->intis not allowed (precision loss risk) - β οΈ
Stringswill be parsed using Dart's native.parse()methods (e.g.,int.parse,DateTime.parse)
This is especially useful for form data or serialized values.
| β‘οΈinput β¬οΈoutput | List | bool | DateTime | double | int | Map<String, dynamic> | String | others |
|---|---|---|---|---|---|---|---|---|
| ZArray | β | β | β | β | β | β | β | β |
| ZBool | β | β | β | β | β | β | β οΈ true / false (case-insensitive) | β |
| ZDateTime | β | β | β | β | β | β | β οΈDateTime.parse | β |
| ZDouble | β | β | β | β | β | β | β οΈdouble.parse | β |
| ZInt | β | β | β | β | β | β | β οΈint.parse | β |
| ZObject | β | β | β | β | β | β | β | β |
| ZString | β | β | β | β | β | β | β | β |