crimson
crimson copied to clipboard
Allow nested classes in freezed classes
Let's say we have a Tweet
class that uses Reply
as a field. This works on non freezed classes
@json
class Tweet {
DateTime? created_at;
String? tweet;
Reply? reply;
}
@json
class Reply {
DateTime? created_at;
String? reply;
}
When I convert this to freezed class I see that generated readTweet
looking for fromJson
methods in Reply
which not exists.
@freezed
class Tweet with _$Tweet {
@json
const factory Tweet({
DateTime? created_at,
String? tweet,
Reply? reply
}) = _Tweet;
}
@freezed
class Reply with _$Reply {
@json
const factory Reply({
DateTime? created_at,
String? reply,
}) = _Reply;
}
// ---- .g ----
extension ReadTweet on Crimson {
Tweet readTweet() {
DateTime? created_at;
String? tweet;
Reply? reply;
loop:
while (true) {
switch (iterObjectHash()) {
case -1:
break loop;
case -3141059728106243719: // created_at
created_at = skipNull() ? null : DateTime.parse(readString());
break;
case -5949187214024354806: // tweet
tweet = readStringOrNull();
break;
case -777431743796252409: // reply
reply = Reply.fromJson(read());
break;
default:
skip();
break;
}
}
...
}
...
}
Wondering if this feature exists or is planned already?
Definitely something I need before making the switch over to Crimson
Seems to work correctly if you remove the json_serializable
package or if you add the fromBytes
method.