An object that can encode itself to various data formats.
The interface can be used like this:
class Person implements SelfEncodable {
/* ... */
@override
void encode(Encoder encoder) {
/* ... */
}
}
Objects implementing SelfEncodable can be encoded to various data formats using the respective to<Format>()
extension method. A particular method is available by importing the appropriate library or package:
final Person person = ...;
// From 'package:codable/json.dart'
final String json = person.toJson();
// From 'package:codable/standard.dart'
final Map<String, dynamic> map = person.toMap();
// From imaginary 'package:x/x.dart'
final X x = person.toX();
See also:
- Implementers
- Available extensions
Constructors
- SelfEncodable.fromHandler(void encode(Encoder encoder))
-
Creates a SelfEncodable from a handler function.
factory
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
-
encode(
Encoder encoder) → void -
Encodes itself using the
encoder
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toCsv(
) → String -
Available on T, provided by the CsvSelfEncodableSelf extension
-
toCsvBytes(
) → List< int> -
Available on T, provided by the CsvSelfEncodableSelf extension
-
toJson(
) → String -
Available on T, provided by the JsonSelfEncodableSelf extension
-
toJsonBytes(
) → List< int> -
Available on T, provided by the JsonSelfEncodableSelf extension
-
toMap(
) → Map< String, dynamic> -
Available on T, provided by the StandardSelfEncodable extension
-
toMsgPack(
) → List< int> -
Available on T, provided by the MsgPackSelfEncodableSelf extension
-
toProgressiveJson(
) → List< int> -
Available on T, provided by the ProgressiveJsonSelfEncodableSelf extension
-
toProgressiveJsonStream(
) → Stream< List< int> > -
Available on T, provided by the ProgressiveJsonSelfEncodableSelf extension
-
toString(
) → String -
A string representation of this object.
inherited
-
toValue(
) → Object? -
Available on T, provided by the StandardSelfEncodable extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited