package:my_custom_type_generator
build.yaml
builders:
extractTypes:
import: "package:my_custom_type_generator/builder.dart"
builder_factories: ["extractTypes"]
build_extensions: {'$lib$': ['extracted-types.json']}
build_to: source
auto_apply: dependents
package:my_custom_type_annotation
annotation.dart
@Target({TargetKind.classType})
class MyCustomType extends JsonSerializable {
const MyCustomType() : super(explicitToJson: true, includeIfNull: false);
}
package:custom_type_project
some_cool_object.dart
part 'some_cool_object.g.dart';
@MyCustomType()
class SomeCoolObject {
final String name;
final int theAgeOfAThing;
SomeCoolObject({required this.name, required this.theAgeOfAThing});
Map<String, dynamic> toJson() => _$SomeCoolObjectToJson(this);
factory SomeCoolObject.fromJson(Map<String, dynamic> json) =>
_$SomeCoolObjectFromJson(json);
}
My custom builder finds the annotations and outputs the data that I need from them. I would also like for json_serializable
to process these same annotations, which is why the annotation extends from JsonSerializable
.
In the project package, I've found that if I don't include json_serializable
in my dev_dependencies
, my builder produces the desired output. But if I do include json_serializable
, then my builder stops producing output, and json_serializable
produces output instead.
Is there a way I can convince both json_serializable
and my custom builder to both run? I assume I need to adjust a build.yaml somewhere, but I have no idea where or what needs to be added.