encodeJsonTree method

  1. @override
Object? encodeJsonTree(
  1. T instance
)
override

Converts instance to a JSON tree.

Before calling this method, you should call isInstance to check whether instance is an instance of T .

Implementation

@override
Object? encodeJsonTree(T instance) {
  final toJson = _toJson;
  if (toJson != null) {
    return toJson(instance);
  }
  final fromJson = _fromJson;
  if (fromJson != null) {
    return (instance as dynamic).toJson();
  }
  final mapper = JsonObjectEncodingMapper();
  map(mapper, instance);
  return mapper.jsonObject;
}