simc / crimson

Fast, efficient and easy-to-use JSON parser and serializer for Dart.
Apache License 2.0
229 stars 6 forks source link

Support `from<Name>(Uint8List <name>)` factory constructor #13

Closed SunlightBro closed 1 year ago

SunlightBro commented 1 year ago

This still has an issue with freezed.

SunlightBro commented 1 year ago

@simc This now supports any factory constructor with posParam type Uint8List, If the constructor and posParam name are the same.

@json
class Foo {
  Foo(this.name, this.age);

  final String name;
  final int age;

  factory Foo.fromName(Uint8List name) => _$FooFromName(name);
}

This still clashes with freezed fromJson (must be fixed in freezed to not generate when posParam is Uint8List). But for now can be workedaround in freezed class by just using something like:

factory MyFreezed.fromBytes(Uint8List bytes) => _$MyFreezedFromBytes(bytes);
SunlightBro commented 1 year ago

For https://github.com/simc/crimson/issues/11 fromJson factory constructor

SunlightBro commented 1 year ago

@simc can have a look/feedback at this PR.

simc commented 1 year ago

Thanks a lot for this PR!