JsonWritable class abstract interface

A class that writes its own JSON.

The JSON encoder of dox_core calls writeJson, and not toJson(), for a response and for JSON.bytes(). The class then makes no Map, so the response is faster.

JSON.stringify() and jsonEncode() do not call it. A class that is used with them also needs a toJson() that gives the same JSON.

class Item implements JsonWritable {
  Item(this.id, this.name);
  final int id;
  final String name;

  @override
  void writeJson(JsonWriter writer) {
    writer.startObject();
    writer.key('id');
    writer.integer(id);
    writer.key('name');
    writer.string(name);
    writer.endObject();
  }
}

The generator of @DoxModel writes this method for a model.

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
writeJson(JsonWriter writer) → void
Writes this object with writer.

Operators

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