JsonOptions class
Configuration for JSON normalization via jsonSafe and related helpers.
Controls how Dart-specific types like DateTime, Duration, Enum, and non-finite doubles are converted to JSON-compatible representations.
Example
final options = JsonOptions(
dropNulls: true,
sortKeys: true,
dateTimeStrategy: DateTimeStrategy.millisecondsSinceEpoch,
);
final json = myMap.toJsonString(options: options);
Constructors
- JsonOptions({bool encodeEnumsAsName = true, DateTimeStrategy dateTimeStrategy = DateTimeStrategy.iso8601String, DurationStrategy durationStrategy = DurationStrategy.milliseconds, NonFiniteDoubleStrategy nonFiniteDoubles = NonFiniteDoubleStrategy.string, bool stringifyUnknown = true, bool setsAsLists = true, bool dropNulls = false, bool sortKeys = false, bool detectCycles = false, String cyclePlaceholder = '<cycle>'})
-
Creates a new configuration bundle for JSON normalization.
const
Properties
- cyclePlaceholder → String
-
Placeholder emitted when a cycle is detected.
final
- dateTimeStrategy → DateTimeStrategy
-
How to encode DateTime values.
final
- detectCycles → bool
-
If true, detect reference cycles to avoid infinite recursion.
final
- dropNulls → bool
-
If true, drop
nullmap values at all nesting levels.final - durationStrategy → DurationStrategy
-
How to encode Duration values.
final
- encodeEnumsAsName → bool
-
Encode enums by
.name(true) or.index(false).final - hashCode → int
-
The hash code for this object.
no setterinherited
- nonFiniteDoubles → NonFiniteDoubleStrategy
-
What to do with non-finite doubles (NaN/±Infinity).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- setsAsLists → bool
-
If true, encode Sets as Lists.
final
- sortKeys → bool
-
If true, sort map keys lexicographically (all levels).
final
- stringifyUnknown → bool
-
If true, unknown objects fall back to
toString(). If false, throw.final
Methods
-
copyWith(
{bool? encodeEnumsAsName, DateTimeStrategy? dateTimeStrategy, DurationStrategy? durationStrategy, NonFiniteDoubleStrategy? nonFiniteDoubles, bool? stringifyUnknown, bool? setsAsLists, bool? dropNulls, bool? sortKeys, bool? detectCycles, String? cyclePlaceholder}) → JsonOptions - Returns a copy of these options with the provided fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited