JsonDecodingContext class

JSON deserializer.

Example

import 'package:kind/kind.dart';

void main() {
  final json = {
    'message': 'Hello world!',
  };

  // Decode JSON
  final context = JsonDecodingContext();
  final greeting = context.decode(
    json,
    kind: Greeting.kind,
  );
}


class Greeting {
  static final EntityKind<Greeting> kind = EntityKind<Greeting>(
    name: 'Example',
    define: (c) {
      c.requiredString(
        id: 1,
        name: 'message', // <-- JSON field name
        getter: (t) => t.message,
        setter: (t,v) => t.message = v;
      );
      c.constructor = () => Greeting();
    },
  );

  String message = '';
}
Inheritance

Constructors

JsonDecodingContext({JsonSettings jsonSettings = const JsonSettings(), KindLibrary? kindLibrary, bool reactive = true, Namer? namer})

Properties

errorPrimaryLabel String
Primary label for errors constructed by newGraphNodeError.
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
jsonSettings JsonSettings
JSON serialization settings.
final
kindLibrary KindLibrary?
Optional library of available kinds.
finalinherited
namer Namer?
Translates names of kinds and properties. Default is null.
finalinherited
pathEdges List<Object?>
Path from root node to the current node.
finalinherited
pathNodes List<Object?>
finalinherited
reactive bool
Whether to construct reactive objects.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decode<T>(Object? json, {required Kind<T> kind}) → T
Deserializes an object using the given Kind.
override
enter(Object? value) → void
inherited
enterField(String name, Object? value) → void
Enters a field.
inherited
enterIndex(int index, Object? value) → void
Enters an index.
inherited
enterMapEntry(String key, Object? value) → void
Enters a map entry.
inherited
leave() → void
Leaves the the top node.
inherited
newGraphNodeError({required Object? value, required String reason}) GraphNodeError
Constructs a new instance of GraphNodeError that describes the location in the graph.
inherited
newUnsupportedTypeError(Object? value) GraphNodeError
Returns a new error.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pathContainsValue(Object? value) bool
Returns true if pathNodes has an identical value.
inherited
toString() String
A string representation of this object.
inherited

Operators

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