JsonSchemaSource class

Names the JSON Schema that the JSON of an @Introspected class is checked against.

Put it on a class whose JSON comes from outside and has a published schema: an order from a partner, a configuration file. When the ObjectMapper has a schemaResolver, it checks the decoded JSON against the schema before it builds the object, and throws a JsonSchemaValidationException listing every violation with its path.

The location is one of:

  • resources:schemas/order.json: a file below lib/resources/;
  • https://example.com/schemas/order.json (or http://);
  • github:owner/repo/path/to/order.json@ref (@ref optional).

The build keeps a copy of a remote schema below lib/resources/, at JsonSchemaLocations.resourceOf, so it is read like a resource.

@Introspected()
@JsonSchemaSource('resources:schemas/order.json')
class Order {
  const Order({required this.id, required this.items});
  final String id;
  final List<OrderItem> items;
}

Spring (Java): Spring has no counterpart.

Constructors

JsonSchemaSource(String location)
The schema at location (see the class description for the forms).
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
location → String
Where the schema is: resources:..., https://..., http://... or github:owner/repo/path@ref.
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.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited