JsonMappingException class
The error the JSON mapper throws when JSON cannot be turned into the requested type, or a value cannot be written as JSON.
Typical causes: text that is not JSON, a missing required property, a value of the wrong type, a constructor that threw. The path says where in the document the problem is, so the message can go back to whoever sent the JSON. Catch it where you read JSON from outside; the web starter turns it into a 400 response for request bodies.
// Reject a bad upload with a message naming the field.
try {
mapper.readValue<Order>(json);
} on JsonMappingException catch (error) {
log.warning(error); // items[2].price: expected a number, got "abc"
}
Spring (Java):
catch (JsonMappingException e) { e.getPathReference(); }
- Implemented types
Constructors
- JsonMappingException(String message, {String path = '', Object? cause})
-
A problem described by
messageatpath(empty for the root), caused bycause.
Properties
- cause → Object?
-
The underlying error, such as a
FormatExceptionfor invalid JSON or what a constructor threw;nullwhen there is none.final - hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
What went wrong, without the path.
final
- path → String
-
Where the problem is, such as
items[2].price; empty for the whole value.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited