mastodon-dart / mastodon-api

This library provides the easiest and powerful Dart/Flutter library for Mastodon API 🎯
http://pub.dev/packages/mastodon_api
BSD 3-Clause "New" or "Revised" License
63 stars 13 forks source link

Bug Report: `Visibility` isn't JSON encodable #156

Open pixelcmtd opened 1 year ago

pixelcmtd commented 1 year ago

1. Current bug behavior

Unhandled exception:
Converting object to an encodable object failed: Instance of 'Visibility'
#0      _JsonStringifier.writeObject (dart:convert/json.dart:793:7)
#1      _JsonStringifier.writeMap (dart:convert/json.dart:874:7)
#2      _JsonStringifier.writeJsonValue (dart:convert/json.dart:829:21)
#3      _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
#4      _JsonStringStringifier.printOn (dart:convert/json.dart:982:17)
#5      _JsonStringStringifier.stringify (dart:convert/json.dart:967:5)
#6      JsonEncoder.convert (dart:convert/json.dart:345:30)
#7      JsonCodec.encode (dart:convert/json.dart:231:45)
#8      jsonEncode (dart:convert/json.dart:114:10)
#9      ServiceHelper.post (package:mastodon_api/src/core/service_helper.dart:167:23)
#10     BaseService.post (package:mastodon_api/src/service/base_service.dart:166:21)
#11     _StatusesV1Service.createStatus (package:mastodon_api/src/service/v1/statuses/statuses_v1_service.dart:876:21)
#12     main (redacted.dart)
#13     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:294:33)
#14     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

2. Expected behavior

The code should just work (i.e. post a toot)

3. Steps to reproduce

import 'package:mastodon_api/mastodon_api.dart';

// the bulk of this is straight copy-paste from the example in the readme
void main(List<String> args) async {
  final mastodon = MastodonApi(
    instance: args[0],
    bearerToken: args[1],

    retryConfig: RetryConfig(
      maxAttempts: 5,
      jitter: Jitter(
        minInSeconds: 2,
        maxInSeconds: 5,
      ),
      onExecute: (event) => print(
        'Retry after ${event.intervalInSeconds} seconds... '
        '[${event.retryCount} times]',
      ),
    ),
  );

  try {
    final response = await mastodon.v1.statuses.createStatus(
      text: 'Toot!',
      visibility: Visibility.private,
    );

    print(response.rateLimit);
    print(response.data);
  } on UnauthorizedException catch (e) {
    print(e);
  } on RateLimitExceededException catch (e) {
    print(e);
  } on MastodonException catch (e) {
    print(e.response);
    print(e.body);
    print(e);
  }
}
  mastodon_api: ^0.6.1
github-actions[bot] commented 1 year ago

Thanks for your contribution! :)