Using the source_gen stack to make a code generator, how can I make a generator that generates code that would be the input of another generator (more specifically json_serializable
)?
For example, consider:
class Example extends Generator {
@override
String generate(LibraryReader library, BuildStep buildStep) {
return '''
@JsonSerializable(nullable: false)
class Person {
final String firstName;
final String lastName;
final DateTime dateOfBirth;
Person({this.firstName, this.lastName, this.dateOfBirth});
factory Person.fromJson(Map<String, dynamic> json) => _PersonFromJson(json);
Map<String, dynamic> toJson() => _PersonToJson(this);
}
''';
}
}
This is an example of a code-generator that output code which then needs to be sent to json_serializable
What can I do so that json_serializable
correctly generates here?