MalformedJsonException class
Thrown when JSON data is structurally invalid or fails validation.
This exception is raised by validation utilities or serializers when:
- JSON structure is broken (mismatched braces/brackets)
- Required fields are missing or malformed
- JSON doesn't match expected schema or object structure
Example
try {
final validator = JsonValidator();
validator.validate('{"incomplete": true', schema: User);
} on MalformedJsonException catch (e) {
print('Validation failed: ${e.message}');
}
See also
Constructors
- MalformedJsonException(String message, {Object? cause})
-
Creates a new MalformedJsonException with an error
messageand optionalcause.
Properties
- cause → Object?
-
The underlying cause of this exception, if any.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
The message describing the error.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace
-
The associated stack trace.
finalinherited
Methods
-
getCause(
) → Object -
The cause of this exception, if any.
inherited
-
getMessage(
) → String -
The message associated with this exception.
inherited
-
getStackTrace(
) → StackTrace -
The stack trace associated with this exception.
inherited
-
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