Skip to content

Generate public classes instead #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lukepighetti opened this issue Apr 24, 2020 · 2 comments
Closed

Generate public classes instead #635

lukepighetti opened this issue Apr 24, 2020 · 2 comments

Comments

@lukepighetti
Copy link

lukepighetti commented Apr 24, 2020

Currently we annotate a public class and the backing to/from json classes are generated.

@JsonSerializable()
class Task {
  final String id;
  final String name;
  final String avatar;
  final String createdAt;

  Task(this.id, this.name, this.avatar, this.createdAt);

  factory Task.fromJson(Map<String, dynamic> json) => _$TaskFromJson(json);
  Map<String, dynamic> toJson() => _$TaskToJson(this);
}

Is there any reason why we cannot annotate a private class and have json_serializable generate the public class? This private class would generate the above public class. The benefit would be less boilerplate. The private class would implemented by the public class.

@JsonSerializable()
abstract class _Task {
  final String id;
  final String name;
  final String avatar;
  final String createdAt;
}
@lukecaan
Copy link

Agreed!! Going through having to manually type a toJson and fromJson method for all of my redux actions is really annoying when the generator could just as easily be generating them for me!

If there was an extra parameter in the annotation like generatePublicMethods:bool that'd be awesome

@kevmoo
Copy link
Collaborator

kevmoo commented May 28, 2020

We likely won't do any work here – and wait for partial class support dart-lang/language#252

@kevmoo kevmoo closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants