JsonConverter class

A Converter implementation that calls json.encode on Requests and json.decode on Responses using the dart:convert package's utf8 and json utilities.

See the official documentation on Serializing JSON manually using dart:convert to learn more about when and how this Converter works as intended.

This Converter also adds the content-type: application/json header to each request.

If content type header is modified (for example by using @Post(headers: {'content-type': '...'})), JsonConverter won't add the header and it won't call json.encode if content type is not JSON.

Implemented types
Annotations
  • @immutable

Constructors

JsonConverter()
A Converter implementation that calls json.encode on Requests and json.decode on Responses using the dart:convert package's utf8 and json utilities.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

convertError<BodyType, InnerType>(Response response) FutureOr<Response>
Converts the received Response to a Response which has a body with the HTTP representation of the original body.
override
convertRequest(Request request) Request
Converts the received Request to a Request which has a body with the HTTP representation of the original body.
override
convertResponse<BodyType, InnerType>(Response response) FutureOr<Response<BodyType>>
Converts the received Response to a Response which has a body of the type BodyType.
override
decodeJson<BodyType, InnerType>(Response response) FutureOr<Response>
encodeJson(Request request) Request
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
tryDecodeJson(String data) FutureOr

Operators

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

Static Methods

isJson(dynamic data) bool
requestFactory(Request request) Request
responseFactory<BodyType, InnerType>(Response response) FutureOr<Response<BodyType>>